Skip to content

Commit

Permalink
Use gcrane.Keychain in gcrane
Browse files Browse the repository at this point in the history
  • Loading branch information
ingwonsong committed Jul 20, 2022
1 parent bb4e0e0 commit 7615ef1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
11 changes: 3 additions & 8 deletions cmd/crane/cmd/auth.go
Expand Up @@ -32,7 +32,7 @@ import (
)

// NewCmdAuth creates a new cobra.Command for the auth subcommand.
func NewCmdAuth(options *[]crane.Option, argv ...string) *cobra.Command {
func NewCmdAuth(options []crane.Option, argv ...string) *cobra.Command {
cmd := &cobra.Command{
Use: "auth",
Short: "Log in or access credentials",
Expand Down Expand Up @@ -63,7 +63,7 @@ func toCreds(config *authn.AuthConfig) credentials {
}

// NewCmdAuthGet creates a new `crane auth get` command.
func NewCmdAuthGet(options *[]crane.Option, argv ...string) *cobra.Command {
func NewCmdAuthGet(options []crane.Option, argv ...string) *cobra.Command {
if len(argv) == 0 {
argv = []string{os.Args[0]}
}
Expand Down Expand Up @@ -97,12 +97,7 @@ func NewCmdAuthGet(options *[]crane.Option, argv ...string) *cobra.Command {
if err != nil {
return err
}
keychain := authn.DefaultKeychain
if options != nil {
opts := crane.GetOptions(*options...)
keychain = opts.Keychain
}
authorizer, err := keychain.Resolve(reg)
authorizer, err := crane.GetOptions(options...).Keychain.Resolve(reg)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/crane/cmd/root.go
Expand Up @@ -93,7 +93,7 @@ func New(use, short string, options []crane.Option) *cobra.Command {

commands := []*cobra.Command{
NewCmdAppend(&options),
NewCmdAuth(&options, "crane", "auth"),
NewCmdAuth(options, "crane", "auth"),
NewCmdBlob(&options),
NewCmdCatalog(&options),
NewCmdConfig(&options),
Expand Down
5 changes: 3 additions & 2 deletions cmd/gcrane/main.go
Expand Up @@ -38,11 +38,12 @@ const (
)

func main() {
options := []crane.Option{crane.WithAuthFromKeychain(gcrane.Keychain)}
// Same as crane, but override usage and keychain.
root := cmd.New(use, short, []crane.Option{crane.WithAuthFromKeychain(gcrane.Keychain)})
root := cmd.New(use, short, options)

// Add or override commands.
gcraneCmds := []*cobra.Command{gcmd.NewCmdList(), gcmd.NewCmdGc(), gcmd.NewCmdCopy(), cmd.NewCmdAuth(nil, "gcrane", "auth")}
gcraneCmds := []*cobra.Command{gcmd.NewCmdList(), gcmd.NewCmdGc(), gcmd.NewCmdCopy(), cmd.NewCmdAuth(options, "gcrane", "auth")}

// Maintain a map of google-specific commands that we "override".
used := make(map[string]bool)
Expand Down

0 comments on commit 7615ef1

Please sign in to comment.