diff --git a/cmd/helm/chart.go b/cmd/helm/chart.go index b0c59a2d0..293ab3635 100644 --- a/cmd/helm/chart.go +++ b/cmd/helm/chart.go @@ -18,14 +18,13 @@ package main import ( "io" - "github.com/sirupsen/logrus" "github.com/spf13/cobra" "helm.sh/helm/pkg/action" ) const chartHelp = ` -This command consists of multiple subcommands to interact with charts and registries. +This command consists of multiple subcommands to work with the chart cache. It can be used to push, pull, tag, list, or remove Helm charts. Example usage: @@ -39,8 +38,6 @@ func newChartCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { Long: chartHelp, } cmd.AddCommand( - newChartLoginCmd(cfg, out), - newChartLogoutCmd(cfg, out), newChartListCmd(cfg, out), newChartExportCmd(cfg, out), newChartPullCmd(cfg, out), @@ -50,8 +47,3 @@ func newChartCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { ) return cmd } - -// TODO remove once WARN lines removed from oras or containerd -func init() { - logrus.SetLevel(logrus.ErrorLevel) -} diff --git a/cmd/helm/registry.go b/cmd/helm/registry.go new file mode 100644 index 000000000..1ed885c83 --- /dev/null +++ b/cmd/helm/registry.go @@ -0,0 +1,45 @@ +/* +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 main + +import ( + "io" + + "github.com/spf13/cobra" + + "helm.sh/helm/pkg/action" +) + +const registryHelp = ` +This command consists of multiple subcommands to interact with registries. + +It can be used to login to or logout from a registry. +Example usage: + $ helm registry login [URL] +` + +func newRegistryCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { + cmd := &cobra.Command{ + Use: "registry", + Short: "login to or logout from a registry", + Long: registryHelp, + } + cmd.AddCommand( + newRegistryLoginCmd(cfg, out), + newRegistryLogoutCmd(cfg, out), + ) + return cmd +} diff --git a/cmd/helm/chart_login.go b/cmd/helm/registry_login.go similarity index 89% rename from cmd/helm/chart_login.go rename to cmd/helm/registry_login.go index a093dc38c..d40b1dd44 100644 --- a/cmd/helm/chart_login.go +++ b/cmd/helm/registry_login.go @@ -32,18 +32,18 @@ import ( "helm.sh/helm/pkg/action" ) -const chartLoginDesc = ` +const registryLoginDesc = ` Authenticate to a remote registry. ` -func newChartLoginCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { +func newRegistryLoginCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { var usernameOpt, passwordOpt string var passwordFromStdinOpt bool cmd := &cobra.Command{ Use: "login [host]", Short: "login to a registry", - Long: chartLoginDesc, + Long: registryLoginDesc, Args: require.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { hostname := args[0] @@ -53,7 +53,7 @@ func newChartLoginCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return err } - return action.NewChartLogin(cfg).Run(out, hostname, username, password) + return action.NewRegistryLogin(cfg).Run(out, hostname, username, password) }, } @@ -108,10 +108,10 @@ func getUsernamePassword(usernameOpt string, passwordOpt string, passwordFromStd return username, password, nil } -// Copied from https://github.com/deislabs/oras -func readLine(prompt string, slient bool) (string, error) { +// Copied/adapted from https://github.com/deislabs/oras +func readLine(prompt string, silent bool) (string, error) { fmt.Print(prompt) - if slient { + if silent { fd := os.Stdin.Fd() state, err := term.SaveState(fd) if err != nil { @@ -126,7 +126,7 @@ func readLine(prompt string, slient bool) (string, error) { if err != nil { return "", err } - if slient { + if silent { fmt.Println() } diff --git a/cmd/helm/chart_logout.go b/cmd/helm/registry_logout.go similarity index 82% rename from cmd/helm/chart_logout.go rename to cmd/helm/registry_logout.go index 77300a89d..099f4ee7b 100644 --- a/cmd/helm/chart_logout.go +++ b/cmd/helm/registry_logout.go @@ -25,19 +25,19 @@ import ( "helm.sh/helm/pkg/action" ) -const chartLogoutDesc = ` +const registryLogoutDesc = ` Remove credentials stored for a remote registry. ` -func newChartLogoutCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { +func newRegistryLogoutCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { return &cobra.Command{ Use: "logout [host]", Short: "logout from a registry", - Long: chartLogoutDesc, + Long: registryLogoutDesc, Args: require.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { hostname := args[0] - return action.NewChartLogout(cfg).Run(out, hostname) + return action.NewRegistryLogout(cfg).Run(out, hostname) }, } } diff --git a/cmd/helm/root.go b/cmd/helm/root.go index 4c744238f..f2124aba4 100644 --- a/cmd/helm/root.go +++ b/cmd/helm/root.go @@ -102,6 +102,9 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string newRepoCmd(out), newSearchCmd(out), newVerifyCmd(out), + + // registry/chart cache commands + newRegistryCmd(actionConfig, out), newChartCmd(actionConfig, out), // release commands diff --git a/pkg/action/chart_login.go b/pkg/action/registry_login.go similarity index 63% rename from pkg/action/chart_login.go rename to pkg/action/registry_login.go index 639a2f3a7..2192d49e8 100644 --- a/pkg/action/chart_login.go +++ b/pkg/action/registry_login.go @@ -20,19 +20,19 @@ import ( "io" ) -// ChartLogin performs a chart login operation. -type ChartLogin struct { +// RegistryLogin performs a registry login operation. +type RegistryLogin struct { cfg *Configuration } -// NewChartLogin creates a new ChartLogin object with the given configuration. -func NewChartLogin(cfg *Configuration) *ChartLogin { - return &ChartLogin{ +// NewRegistryLogin creates a new RegistryLogin object with the given configuration. +func NewRegistryLogin(cfg *Configuration) *RegistryLogin { + return &RegistryLogin{ cfg: cfg, } } -// Run executes the chart login operation -func (a *ChartLogin) Run(out io.Writer, hostname string, username string, password string) error { +// Run executes the registry login operation +func (a *RegistryLogin) 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/registry_logout.go similarity index 64% rename from pkg/action/chart_logout.go rename to pkg/action/registry_logout.go index 1cbf5efe1..69add4163 100644 --- a/pkg/action/chart_logout.go +++ b/pkg/action/registry_logout.go @@ -20,19 +20,19 @@ import ( "io" ) -// ChartLogout performs a chart login operation. -type ChartLogout struct { +// RegistryLogout performs a registry login operation. +type RegistryLogout struct { cfg *Configuration } -// NewChartLogout creates a new ChartLogout object with the given configuration. -func NewChartLogout(cfg *Configuration) *ChartLogout { - return &ChartLogout{ +// NewRegistryLogout creates a new RegistryLogout object with the given configuration. +func NewRegistryLogout(cfg *Configuration) *RegistryLogout { + return &RegistryLogout{ cfg: cfg, } } -// Run executes the chart logout operation -func (a *ChartLogout) Run(out io.Writer, hostname string) error { +// Run executes the registry logout operation +func (a *RegistryLogout) Run(out io.Writer, hostname string) error { return a.cfg.RegistryClient.Logout(hostname) }