diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-02-19 15:11:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-19 15:11:54 +0100 |
commit | cba5791a5db8980a7952b111b8b846ca15bb6980 (patch) | |
tree | 2b5357c868dc892a2f85bff7d5adf107454ce4b3 /cmd/podman | |
parent | 1bed53b02c2f65ba26dc320a797c6fe473fce9a1 (diff) | |
parent | 4c135017b228280e1dd2bd6693fdf2edb44b682a (diff) | |
download | podman-cba5791a5db8980a7952b111b8b846ca15bb6980.tar.gz podman-cba5791a5db8980a7952b111b8b846ca15bb6980.tar.bz2 podman-cba5791a5db8980a7952b111b8b846ca15bb6980.zip |
Merge pull request #5233 from QiWang19/login/out-parameter
fix mandatory parameter in login/logout
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/login.go | 14 | ||||
-rw-r--r-- | cmd/podman/logout.go | 12 |
2 files changed, 22 insertions, 4 deletions
diff --git a/cmd/podman/login.go b/cmd/podman/login.go index 369e0da16..e5ff273b8 100644 --- a/cmd/podman/login.go +++ b/cmd/podman/login.go @@ -12,6 +12,7 @@ import ( "github.com/containers/image/v5/types" "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/libpod/image" + "github.com/containers/libpod/pkg/registries" "github.com/docker/docker-credential-helpers/credentials" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -67,10 +68,19 @@ func loginCmd(c *cliconfig.LoginValues) error { if len(args) > 1 { return errors.Errorf("too many arguments, login takes only 1 argument") } + var server string if len(args) == 0 { - return errors.Errorf("please specify a registry to login to") + registriesFromFile, err := registries.GetRegistries() + if err != nil || len(registriesFromFile) == 0 { + return errors.Errorf("please specify a registry to login to") + } + + server = registriesFromFile[0] + logrus.Debugf("registry not specified, default to the first registry %q from registries.conf", server) + + } else { + server = registryFromFullName(scrubServer(args[0])) } - server := registryFromFullName(scrubServer(args[0])) sc := image.GetSystemContext("", c.Authfile, false) if c.Flag("tls-verify").Changed { diff --git a/cmd/podman/logout.go b/cmd/podman/logout.go index 4a113b1d0..dec6822cf 100644 --- a/cmd/podman/logout.go +++ b/cmd/podman/logout.go @@ -8,7 +8,9 @@ import ( "github.com/containers/image/v5/pkg/docker/config" "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/shared" + "github.com/containers/libpod/pkg/registries" "github.com/pkg/errors" + "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -51,10 +53,16 @@ func logoutCmd(c *cliconfig.LogoutValues) error { if len(args) > 1 { return errors.Errorf("too many arguments, logout takes at most 1 argument") } + var server string if len(args) == 0 && !c.All { - return errors.Errorf("registry must be given") + registriesFromFile, err := registries.GetRegistries() + if err != nil || len(registriesFromFile) == 0 { + return errors.Errorf("no registries found in registries.conf, a registry must be provided") + } + + server = registriesFromFile[0] + logrus.Debugf("registry not specified, default to the first registry %q from registries.conf", server) } - var server string if len(args) == 1 { server = scrubServer(args[0]) } |