move login/logout to new registry subcommand

Signed-off-by: Josh Dolitsky <jdolitsky@gmail.com>
pull/5597/head
Josh Dolitsky 7 years ago
parent a138699686
commit 7fef0b0701

@ -18,14 +18,13 @@ package main
import ( import (
"io" "io"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"helm.sh/helm/pkg/action" "helm.sh/helm/pkg/action"
) )
const chartHelp = ` 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. It can be used to push, pull, tag, list, or remove Helm charts.
Example usage: Example usage:
@ -39,8 +38,6 @@ func newChartCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
Long: chartHelp, Long: chartHelp,
} }
cmd.AddCommand( cmd.AddCommand(
newChartLoginCmd(cfg, out),
newChartLogoutCmd(cfg, out),
newChartListCmd(cfg, out), newChartListCmd(cfg, out),
newChartExportCmd(cfg, out), newChartExportCmd(cfg, out),
newChartPullCmd(cfg, out), newChartPullCmd(cfg, out),
@ -50,8 +47,3 @@ func newChartCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
) )
return cmd return cmd
} }
// TODO remove once WARN lines removed from oras or containerd
func init() {
logrus.SetLevel(logrus.ErrorLevel)
}

@ -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
}

@ -32,18 +32,18 @@ import (
"helm.sh/helm/pkg/action" "helm.sh/helm/pkg/action"
) )
const chartLoginDesc = ` const registryLoginDesc = `
Authenticate to a remote registry. 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 usernameOpt, passwordOpt string
var passwordFromStdinOpt bool var passwordFromStdinOpt bool
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "login [host]", Use: "login [host]",
Short: "login to a registry", Short: "login to a registry",
Long: chartLoginDesc, Long: registryLoginDesc,
Args: require.MinimumNArgs(1), Args: require.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
hostname := args[0] hostname := args[0]
@ -53,7 +53,7 @@ func newChartLoginCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
return err 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 return username, password, nil
} }
// Copied from https://github.com/deislabs/oras // Copied/adapted from https://github.com/deislabs/oras
func readLine(prompt string, slient bool) (string, error) { func readLine(prompt string, silent bool) (string, error) {
fmt.Print(prompt) fmt.Print(prompt)
if slient { if silent {
fd := os.Stdin.Fd() fd := os.Stdin.Fd()
state, err := term.SaveState(fd) state, err := term.SaveState(fd)
if err != nil { if err != nil {
@ -126,7 +126,7 @@ func readLine(prompt string, slient bool) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
if slient { if silent {
fmt.Println() fmt.Println()
} }

@ -25,19 +25,19 @@ import (
"helm.sh/helm/pkg/action" "helm.sh/helm/pkg/action"
) )
const chartLogoutDesc = ` const registryLogoutDesc = `
Remove credentials stored for a remote registry. 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{ return &cobra.Command{
Use: "logout [host]", Use: "logout [host]",
Short: "logout from a registry", Short: "logout from a registry",
Long: chartLogoutDesc, Long: registryLogoutDesc,
Args: require.MinimumNArgs(1), Args: require.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
hostname := args[0] hostname := args[0]
return action.NewChartLogout(cfg).Run(out, hostname) return action.NewRegistryLogout(cfg).Run(out, hostname)
}, },
} }
} }

@ -102,6 +102,9 @@ func newRootCmd(actionConfig *action.Configuration, out io.Writer, args []string
newRepoCmd(out), newRepoCmd(out),
newSearchCmd(out), newSearchCmd(out),
newVerifyCmd(out), newVerifyCmd(out),
// registry/chart cache commands
newRegistryCmd(actionConfig, out),
newChartCmd(actionConfig, out), newChartCmd(actionConfig, out),
// release commands // release commands

@ -20,19 +20,19 @@ import (
"io" "io"
) )
// ChartLogin performs a chart login operation. // RegistryLogin performs a registry login operation.
type ChartLogin struct { type RegistryLogin struct {
cfg *Configuration cfg *Configuration
} }
// NewChartLogin creates a new ChartLogin object with the given configuration. // NewRegistryLogin creates a new RegistryLogin object with the given configuration.
func NewChartLogin(cfg *Configuration) *ChartLogin { func NewRegistryLogin(cfg *Configuration) *RegistryLogin {
return &ChartLogin{ return &RegistryLogin{
cfg: cfg, cfg: cfg,
} }
} }
// Run executes the chart login operation // Run executes the registry login operation
func (a *ChartLogin) Run(out io.Writer, hostname string, username string, password string) error { func (a *RegistryLogin) Run(out io.Writer, hostname string, username string, password string) error {
return a.cfg.RegistryClient.Login(hostname, username, password) return a.cfg.RegistryClient.Login(hostname, username, password)
} }

@ -20,19 +20,19 @@ import (
"io" "io"
) )
// ChartLogout performs a chart login operation. // RegistryLogout performs a registry login operation.
type ChartLogout struct { type RegistryLogout struct {
cfg *Configuration cfg *Configuration
} }
// NewChartLogout creates a new ChartLogout object with the given configuration. // NewRegistryLogout creates a new RegistryLogout object with the given configuration.
func NewChartLogout(cfg *Configuration) *ChartLogout { func NewRegistryLogout(cfg *Configuration) *RegistryLogout {
return &ChartLogout{ return &RegistryLogout{
cfg: cfg, cfg: cfg,
} }
} }
// Run executes the chart logout operation // Run executes the registry logout operation
func (a *ChartLogout) Run(out io.Writer, hostname string) error { func (a *RegistryLogout) Run(out io.Writer, hostname string) error {
return a.cfg.RegistryClient.Logout(hostname) return a.cfg.RegistryClient.Logout(hostname)
} }
Loading…
Cancel
Save