47 lines
1 KiB
Go
47 lines
1 KiB
Go
|
|
package cmd
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"os"
|
||
|
|
|
||
|
|
"github.com/spf13/cobra"
|
||
|
|
|
||
|
|
"guardianproject.dev/ops/nix-cache-login/internal/config"
|
||
|
|
)
|
||
|
|
|
||
|
|
var (
|
||
|
|
cfgPath string
|
||
|
|
cfg *config.Config
|
||
|
|
)
|
||
|
|
|
||
|
|
var rootCmd = &cobra.Command{
|
||
|
|
Use: "nix-cache-login",
|
||
|
|
Short: "Authenticate with a Nix binary cache via OIDC",
|
||
|
|
Long: `nix-cache-login authenticates users and servers against a Keycloak OIDC
|
||
|
|
provider and writes access tokens to a netrc file so Nix can use them
|
||
|
|
when accessing an authenticated binary cache.`,
|
||
|
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||
|
|
var err error
|
||
|
|
cfg, err = config.Load(cfgPath)
|
||
|
|
if err != nil {
|
||
|
|
return err
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
},
|
||
|
|
// Default to login when no subcommand is given
|
||
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||
|
|
return loginCmd.RunE(cmd, args)
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
func Execute() {
|
||
|
|
if err := rootCmd.Execute(); err != nil {
|
||
|
|
fmt.Fprintln(os.Stderr, err)
|
||
|
|
os.Exit(1)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func init() {
|
||
|
|
rootCmd.PersistentFlags().StringVar(&cfgPath, "config", "", "path to config file (default: $XDG_CONFIG_HOME/nix-cache-login/config.toml)")
|
||
|
|
}
|