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 (
"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)
}

@ -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"
)
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()
}

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

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

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

@ -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)
}
Loading…
Cancel
Save