initial working version
This commit is contained in:
parent
db6b90134d
commit
d986a0b31a
19 changed files with 1430 additions and 0 deletions
46
cmd/root.go
Normal file
46
cmd/root.go
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
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)")
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue