summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorUrvashi Mohnani <umohnani@redhat.com>2018-11-30 13:27:56 +0000
committerUrvashi Mohnani <umohnani@redhat.com>2018-12-06 09:33:16 +0000
commita75b397ac140f575c3aa7357b94b89a303435395 (patch)
treeabca0acade6232cd5fe691049725bdf19d20b5cf /cmd
parent75b19ca8abe1957f3c48035767960a6b20c10519 (diff)
downloadpodman-a75b397ac140f575c3aa7357b94b89a303435395.tar.gz
podman-a75b397ac140f575c3aa7357b94b89a303435395.tar.bz2
podman-a75b397ac140f575c3aa7357b94b89a303435395.zip
Pick registry to login from full image name as well
podman login reg.io/username/image works as well now. It picks the registry and checks for authentication, if none exist it will prompt for username and password. If the credentials exist but are not valid, it will prompt the user for new valid credentials. Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/login.go43
1 files changed, 37 insertions, 6 deletions
diff --git a/cmd/podman/login.go b/cmd/podman/login.go
index aa26d1466..33ce8635f 100644
--- a/cmd/podman/login.go
+++ b/cmd/podman/login.go
@@ -2,7 +2,6 @@ package main
import (
"bufio"
- "context"
"fmt"
"os"
"strings"
@@ -60,27 +59,48 @@ func loginCmd(c *cli.Context) error {
if len(args) == 0 {
return errors.Errorf("registry must be given")
}
- server := scrubServer(args[0])
+ server := registryFromFullName(scrubServer(args[0]))
authfile := getAuthFile(c.String("authfile"))
sc := common.GetSystemContext("", authfile, false)
// username of user logged in to server (if one exists)
- userFromAuthFile, err := config.GetUserLoggedIn(sc, server)
+ userFromAuthFile, passFromAuthFile, err := config.GetAuthentication(sc, server)
if err != nil {
return errors.Wrapf(err, "error getting logged-in user")
}
- username, password, err := getUserAndPass(c.String("username"), c.String("password"), userFromAuthFile)
+
+ ctx := getContext()
+
+ var (
+ username string
+ password string
+ )
+
+ if userFromAuthFile != "" {
+ username = userFromAuthFile
+ password = passFromAuthFile
+ fmt.Println("Authenticating with existing credentials...")
+ if err := docker.CheckAuth(ctx, sc, username, password, server); err == nil {
+ fmt.Println("Existing credentials are valid. Already logged in to", server)
+ return nil
+ }
+ fmt.Println("Existing credentials are invalid, please enter valid username and password")
+ }
+
+ username, password, err = getUserAndPass(c.String("username"), c.String("password"), userFromAuthFile)
if err != nil {
return errors.Wrapf(err, "error getting username and password")
}
+
sc.DockerInsecureSkipTLSVerify = !c.BoolT("tls-verify")
if c.String("cert-dir") != "" {
sc.DockerCertPath = c.String("cert-dir")
}
- if err = docker.CheckAuth(context.TODO(), sc, username, password, server); err == nil {
- if err := config.SetAuthentication(sc, server, username, password); err != nil {
+ if err = docker.CheckAuth(ctx, sc, username, password, server); err == nil {
+ // Write the new credentials to the authfile
+ if err = config.SetAuthentication(sc, server, username, password); err != nil {
return err
}
}
@@ -126,3 +146,14 @@ func getUserAndPass(username, password, userFromAuthFile string) (string, string
}
return strings.TrimSpace(username), password, err
}
+
+// registryFromFullName gets the registry from the input. If the input is of the form
+// quay.io/myuser/myimage, it will parse it and just return quay.io
+// It also returns true if a full image name was given
+func registryFromFullName(input string) string {
+ split := strings.Split(input, "/")
+ if len(split) > 1 {
+ return split[0]
+ }
+ return split[0]
+}