diff options
author | Qi Wang <qiwan@redhat.com> | 2019-02-12 09:53:38 -0500 |
---|---|---|
committer | Qi Wang <qiwan@redhat.com> | 2019-02-14 10:09:25 -0500 |
commit | a8b149b406e9565067c1f281e86071942123163e (patch) | |
tree | b90126b851ac1a1d240af386cc0e5ee3b041d64e /cmd/podman/login.go | |
parent | 112a5ab20cd6a07bcfcccadd0c0b851927a16f05 (diff) | |
download | podman-a8b149b406e9565067c1f281e86071942123163e.tar.gz podman-a8b149b406e9565067c1f281e86071942123163e.tar.bz2 podman-a8b149b406e9565067c1f281e86071942123163e.zip |
--password-stdin flag in `podman login`
Support --password-stdin flag, reads a password from STDIN and pass it to `podman login`.
Signed-off-by: Qi Wang <qiwan@redhat.com>
Diffstat (limited to 'cmd/podman/login.go')
-rw-r--r-- | cmd/podman/login.go | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/cmd/podman/login.go b/cmd/podman/login.go index 5ab0713e5..ac3e72d95 100644 --- a/cmd/podman/login.go +++ b/cmd/podman/login.go @@ -43,6 +43,7 @@ func init() { flags.StringVarP(&loginCommand.Password, "password", "p", "", "Password for registry") flags.BoolVar(&loginCommand.TlsVerify, "tls-verify", true, "Require HTTPS and verify certificates when contacting registries (default: true)") flags.StringVarP(&loginCommand.Username, "username", "u", "", "Username for registry") + flags.BoolVar(&loginCommand.StdinPassword, "password-stdin", false, "Take the password from stdin") rootCmd.AddCommand(loginCommand.Command) } @@ -90,8 +91,26 @@ func loginCmd(c *cliconfig.LoginValues) error { } ctx := getContext() + + password := c.Password + + if c.Flag("password-stdin").Changed { + var stdinPasswordStrBuilder strings.Builder + if c.Password != "" { + return errors.Errorf("Can't specify both --password-stdin and --password") + } + if c.Username == "" { + return errors.Errorf("Must provide --username with --password-stdin") + } + scanner := bufio.NewScanner(os.Stdin) + for scanner.Scan() { + fmt.Fprint(&stdinPasswordStrBuilder, scanner.Text()) + } + password = stdinPasswordStrBuilder.String() + } + // If no username and no password is specified, try to use existing ones. - if c.Username == "" && c.Password == "" { + if c.Username == "" && password == "" { fmt.Println("Authenticating with existing credentials...") if err := docker.CheckAuth(ctx, sc, userFromAuthFile, passFromAuthFile, server); err == nil { fmt.Println("Existing credentials are valid. Already logged in to", server) @@ -100,7 +119,7 @@ func loginCmd(c *cliconfig.LoginValues) error { fmt.Println("Existing credentials are invalid, please enter valid username and password") } - username, password, err := getUserAndPass(c.Username, c.Password, userFromAuthFile) + username, password, err := getUserAndPass(c.Username, password, userFromAuthFile) if err != nil { return errors.Wrapf(err, "error getting username and password") } |