summaryrefslogtreecommitdiff
path: root/cmd/podman/login.go
diff options
context:
space:
mode:
authorQi Wang <qiwan@redhat.com>2020-02-17 11:59:12 -0500
committerQi Wang <qiwan@redhat.com>2020-02-18 15:30:49 -0500
commit4c135017b228280e1dd2bd6693fdf2edb44b682a (patch)
treefa2699dc5742f54a1c7d8535df554deb2ad3cfce /cmd/podman/login.go
parent5dacee93950a97ea14180bb86f21e462101fe5ea (diff)
downloadpodman-4c135017b228280e1dd2bd6693fdf2edb44b682a.tar.gz
podman-4c135017b228280e1dd2bd6693fdf2edb44b682a.tar.bz2
podman-4c135017b228280e1dd2bd6693fdf2edb44b682a.zip
fix mandatory parameter in login/logout
fix #5146 Insted of using a registry as mandatory parameter, this path allows podman to use the first registry from registries.conf. Signed-off-by: Qi Wang <qiwan@redhat.com>
Diffstat (limited to 'cmd/podman/login.go')
-rw-r--r--cmd/podman/login.go14
1 files changed, 12 insertions, 2 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 {