From 7615ef1806d36230699ed1f86d43fa799b8251d0 Mon Sep 17 00:00:00 2001 From: Ingwon Song Date: Wed, 20 Jul 2022 21:02:57 +0000 Subject: [PATCH] Use gcrane.Keychain in gcrane --- cmd/crane/cmd/auth.go | 11 +++-------- cmd/crane/cmd/root.go | 2 +- cmd/gcrane/main.go | 5 +++-- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/cmd/crane/cmd/auth.go b/cmd/crane/cmd/auth.go index fad929749..eaaa32622 100644 --- a/cmd/crane/cmd/auth.go +++ b/cmd/crane/cmd/auth.go @@ -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", @@ -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]} } @@ -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 } diff --git a/cmd/crane/cmd/root.go b/cmd/crane/cmd/root.go index 0ea3e1421..7950ae7b6 100644 --- a/cmd/crane/cmd/root.go +++ b/cmd/crane/cmd/root.go @@ -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), diff --git a/cmd/gcrane/main.go b/cmd/gcrane/main.go index 3d51bcec1..a77168420 100644 --- a/cmd/gcrane/main.go +++ b/cmd/gcrane/main.go @@ -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)