From da546523d9f8f37e76491fe8721e40597a12487c Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Sat, 12 Oct 2024 17:30:19 +0900 Subject: [PATCH 1/2] feat: support keyring --- go.mod | 4 ++++ go.sum | 10 ++++++++++ pkg/github/github.go | 33 +++++++++++++++++++++++++++------ pkg/github/keyring.go | 27 +++++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 6 deletions(-) create mode 100644 pkg/github/keyring.go diff --git a/go.mod b/go.mod index 902dc20a4..5050d5d4e 100644 --- a/go.mod +++ b/go.mod @@ -27,6 +27,7 @@ require ( github.com/suzuki-shunsuke/logrus-error v0.1.4 github.com/urfave/cli/v2 v2.27.4 github.com/wk8/go-ordered-map/v2 v2.1.8 + github.com/zalando/go-keyring v0.2.5 golang.org/x/oauth2 v0.23.0 golang.org/x/sys v0.26.0 gopkg.in/yaml.v2 v2.4.0 @@ -36,16 +37,19 @@ require ( dario.cat/mergo v1.0.1 // indirect github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/semver/v3 v3.3.0 // indirect + github.com/alessio/shellescape v1.4.1 // indirect github.com/andybalholm/brotli v1.0.1 // indirect github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/buger/jsonparser v1.1.1 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect + github.com/danieljoos/wincred v1.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/dsnet/compress v0.0.2-0.20210315054119-f66993602bf5 // indirect github.com/fatih/color v1.13.0 // indirect github.com/gdamore/encoding v1.0.0 // indirect github.com/gdamore/tcell/v2 v2.6.0 // indirect github.com/go-playground/validator/v10 v10.11.1 // indirect + github.com/godbus/dbus/v5 v5.1.0 // indirect github.com/golang/snappy v0.0.4 // indirect github.com/google/go-querystring v1.1.0 // indirect github.com/google/uuid v1.6.0 // indirect diff --git a/go.sum b/go.sum index a0abe1941..42adb323d 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,8 @@ github.com/Masterminds/sprig/v3 v3.3.0 h1:mQh0Yrg1XPo6vjYXgtf5OtijNAKJRNcTdOOGZe github.com/Masterminds/sprig/v3 v3.3.0/go.mod h1:Zy1iXRYNqNLUolqCpL4uhk6SHUMAOSCzdgBfDb35Lz0= github.com/adrg/xdg v0.5.0 h1:dDaZvhMXatArP1NPHhnfaQUqWBLBsmx1h1HXQdMoFCY= github.com/adrg/xdg v0.5.0/go.mod h1:dDdY4M4DF9Rjy4kHPeNL+ilVF+p2lK8IdM9/rTSGcI4= +github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0= +github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= github.com/andybalholm/brotli v1.0.1 h1:KqhlKozYbRtJvsPrrEeXcO+N2l6NYT5A2QAFmSULpEc= github.com/andybalholm/brotli v1.0.1/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPnH1Wvgk= @@ -17,6 +19,8 @@ github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx2 github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/danieljoos/wincred v1.2.0 h1:ozqKHaLK0W/ii4KVbbvluM91W2H3Sh0BncbUNPS7jLE= +github.com/danieljoos/wincred v1.2.0/go.mod h1:FzQLLMKBFdvu+osBrnFODiv32YGwCfx0SkRa/eYHgec= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -45,6 +49,8 @@ github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJ github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU= github.com/goccy/go-yaml v1.12.0 h1:/1WHjnMsI1dlIBQutrvSMGZRQufVO3asrHfTwfACoPM= github.com/goccy/go-yaml v1.12.0/go.mod h1:wKnAMd44+9JAAnGQpWVEgBzGt3YuTaQ4uXoHvE4m7WU= +github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= +github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= @@ -155,6 +161,8 @@ github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNo github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w= github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -189,6 +197,8 @@ github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMx github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 h1:gEOO8jv9F4OT7lGCjxCBTO/36wtF6j2nSip77qHd4x4= github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1/go.mod h1:Ohn+xnUBiLI6FVj/9LpzZWtj1/D6lUovWYBkxHVV3aM= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +github.com/zalando/go-keyring v0.2.5 h1:Bc2HHpjALryKD62ppdEzaFG6VxL6Bc+5v0LYpN8Lba8= +github.com/zalando/go-keyring v0.2.5/go.mod h1:HL4k+OXQfJUWaMnqyuSOc0drfGPX2b51Du6K+MRgZMk= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= diff --git a/pkg/github/github.go b/pkg/github/github.go index 93fc74fa6..7cb2b596b 100644 --- a/pkg/github/github.go +++ b/pkg/github/github.go @@ -2,12 +2,15 @@ package github import ( "context" + "fmt" "io" "net/http" "net/url" "os" + "strconv" "github.com/google/go-github/v66/github" + "github.com/sirupsen/logrus" "golang.org/x/oauth2" ) @@ -26,8 +29,13 @@ type ( const Tarball = github.Tarball -func New(ctx context.Context) *RepositoriesServiceImpl { - return github.NewClient(getHTTPClientForGitHub(ctx, getGitHubToken())).Repositories +func New(ctx context.Context, logE *logrus.Entry) *RepositoriesServiceImpl { + token, err := getGitHubToken() + if err != nil { + logE.WithError(err).Warn("get a GitHub Access token") + token = "" + } + return github.NewClient(getHTTPClientForGitHub(ctx, token)).Repositories } type RepositoriesService interface { @@ -37,11 +45,24 @@ type RepositoriesService interface { DownloadContents(ctx context.Context, owner, repo, filepath string, opts *github.RepositoryContentGetOptions) (io.ReadCloser, *github.Response, error) } -func getGitHubToken() string { - if token := os.Getenv("AQUA_GITHUB_TOKEN"); token != "" { - return token +func getGitHubToken() (string, error) { + for _, key := range []string{"AQUA_GITHUB_TOKEN", "GITHUB_TOKEN"} { + if token := os.Getenv(key); token != "" { + return token, nil + } + } + k := os.Getenv("AQUA_KEYRING") + if k == "" { + return "", nil + } + a, err := strconv.ParseBool(k) + if err != nil { + return "", fmt.Errorf("parse AQUA_KEYRING as bool: %w", err) + } + if !a { + return "", nil } - return os.Getenv("GITHUB_TOKEN") + return getTokenFromKeyring() } func getHTTPClientForGitHub(ctx context.Context, token string) *http.Client { diff --git a/pkg/github/keyring.go b/pkg/github/keyring.go new file mode 100644 index 000000000..d9ffe72ca --- /dev/null +++ b/pkg/github/keyring.go @@ -0,0 +1,27 @@ +package github + +import ( + "fmt" + + "github.com/zalando/go-keyring" +) + +const ( + keyService = "aquaproj.github.io" + keyName = "GITHUB_TOKEN" +) + +func getTokenFromKeyring() (string, error) { + s, err := keyring.Get(keyService, keyName) + if err != nil { + return "", fmt.Errorf("get a GitHub Access token from keyring: %w", err) + } + return s, nil +} + +func SetTokenInKeyring(token string) error { + if err := keyring.Set(keyService, keyName, token); err != nil { + return fmt.Errorf("set a GitHub Access token in keyring: %w", err) + } + return nil +} From 1e29ad1b6baa1942f2597c9f1048a41128d7691b Mon Sep 17 00:00:00 2001 From: Shunsuke Suzuki Date: Sat, 12 Oct 2024 17:49:29 +0900 Subject: [PATCH 2/2] fix: fix compile errors --- pkg/cli/cp/command.go | 2 +- pkg/cli/exec/command.go | 2 +- pkg/cli/generate/command.go | 2 +- pkg/cli/genr/command.go | 2 +- pkg/cli/initcmd/command.go | 2 +- pkg/cli/install/command.go | 2 +- pkg/cli/list/command.go | 2 +- pkg/cli/remove/command.go | 2 +- pkg/cli/upc/command.go | 2 +- pkg/cli/update/command.go | 2 +- pkg/cli/updateaqua/command.go | 2 +- pkg/cli/which/command.go | 2 +- pkg/controller/wire.go | 25 +++++++++--------- pkg/controller/wire_gen.go | 49 ++++++++++++++++++----------------- pkg/github/github_test.go | 3 ++- 15 files changed, 52 insertions(+), 49 deletions(-) diff --git a/pkg/cli/cp/command.go b/pkg/cli/cp/command.go index 56315a8d3..c84e5ddd5 100644 --- a/pkg/cli/cp/command.go +++ b/pkg/cli/cp/command.go @@ -85,7 +85,7 @@ func (i *command) action(c *cli.Context) error { return fmt.Errorf("parse the command line arguments: %w", err) } param.SkipLink = true - ctrl, err := controller.InitializeCopyCommandController(c.Context, param, http.DefaultClient, i.r.Runtime) + ctrl, err := controller.InitializeCopyCommandController(c.Context, i.r.LogE, param, http.DefaultClient, i.r.Runtime) if err != nil { return fmt.Errorf("initialize a CopyController: %w", err) } diff --git a/pkg/cli/exec/command.go b/pkg/cli/exec/command.go index 16f136306..a4f08bf07 100644 --- a/pkg/cli/exec/command.go +++ b/pkg/cli/exec/command.go @@ -46,7 +46,7 @@ func (i *command) action(c *cli.Context) error { if err := util.SetParam(c, i.r.LogE, "exec", param, i.r.LDFlags); err != nil { return fmt.Errorf("parse the command line arguments: %w", err) } - ctrl, err := controller.InitializeExecCommandController(c.Context, param, http.DefaultClient, i.r.Runtime) + ctrl, err := controller.InitializeExecCommandController(c.Context, i.r.LogE, param, http.DefaultClient, i.r.Runtime) if err != nil { return fmt.Errorf("initialize a ExecController: %w", err) } diff --git a/pkg/cli/generate/command.go b/pkg/cli/generate/command.go index e3b3e0020..a565e3226 100644 --- a/pkg/cli/generate/command.go +++ b/pkg/cli/generate/command.go @@ -79,7 +79,7 @@ func (i *command) action(c *cli.Context) error { if err := util.SetParam(c, i.r.LogE, "generate", param, i.r.LDFlags); err != nil { return fmt.Errorf("parse the command line arguments: %w", err) } - ctrl := controller.InitializeGenerateCommandController(c.Context, param, http.DefaultClient, i.r.Runtime) + ctrl := controller.InitializeGenerateCommandController(c.Context, i.r.LogE, param, http.DefaultClient, i.r.Runtime) return ctrl.Generate(c.Context, i.r.LogE, param, c.Args().Slice()...) //nolint:wrapcheck } diff --git a/pkg/cli/genr/command.go b/pkg/cli/genr/command.go index b3526c2d3..ceb55561c 100644 --- a/pkg/cli/genr/command.go +++ b/pkg/cli/genr/command.go @@ -132,6 +132,6 @@ func (i *command) action(c *cli.Context) error { if err := util.SetParam(c, i.r.LogE, "generate-registry", param, i.r.LDFlags); err != nil { return fmt.Errorf("parse the command line arguments: %w", err) } - ctrl := controller.InitializeGenerateRegistryCommandController(c.Context, param, http.DefaultClient, os.Stdout) + ctrl := controller.InitializeGenerateRegistryCommandController(c.Context, i.r.LogE, param, http.DefaultClient, os.Stdout) return ctrl.GenerateRegistry(c.Context, param, i.r.LogE, c.Args().Slice()...) //nolint:wrapcheck } diff --git a/pkg/cli/initcmd/command.go b/pkg/cli/initcmd/command.go index 7e0165610..fb179cc86 100644 --- a/pkg/cli/initcmd/command.go +++ b/pkg/cli/initcmd/command.go @@ -42,6 +42,6 @@ func (ic *initCommand) action(c *cli.Context) error { if err := util.SetParam(c, ic.r.LogE, "init", param, ic.r.LDFlags); err != nil { return fmt.Errorf("parse the command line arguments: %w", err) } - ctrl := controller.InitializeInitCommandController(c.Context, param) + ctrl := controller.InitializeInitCommandController(c.Context, ic.r.LogE, param) return ctrl.Init(c.Context, ic.r.LogE, c.Args().First()) //nolint:wrapcheck } diff --git a/pkg/cli/install/command.go b/pkg/cli/install/command.go index fb055b739..bae5a5814 100644 --- a/pkg/cli/install/command.go +++ b/pkg/cli/install/command.go @@ -84,7 +84,7 @@ func (i *command) action(c *cli.Context) error { if err := util.SetParam(c, i.r.LogE, "install", param, i.r.LDFlags); err != nil { return fmt.Errorf("parse the command line arguments: %w", err) } - ctrl, err := controller.InitializeInstallCommandController(c.Context, param, http.DefaultClient, i.r.Runtime) + ctrl, err := controller.InitializeInstallCommandController(c.Context, i.r.LogE, param, http.DefaultClient, i.r.Runtime) if err != nil { return fmt.Errorf("initialize a InstallController: %w", err) } diff --git a/pkg/cli/list/command.go b/pkg/cli/list/command.go index 0686d3b93..815561a79 100644 --- a/pkg/cli/list/command.go +++ b/pkg/cli/list/command.go @@ -71,6 +71,6 @@ func (i *command) action(c *cli.Context) error { if err := util.SetParam(c, i.r.LogE, "list", param, i.r.LDFlags); err != nil { return fmt.Errorf("parse the command line arguments: %w", err) } - ctrl := controller.InitializeListCommandController(c.Context, param, http.DefaultClient, i.r.Runtime) + ctrl := controller.InitializeListCommandController(c.Context, i.r.LogE, param, http.DefaultClient, i.r.Runtime) return ctrl.List(c.Context, i.r.LogE, param) //nolint:wrapcheck } diff --git a/pkg/cli/remove/command.go b/pkg/cli/remove/command.go index 85b8c7181..af9d0ff65 100644 --- a/pkg/cli/remove/command.go +++ b/pkg/cli/remove/command.go @@ -88,7 +88,7 @@ func (i *command) action(c *cli.Context) error { return fmt.Errorf("parse the command line arguments: %w", err) } param.SkipLink = true - ctrl := controller.InitializeRemoveCommandController(c.Context, param, http.DefaultClient, i.r.Runtime, mode) + ctrl := controller.InitializeRemoveCommandController(c.Context, i.r.LogE, param, http.DefaultClient, i.r.Runtime, mode) if err := ctrl.Remove(c.Context, i.r.LogE, param); err != nil { return err //nolint:wrapcheck } diff --git a/pkg/cli/upc/command.go b/pkg/cli/upc/command.go index d1afc4263..b618564ee 100644 --- a/pkg/cli/upc/command.go +++ b/pkg/cli/upc/command.go @@ -71,6 +71,6 @@ func (i *command) action(c *cli.Context) error { if err := util.SetParam(c, i.r.LogE, "update-checksum", param, i.r.LDFlags); err != nil { return fmt.Errorf("parse the command line arguments: %w", err) } - ctrl := controller.InitializeUpdateChecksumCommandController(c.Context, param, http.DefaultClient, i.r.Runtime) + ctrl := controller.InitializeUpdateChecksumCommandController(c.Context, i.r.LogE, param, http.DefaultClient, i.r.Runtime) return ctrl.UpdateChecksum(c.Context, i.r.LogE, param) //nolint:wrapcheck } diff --git a/pkg/cli/update/command.go b/pkg/cli/update/command.go index 9b9035ebc..f8344c60f 100644 --- a/pkg/cli/update/command.go +++ b/pkg/cli/update/command.go @@ -139,6 +139,6 @@ func (i *command) action(c *cli.Context) error { if err := util.SetParam(c, i.r.LogE, "update", param, i.r.LDFlags); err != nil { return fmt.Errorf("parse the command line arguments: %w", err) } - ctrl := controller.InitializeUpdateCommandController(c.Context, param, http.DefaultClient, i.r.Runtime) + ctrl := controller.InitializeUpdateCommandController(c.Context, i.r.LogE, param, http.DefaultClient, i.r.Runtime) return ctrl.Update(c.Context, i.r.LogE, param) //nolint:wrapcheck } diff --git a/pkg/cli/updateaqua/command.go b/pkg/cli/updateaqua/command.go index cd7114915..0e33c7920 100644 --- a/pkg/cli/updateaqua/command.go +++ b/pkg/cli/updateaqua/command.go @@ -52,7 +52,7 @@ func (ua *updateAquaCommand) action(c *cli.Context) error { if err := util.SetParam(c, ua.r.LogE, "update-aqua", param, ua.r.LDFlags); err != nil { return fmt.Errorf("parse the command line arguments: %w", err) } - ctrl, err := controller.InitializeUpdateAquaCommandController(c.Context, param, http.DefaultClient, ua.r.Runtime) + ctrl, err := controller.InitializeUpdateAquaCommandController(c.Context, ua.r.LogE, param, http.DefaultClient, ua.r.Runtime) if err != nil { return fmt.Errorf("initialize a UpdateAquaController: %w", err) } diff --git a/pkg/cli/which/command.go b/pkg/cli/which/command.go index 3954c514e..6c01eff6e 100644 --- a/pkg/cli/which/command.go +++ b/pkg/cli/which/command.go @@ -70,7 +70,7 @@ func (i *command) action(c *cli.Context) error { if err := util.SetParam(c, i.r.LogE, "which", param, i.r.LDFlags); err != nil { return fmt.Errorf("parse the command line arguments: %w", err) } - ctrl := controller.InitializeWhichCommandController(c.Context, param, http.DefaultClient, i.r.Runtime) + ctrl := controller.InitializeWhichCommandController(c.Context, i.r.LogE, param, http.DefaultClient, i.r.Runtime) exeName, _, err := ParseExecArgs(c.Args().Slice()) if err != nil { return err diff --git a/pkg/controller/wire.go b/pkg/controller/wire.go index e114c1301..edd6dccdb 100644 --- a/pkg/controller/wire.go +++ b/pkg/controller/wire.go @@ -46,13 +46,14 @@ import ( "github.com/aquaproj/aqua/v2/pkg/slsa" "github.com/aquaproj/aqua/v2/pkg/unarchive" "github.com/aquaproj/aqua/v2/pkg/versiongetter" + "github.com/sirupsen/logrus" "github.com/google/wire" "github.com/spf13/afero" "github.com/suzuki-shunsuke/go-osenv/osenv" ) -func InitializeListCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *list.Controller { +func InitializeListCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *list.Controller { wire.Build( list.NewController, wire.NewSet( @@ -105,7 +106,7 @@ func InitializeListCommandController(ctx context.Context, param *config.Param, h return &list.Controller{} } -func InitializeGenerateRegistryCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, stdout io.Writer) *genrgst.Controller { +func InitializeGenerateRegistryCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, stdout io.Writer) *genrgst.Controller { wire.Build( genrgst.NewController, wire.NewSet( @@ -125,7 +126,7 @@ func InitializeGenerateRegistryCommandController(ctx context.Context, param *con return &genrgst.Controller{} } -func InitializeInitCommandController(ctx context.Context, param *config.Param) *initcmd.Controller { +func InitializeInitCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param) *initcmd.Controller { wire.Build( initcmd.New, wire.NewSet( @@ -145,7 +146,7 @@ func InitializeInitPolicyCommandController(ctx context.Context) *initpolicy.Cont return &initpolicy.Controller{} } -func InitializeGenerateCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *generate.Controller { +func InitializeGenerateCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *generate.Controller { wire.Build( generate.New, wire.NewSet( @@ -222,7 +223,7 @@ func InitializeGenerateCommandController(ctx context.Context, param *config.Para return &generate.Controller{} } -func InitializeInstallCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*install.Controller, error) { +func InitializeInstallCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*install.Controller, error) { wire.Build( install.New, wire.NewSet( @@ -346,7 +347,7 @@ func InitializeInstallCommandController(ctx context.Context, param *config.Param return &install.Controller{}, nil } -func InitializeWhichCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *which.Controller { +func InitializeWhichCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *which.Controller { wire.Build( which.New, wire.NewSet( @@ -405,7 +406,7 @@ func InitializeWhichCommandController(ctx context.Context, param *config.Param, return nil } -func InitializeExecCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*cexec.Controller, error) { +func InitializeExecCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*cexec.Controller, error) { wire.Build( cexec.New, wire.NewSet( @@ -536,7 +537,7 @@ func InitializeExecCommandController(ctx context.Context, param *config.Param, h return &cexec.Controller{}, nil } -func InitializeUpdateAquaCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*updateaqua.Controller, error) { +func InitializeUpdateAquaCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*updateaqua.Controller, error) { wire.Build( updateaqua.New, wire.NewSet( @@ -628,7 +629,7 @@ func InitializeUpdateAquaCommandController(ctx context.Context, param *config.Pa return &updateaqua.Controller{}, nil } -func InitializeCopyCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*cp.Controller, error) { +func InitializeCopyCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*cp.Controller, error) { wire.Build( cp.New, wire.NewSet( @@ -768,7 +769,7 @@ func InitializeCopyCommandController(ctx context.Context, param *config.Param, h return &cp.Controller{}, nil } -func InitializeUpdateChecksumCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *updatechecksum.Controller { +func InitializeUpdateChecksumCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *updatechecksum.Controller { wire.Build( updatechecksum.New, wire.NewSet( @@ -827,7 +828,7 @@ func InitializeUpdateChecksumCommandController(ctx context.Context, param *confi return &updatechecksum.Controller{} } -func InitializeUpdateCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *update.Controller { +func InitializeUpdateCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *update.Controller { wire.Build( update.New, wire.NewSet( @@ -960,7 +961,7 @@ func InitializeInfoCommandController(ctx context.Context, param *config.Param, r return &info.Controller{} } -func InitializeRemoveCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime, target *config.RemoveMode) *remove.Controller { +func InitializeRemoveCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime, target *config.RemoveMode) *remove.Controller { wire.Build( remove.New, wire.NewSet( diff --git a/pkg/controller/wire_gen.go b/pkg/controller/wire_gen.go index e7af48ed8..ba4286446 100644 --- a/pkg/controller/wire_gen.go +++ b/pkg/controller/wire_gen.go @@ -45,6 +45,7 @@ import ( "github.com/aquaproj/aqua/v2/pkg/slsa" "github.com/aquaproj/aqua/v2/pkg/unarchive" "github.com/aquaproj/aqua/v2/pkg/versiongetter" + "github.com/sirupsen/logrus" "github.com/spf13/afero" "github.com/suzuki-shunsuke/go-osenv/osenv" "io" @@ -53,11 +54,11 @@ import ( // Injectors from wire.go: -func InitializeListCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *list.Controller { +func InitializeListCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *list.Controller { fs := afero.NewOsFs() configFinder := finder.NewConfigFinder(fs) configReader := reader.New(fs, param) - repositoriesService := github.New(ctx) + repositoriesService := github.New(ctx, logE) httpDownloader := download.NewHTTPDownloader(httpClient) gitHubContentFileDownloader := download.NewGitHubContentFileDownloader(repositoriesService, httpDownloader) executor := osexec.New() @@ -70,17 +71,17 @@ func InitializeListCommandController(ctx context.Context, param *config.Param, h return controller } -func InitializeGenerateRegistryCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, stdout io.Writer) *genrgst.Controller { +func InitializeGenerateRegistryCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, stdout io.Writer) *genrgst.Controller { fs := afero.NewOsFs() - repositoriesService := github.New(ctx) + repositoriesService := github.New(ctx, logE) outputter := output.New(stdout, fs) client := cargo.NewClient(httpClient) controller := genrgst.NewController(fs, repositoriesService, outputter, client) return controller } -func InitializeInitCommandController(ctx context.Context, param *config.Param) *initcmd.Controller { - repositoriesService := github.New(ctx) +func InitializeInitCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param) *initcmd.Controller { + repositoriesService := github.New(ctx, logE) fs := afero.NewOsFs() controller := initcmd.New(repositoriesService, fs) return controller @@ -92,11 +93,11 @@ func InitializeInitPolicyCommandController(ctx context.Context) *initpolicy.Cont return controller } -func InitializeGenerateCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *generate.Controller { +func InitializeGenerateCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *generate.Controller { fs := afero.NewOsFs() configFinder := finder.NewConfigFinder(fs) configReader := reader.New(fs, param) - repositoriesService := github.New(ctx) + repositoriesService := github.New(ctx, logE) httpDownloader := download.NewHTTPDownloader(httpClient) gitHubContentFileDownloader := download.NewGitHubContentFileDownloader(repositoriesService, httpDownloader) executor := osexec.New() @@ -116,11 +117,11 @@ func InitializeGenerateCommandController(ctx context.Context, param *config.Para return controller } -func InitializeInstallCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*install.Controller, error) { +func InitializeInstallCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*install.Controller, error) { fs := afero.NewOsFs() configFinder := finder.NewConfigFinder(fs) configReader := reader.New(fs, param) - repositoriesService := github.New(ctx) + repositoriesService := github.New(ctx, logE) httpDownloader := download.NewHTTPDownloader(httpClient) gitHubContentFileDownloader := download.NewGitHubContentFileDownloader(repositoriesService, httpDownloader) executor := osexec.New() @@ -155,11 +156,11 @@ func InitializeInstallCommandController(ctx context.Context, param *config.Param return controller, nil } -func InitializeWhichCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *which.Controller { +func InitializeWhichCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *which.Controller { fs := afero.NewOsFs() configFinder := finder.NewConfigFinder(fs) configReader := reader.New(fs, param) - repositoriesService := github.New(ctx) + repositoriesService := github.New(ctx, logE) httpDownloader := download.NewHTTPDownloader(httpClient) gitHubContentFileDownloader := download.NewGitHubContentFileDownloader(repositoriesService, httpDownloader) executor := osexec.New() @@ -174,8 +175,8 @@ func InitializeWhichCommandController(ctx context.Context, param *config.Param, return controller } -func InitializeExecCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*exec.Controller, error) { - repositoriesService := github.New(ctx) +func InitializeExecCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*exec.Controller, error) { + repositoriesService := github.New(ctx, logE) httpDownloader := download.NewHTTPDownloader(httpClient) downloader := download.NewDownloader(repositoriesService, httpDownloader) fs := afero.NewOsFs() @@ -215,9 +216,9 @@ func InitializeExecCommandController(ctx context.Context, param *config.Param, h return execController, nil } -func InitializeUpdateAquaCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*updateaqua.Controller, error) { +func InitializeUpdateAquaCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*updateaqua.Controller, error) { fs := afero.NewOsFs() - repositoriesService := github.New(ctx) + repositoriesService := github.New(ctx, logE) httpDownloader := download.NewHTTPDownloader(httpClient) downloader := download.NewDownloader(repositoriesService, httpDownloader) linker := link.New() @@ -246,8 +247,8 @@ func InitializeUpdateAquaCommandController(ctx context.Context, param *config.Pa return controller, nil } -func InitializeCopyCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*cp.Controller, error) { - repositoriesService := github.New(ctx) +func InitializeCopyCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) (*cp.Controller, error) { + repositoriesService := github.New(ctx, logE) httpDownloader := download.NewHTTPDownloader(httpClient) downloader := download.NewDownloader(repositoriesService, httpDownloader) fs := afero.NewOsFs() @@ -288,11 +289,11 @@ func InitializeCopyCommandController(ctx context.Context, param *config.Param, h return cpController, nil } -func InitializeUpdateChecksumCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *updatechecksum.Controller { +func InitializeUpdateChecksumCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *updatechecksum.Controller { fs := afero.NewOsFs() configFinder := finder.NewConfigFinder(fs) configReader := reader.New(fs, param) - repositoriesService := github.New(ctx) + repositoriesService := github.New(ctx, logE) httpDownloader := download.NewHTTPDownloader(httpClient) gitHubContentFileDownloader := download.NewGitHubContentFileDownloader(repositoriesService, httpDownloader) executor := osexec.New() @@ -306,8 +307,8 @@ func InitializeUpdateChecksumCommandController(ctx context.Context, param *confi return controller } -func InitializeUpdateCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *update.Controller { - repositoriesService := github.New(ctx) +func InitializeUpdateCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime) *update.Controller { + repositoriesService := github.New(ctx, logE) fs := afero.NewOsFs() configFinder := finder.NewConfigFinder(fs) configReader := reader.New(fs, param) @@ -356,11 +357,11 @@ func InitializeInfoCommandController(ctx context.Context, param *config.Param, r return controller } -func InitializeRemoveCommandController(ctx context.Context, param *config.Param, httpClient *http.Client, rt *runtime.Runtime, target *config.RemoveMode) *remove.Controller { +func InitializeRemoveCommandController(ctx context.Context, logE *logrus.Entry, param *config.Param, httpClient *http.Client, rt *runtime.Runtime, target *config.RemoveMode) *remove.Controller { fs := afero.NewOsFs() configFinder := finder.NewConfigFinder(fs) configReader := reader.New(fs, param) - repositoriesService := github.New(ctx) + repositoriesService := github.New(ctx, logE) httpDownloader := download.NewHTTPDownloader(httpClient) gitHubContentFileDownloader := download.NewGitHubContentFileDownloader(repositoriesService, httpDownloader) executor := osexec.New() diff --git a/pkg/github/github_test.go b/pkg/github/github_test.go index e1d03e8a5..30bd02826 100644 --- a/pkg/github/github_test.go +++ b/pkg/github/github_test.go @@ -5,11 +5,12 @@ import ( "testing" "github.com/aquaproj/aqua/v2/pkg/github" + "github.com/sirupsen/logrus" ) func TestNew(t *testing.T) { t.Parallel() - if client := github.New(context.Background()); client == nil { + if client := github.New(context.Background(), logrus.NewEntry(logrus.New())); client == nil { t.Fatal("client must not be nil") } }