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>
This commit is contained in:
Theodore Cowan 2018-12-17 07:05:44 -05:00
parent 93b5ccfe94
commit d5647fe053
No known key found for this signature in database
GPG Key ID: 6F79A3D0568970C4
3 changed files with 24 additions and 0 deletions

View File

@ -33,6 +33,10 @@ var (
Name: "cert-dir", Name: "cert-dir",
Usage: "Pathname of a directory containing TLS certificates and keys used to connect to the registry", 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{ cli.BoolTFlag{
Name: "tls-verify", Name: "tls-verify",
Usage: "Require HTTPS and verify certificates when contacting registries (default: true)", 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) 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) // username of user logged in to server (if one exists)
userFromAuthFile, passFromAuthFile, err := config.GetAuthentication(sc, server) userFromAuthFile, passFromAuthFile, err := config.GetAuthentication(sc, server)
if err != nil { if err != nil {

View File

@ -2217,6 +2217,7 @@ _podman_login() {
--password --password
-p -p
--authfile --authfile
--get-login
" "
local boolean_options=" local boolean_options="
--help --help

View File

@ -36,6 +36,10 @@ Path of the authentication file. Default is ${XDG_\RUNTIME\_DIR}/containers/auth
Note: You can also override the default path of the authentication file by setting the REGISTRY\_AUTH\_FILE Note: You can also override the default path of the authentication file by setting the REGISTRY\_AUTH\_FILE
environment variable. `export REGISTRY_AUTH_FILE=path` environment variable. `export REGISTRY_AUTH_FILE=path`
**--get-login**
Return the logged-in user for the registry. Return error if no login is found.
**--cert-dir** *path* **--cert-dir** *path*
Use certificates at *path* (\*.crt, \*.cert, \*.key) to connect to the registry. Use certificates at *path* (\*.crt, \*.cert, \*.key) to connect to the registry.