diff --git a/Gopkg.lock b/Gopkg.lock index aeaf0ece9..39cb8eb22 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -91,6 +91,22 @@ revision = "b4f55832432b95a611cf1495272b5c8e24952a1a" version = "v1.13.0" +[[projects]] + digest = "1:f9ae348e1f793dcf9ed930ed47136a67343dbd6809c5c91391322267f4476892" + name = "github.com/Microsoft/go-winio" + packages = ["."] + pruneopts = "UT" + revision = "1a8911d1ed007260465c3bfbbc785ac6915a0bb8" + version = "v0.4.12" + +[[projects]] + branch = "master" + digest = "1:3721a10686511b80c052323423f0de17a8c06d417dbdd3b392b1578432a33aae" + name = "github.com/Nvveen/Gotty" + packages = ["."] + pruneopts = "UT" + revision = "cd527374f1e5bff4938207604a14f2e38a9cf512" + [[projects]] digest = "1:d1665c44bd5db19aaee18d1b6233c99b0b9a986e8bccb24ef54747547a48027f" name = "github.com/PuerkitoBio/purell" @@ -201,6 +217,14 @@ revision = "894b81a4b802e4eb2a91d1ce216b8817763c29fb" version = "v1.2.6" +[[projects]] + branch = "master" + digest = "1:e48c63e818c67fbf3d7afe20bba33134ab1a5bf384847385384fd027652a5a96" + name = "github.com/containerd/continuity" + packages = ["pathdriver"] + pruneopts = "UT" + revision = "004b46473808b3e7a4a3049c20e4376c91eb966d" + [[projects]] digest = "1:7cb4fdca4c251b3ef8027c90ea35f70c7b661a593b9eeae34753c65499098bb1" name = "github.com/cpuguy83/go-md2man" @@ -218,9 +242,11 @@ version = "v1.1.1" [[projects]] - digest = "1:a74c8901dcf32f45e57e82403dd788b1ce0bcf82c62b4d147cdd41f70e65dc1c" + digest = "1:a841cef1b22bee47aa59c3d9cc4bca4f419c864b03012606fa5b67aef08eab5d" name = "github.com/deislabs/oras" packages = [ + "pkg/auth", + "pkg/auth/docker", "pkg/content", "pkg/oras", ] @@ -235,6 +261,19 @@ revision = "06ea1031745cb8b3dab3f6a236daf2b0aa468b7e" version = "v3.2.0" +[[projects]] + digest = "1:f65090e4f60dcd4d2de69e8ebca022d59a8c6463a3a4c122e64cec91a83749ff" + name = "github.com/docker/cli" + packages = [ + "cli/config", + "cli/config/configfile", + "cli/config/credentials", + "opts", + ] + pruneopts = "UT" + revision = "c89750f836c57ce10386e71669e1b08a54c3caeb" + version = "v18.09.5" + [[projects]] digest = "1:888aaacf886021e4a0fa6b09a61f1158063bd6c2e2ddefe14f3a7ccbc93ffe27" name = "github.com/docker/distribution" @@ -285,15 +324,61 @@ [[projects]] branch = "master" - digest = "1:8da8bb2b12c31c632e96ca6f15666a36c36cd390326b6c5e1c5e309cf4b5419a" + digest = "1:b5be0d9940d8fa3ff7df4949a8e8c47a7f93ea8251239ad074e1a6b0db55876a" name = "github.com/docker/docker" packages = [ + "api/types", + "api/types/blkiodev", + "api/types/container", + "api/types/filters", + "api/types/mount", + "api/types/network", + "api/types/registry", + "api/types/strslice", + "api/types/swarm", + "api/types/swarm/runtime", + "api/types/versions", + "errdefs", + "pkg/homedir", + "pkg/idtools", + "pkg/ioutils", + "pkg/jsonmessage", + "pkg/longpath", + "pkg/mount", + "pkg/stringid", + "pkg/system", + "pkg/tarsum", "pkg/term", "pkg/term/windows", + "registry", + "registry/resumable", ] pruneopts = "UT" revision = "2cb26cfe9cbf8a64c5046c74d65f4528b22e67f4" +[[projects]] + digest = "1:8866486038791fe65ea1abf660041423954b1f3fb99ea6a0ad8424422e943458" + name = "github.com/docker/docker-credential-helpers" + packages = [ + "client", + "credentials", + ] + pruneopts = "UT" + revision = "5241b46610f2491efdf9d1c85f1ddf5b02f6d962" + version = "v0.6.1" + +[[projects]] + digest = "1:811c86996b1ca46729bad2724d4499014c4b9effd05ef8c71b852aad90deb0ce" + name = "github.com/docker/go-connections" + packages = [ + "nat", + "sockets", + "tlsconfig", + ] + pruneopts = "UT" + revision = "7395e3f8aa162843a74ed6d48e79627d9792ac55" + version = "v0.4.0" + [[projects]] branch = "master" digest = "1:2b126e77be4ab4b92cdb3924c87894dd76bf365ba282f358a13133e848aa0059" @@ -710,6 +795,14 @@ revision = "d60099175f88c47cd379c4738d158884749ed235" version = "v1.0.1" +[[projects]] + digest = "1:38ee335aedf4626620f3cf8f605661e71abdcce7b40b38921962beb3980f0a20" + name = "github.com/opencontainers/runc" + packages = ["libcontainer/user"] + pruneopts = "UT" + revision = "baf6536d6259209c3edfa2b22237af82942d3dfa" + version = "v0.1.1" + [[projects]] branch = "master" digest = "1:3bf17a6e6eaa6ad24152148a631d18662f7212e21637c2699bff3369b7f00fa2" @@ -913,7 +1006,7 @@ [[projects]] branch = "master" - digest = "1:647b0128e9a9886335bfb6c9a1fc97758b7f846ec42f222933f6fee6730c96e2" + digest = "1:80c256dfc14840e13293d6404b7774e497187bd15a53f943f99bfaef4bbb2e42" name = "golang.org/x/net" packages = [ "bpf", @@ -925,9 +1018,11 @@ "idna", "internal/iana", "internal/socket", + "internal/socks", "internal/timeseries", "ipv4", "ipv6", + "proxy", "publicsuffix", "trace", ] @@ -1654,6 +1749,8 @@ "github.com/containerd/containerd/reference", "github.com/containerd/containerd/remotes", "github.com/containerd/containerd/remotes/docker", + "github.com/deislabs/oras/pkg/auth", + "github.com/deislabs/oras/pkg/auth/docker", "github.com/deislabs/oras/pkg/content", "github.com/deislabs/oras/pkg/oras", "github.com/docker/distribution/configuration", diff --git a/Gopkg.toml b/Gopkg.toml index f25d6a9f1..662a196ee 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -76,11 +76,6 @@ branch = "master" source = "https://github.com/dmcgowan/letsencrypt.git" -# https://github.com/bugsnag/bugsnag-go/issues/96 -[[override]] - name = "github.com/bugsnag/bugsnag-go" - version = "=1.3.2" - # gopkg.in is broken # # https://github.com/golang/dep/issues/1760 diff --git a/cmd/helm/chart_login.go b/cmd/helm/chart_login.go index 6a9ad282d..729c68f3d 100644 --- a/cmd/helm/chart_login.go +++ b/cmd/helm/chart_login.go @@ -26,7 +26,7 @@ import ( ) const chartLoginDesc = ` -Authenticate against a remote registry. +Authenticate to a remote registry. ` func newChartLoginCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { @@ -36,8 +36,8 @@ func newChartLoginCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { Long: chartLoginDesc, Args: require.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - host := args[0] - return action.NewChartLogin(cfg).Run(out, host, "myuser", "mypass") + hostname := args[0] + return action.NewChartLogin(cfg).Run(out, hostname, "myuser", "mypass") }, } } diff --git a/cmd/helm/chart_logout.go b/cmd/helm/chart_logout.go index ae016dcd7..77300a89d 100644 --- a/cmd/helm/chart_logout.go +++ b/cmd/helm/chart_logout.go @@ -36,8 +36,8 @@ func newChartLogoutCmd(cfg *action.Configuration, out io.Writer) *cobra.Command Long: chartLogoutDesc, Args: require.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { - host := args[0] - return action.NewChartLogout(cfg).Run(out, host) + hostname := args[0] + return action.NewChartLogout(cfg).Run(out, hostname) }, } } diff --git a/cmd/helm/root.go b/cmd/helm/root.go index 5a6f43d6e..de242990d 100644 --- a/cmd/helm/root.go +++ b/cmd/helm/root.go @@ -17,9 +17,11 @@ limitations under the License. package main // import "helm.sh/helm/cmd/helm" import ( + "context" "io" + "path/filepath" - "github.com/containerd/containerd/remotes/docker" + auth "github.com/deislabs/oras/pkg/auth/docker" "github.com/spf13/cobra" "helm.sh/helm/cmd/helm/require" @@ -68,10 +70,17 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string // Add the registry client based on settings // TODO: Move this elsewhere (first, settings.Init() must move) + // TODO: handle errors + credentialsFile := filepath.Join(settings.Home.Registry(), registry.CredentialsFileBasename) + client, _ := auth.NewClient(credentialsFile) + resolver, _ := client.Resolver(context.Background()) actionConfig.RegistryClient = registry.NewClient(®istry.ClientOptions{ Out: out, + Authorizer: registry.Authorizer{ + Client: client, + }, Resolver: registry.Resolver{ - Resolver: docker.NewResolver(docker.ResolverOptions{}), + Resolver: resolver, }, CacheRootDir: settings.Home.Registry(), }) diff --git a/pkg/action/chart_login.go b/pkg/action/chart_login.go index a5eff652e..639a2f3a7 100644 --- a/pkg/action/chart_login.go +++ b/pkg/action/chart_login.go @@ -17,11 +17,7 @@ limitations under the License. package action import ( - "context" - "fmt" "io" - - auth "github.com/deislabs/oras/pkg/auth/docker" ) // ChartLogin performs a chart login operation. @@ -37,14 +33,6 @@ func NewChartLogin(cfg *Configuration) *ChartLogin { } // Run executes the chart login operation -func (a *ChartLogin) Run(out io.Writer, host string, username string, password string) error { - cli, err := auth.NewClient("~/.docker/config") - if err != nil { - return err - } - if err := cli.Login(context.Background(), host, username, password); err != nil { - return err - } - fmt.Println("Login Succeeded") - return nil +func (a *ChartLogin) Run(out io.Writer, hostname string, username string, password string) error { + return a.cfg.RegistryClient.Login(hostname, username, password) } diff --git a/pkg/action/chart_logout.go b/pkg/action/chart_logout.go index d4cf73203..1cbf5efe1 100644 --- a/pkg/action/chart_logout.go +++ b/pkg/action/chart_logout.go @@ -17,11 +17,7 @@ limitations under the License. package action import ( - "context" - "fmt" "io" - - auth "github.com/deislabs/oras/pkg/auth/docker" ) // ChartLogout performs a chart login operation. @@ -37,14 +33,6 @@ func NewChartLogout(cfg *Configuration) *ChartLogout { } // Run executes the chart logout operation -func (a *ChartLogout) Run(out io.Writer, host string) error { - cli, err := auth.NewClient("~/.docker/config") - if err != nil { - return err - } - if err := cli.Logout(context.Background(), host); err != nil { - return err - } - fmt.Println("Logout Succeeded") - return nil +func (a *ChartLogout) Run(out io.Writer, hostname string) error { + return a.cfg.RegistryClient.Logout(hostname) } diff --git a/pkg/registry/authorizer.go b/pkg/registry/authorizer.go new file mode 100644 index 000000000..c601b59d4 --- /dev/null +++ b/pkg/registry/authorizer.go @@ -0,0 +1,28 @@ +/* +Copyright The Helm Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package registry // import "helm.sh/helm/pkg/registry" + +import ( + "github.com/deislabs/oras/pkg/auth" +) + +type ( + // Authorizer handles registry auth operations + Authorizer struct { + auth.Client + } +) diff --git a/pkg/registry/client.go b/pkg/registry/client.go index a2244f816..f0a3876ef 100644 --- a/pkg/registry/client.go +++ b/pkg/registry/client.go @@ -28,27 +28,34 @@ import ( "helm.sh/helm/pkg/chart" ) +const ( + CredentialsFileBasename = "config" +) + type ( // ClientOptions is used to construct a new client ClientOptions struct { Out io.Writer + Authorizer Authorizer Resolver Resolver CacheRootDir string } // Client works with OCI-compliant registries and local Helm chart cache Client struct { - out io.Writer - resolver Resolver - cache *filesystemCache // TODO: something more robust + out io.Writer + authorizer Authorizer + resolver Resolver + cache *filesystemCache // TODO: something more robust } ) // NewClient returns a new registry client with config func NewClient(options *ClientOptions) *Client { return &Client{ - out: options.Out, - resolver: options.Resolver, + out: options.Out, + resolver: options.Resolver, + authorizer: options.Authorizer, cache: &filesystemCache{ out: options.Out, rootDir: options.CacheRootDir, @@ -57,6 +64,26 @@ func NewClient(options *ClientOptions) *Client { } } +// Login logs into a registry +func (c *Client) Login(hostname string, username string, password string) error { + err := c.authorizer.Login(context.Background(), hostname, username, password) + if err != nil { + return err + } + fmt.Fprint(c.out, "Login succeeded\n") + return nil +} + +// Logout logs out of a registry +func (c *Client) Logout(hostname string) error { + err := c.authorizer.Logout(context.Background(), hostname) + if err != nil { + return err + } + fmt.Fprint(c.out, "Logout succeeded\n") + return nil +} + // PushChart uploads a chart to a registry func (c *Client) PushChart(ref *Reference) error { c.setDefaultTag(ref)