aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-02-14 22:31:58 +0100
committerGitHub <noreply@github.com>2019-02-14 22:31:58 +0100
commit1a9128d1e4851df7c0316e0b861e70605fd262f6 (patch)
tree887ffe79dd00a78b118218541ea7373df083bfaf /cmd
parent18bf883eeb08d7cb5bd1c999e43f1140be4f787d (diff)
parenta8b149b406e9565067c1f281e86071942123163e (diff)
downloadpodman-1a9128d1e4851df7c0316e0b861e70605fd262f6.tar.gz
podman-1a9128d1e4851df7c0316e0b861e70605fd262f6.tar.bz2
podman-1a9128d1e4851df7c0316e0b861e70605fd262f6.zip
Merge pull request #2320 from QiWang19/stdinPW
--password-stdin flag in `podman login`
Diffstat (limited to 'cmd')
-rw-r--r--cmd/podman/cliconfig/config.go13
-rw-r--r--cmd/podman/login.go23
2 files changed, 28 insertions, 8 deletions
diff --git a/cmd/podman/cliconfig/config.go b/cmd/podman/cliconfig/config.go
index f38bcaa62..f5d6a8685 100644
--- a/cmd/podman/cliconfig/config.go
+++ b/cmd/podman/cliconfig/config.go
@@ -177,12 +177,13 @@ type LoadValues struct {
type LoginValues struct {
PodmanCommand
- Password string
- Username string
- Authfile string
- CertDir string
- GetLogin bool
- TlsVerify bool
+ Password string
+ StdinPassword bool
+ Username string
+ Authfile string
+ CertDir string
+ GetLogin bool
+ TlsVerify bool
}
type LogoutValues struct {
diff --git a/cmd/podman/login.go b/cmd/podman/login.go
index 0bd58ff78..1fc4d5327 100644
--- a/cmd/podman/login.go
+++ b/cmd/podman/login.go
@@ -44,6 +44,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")
}
@@ -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")
}