summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2018-10-22 16:30:15 -0700
committerGitHub <noreply@github.com>2018-10-22 16:30:15 -0700
commit58a26ac9dcb0d75ca7f061941c1399a28579ed69 (patch)
tree9682264be226052e9ccc4327e3d55e8097c690dc /cmd
parent5b2478ed87eedd8178c1672a786f95a6716a8edb (diff)
parente75b3477ce2acf8af49a13e8197401ee00bff459 (diff)
downloadpodman-58a26ac9dcb0d75ca7f061941c1399a28579ed69.tar.gz
podman-58a26ac9dcb0d75ca7f061941c1399a28579ed69.tar.bz2
podman-58a26ac9dcb0d75ca7f061941c1399a28579ed69.zip
Merge pull request #1661 from TomSweeneyRedHat/dev/tsweeney/loginhttp
Handle http/https in registry given to login/out
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/common.go8
-rw-r--r--cmd/podman/login.go9
-rw-r--r--cmd/podman/logout.go6
3 files changed, 16 insertions, 7 deletions
diff --git a/cmd/podman/common.go b/cmd/podman/common.go
index e342659ed..8ae1c9e0f 100644
--- a/cmd/podman/common.go
+++ b/cmd/podman/common.go
@@ -465,3 +465,11 @@ func getAuthFile(authfile string) string {
}
return os.Getenv("REGISTRY_AUTH_FILE")
}
+
+// scrubServer removes 'http://' or 'https://' from the front of the
+// server/registry string if either is there. This will be mostly used
+// for user input from 'podman login' and 'podman logout'.
+func scrubServer(server string) string {
+ server = strings.TrimPrefix(server, "https://")
+ return strings.TrimPrefix(server, "http://")
+}
diff --git a/cmd/podman/login.go b/cmd/podman/login.go
index 76f0f50ff..aa26d1466 100644
--- a/cmd/podman/login.go
+++ b/cmd/podman/login.go
@@ -60,10 +60,7 @@ func loginCmd(c *cli.Context) error {
if len(args) == 0 {
return errors.Errorf("registry must be given")
}
- var server string
- if len(args) == 1 {
- server = args[0]
- }
+ server := scrubServer(args[0])
authfile := getAuthFile(c.String("authfile"))
sc := common.GetSystemContext("", authfile, false)
@@ -113,6 +110,10 @@ func getUserAndPass(username, password, userFromAuthFile string) (string, string
if err != nil {
return "", "", errors.Wrapf(err, "error reading username")
}
+ // If no username provided, use userFromAuthFile instead.
+ if strings.TrimSpace(username) == "" {
+ username = userFromAuthFile
+ }
}
if password == "" {
fmt.Print("Password: ")
diff --git a/cmd/podman/logout.go b/cmd/podman/logout.go
index 099464e4f..3cdb606b5 100644
--- a/cmd/podman/logout.go
+++ b/cmd/podman/logout.go
@@ -44,7 +44,7 @@ func logoutCmd(c *cli.Context) error {
}
var server string
if len(args) == 1 {
- server = args[0]
+ server = scrubServer(args[0])
}
authfile := getAuthFile(c.String("authfile"))
@@ -54,14 +54,14 @@ func logoutCmd(c *cli.Context) error {
if err := config.RemoveAllAuthentication(sc); err != nil {
return err
}
- fmt.Println("Remove login credentials for all registries")
+ fmt.Println("Removed login credentials for all registries")
return nil
}
err := config.RemoveAuthentication(sc, server)
switch err {
case nil:
- fmt.Printf("Remove login credentials for %s\n", server)
+ fmt.Printf("Removed login credentials for %s\n", server)
return nil
case config.ErrNotLoggedIn:
return errors.Errorf("Not logged into %s\n", server)