diff options
author | Theodore Cowan <theodore-cowan@pluralsight.com> | 2018-12-17 07:05:44 -0500 |
---|---|---|
committer | Theodore Cowan <theodore-cowan@pluralsight.com> | 2018-12-17 11:20:40 -0500 |
commit | d5647fe053f2fdd97118c6aebfb1e467bdbf3ed3 (patch) | |
tree | 0485d462fe33254fa7ba98333576e59976ffc9a7 /cmd/podman/login.go | |
parent | 93b5ccfe94f3f180542f045a92f14b8d2368e73e (diff) | |
download | podman-d5647fe053f2fdd97118c6aebfb1e467bdbf3ed3.tar.gz podman-d5647fe053f2fdd97118c6aebfb1e467bdbf3ed3.tar.bz2 podman-d5647fe053f2fdd97118c6aebfb1e467bdbf3ed3.zip |
add --get-login command to podman-login.
Returns user if user is logged-in to the registry. Returns error
if not logged in with non-zero status code.
Signed-off-by: Theodore Cowan <theodore-cowan@pluralsight.com>
Diffstat (limited to 'cmd/podman/login.go')
-rw-r--r-- | cmd/podman/login.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/cmd/podman/login.go b/cmd/podman/login.go index cfdd8005b..4452651f8 100644 --- a/cmd/podman/login.go +++ b/cmd/podman/login.go @@ -34,6 +34,10 @@ var ( Usage: "Pathname of a directory containing TLS certificates and keys used to connect to the registry", }, cli.BoolTFlag{ + Name: "get-login", + Usage: "Return the current login user for the registry", + }, + cli.BoolTFlag{ Name: "tls-verify", Usage: "Require HTTPS and verify certificates when contacting registries (default: true)", }, @@ -65,6 +69,21 @@ func loginCmd(c *cli.Context) error { sc := common.GetSystemContext("", authfile, false) + if c.IsSet("get-login") { + user, err := config.GetUserLoggedIn(sc, server) + + if err != nil { + return errors.Wrapf(err, "unable to check for login user") + } + + if user == "" { + return errors.Errorf("not logged into %s", server) + } + + fmt.Printf("%s\n", user) + return nil + } + // username of user logged in to server (if one exists) userFromAuthFile, passFromAuthFile, err := config.GetAuthentication(sc, server) if err != nil { |