Skip to content

Commit 0d8f015

Browse files
committed
Allow password for docker registry to be inputted silently
Signed-off-by: Ryan Cole <[email protected]>
1 parent 44e3b8d commit 0d8f015

File tree

8 files changed

+1297
-3
lines changed

8 files changed

+1297
-3
lines changed

cmd/kpod/push.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
libkpodimage "github.com/kubernetes-incubator/cri-o/libkpod/image"
1111
"github.com/pkg/errors"
1212
"github.com/urfave/cli"
13+
"golang.org/x/crypto/ssh/terminal"
1314
)
1415

1516
var (
@@ -88,7 +89,16 @@ func pushCmd(c *cli.Context) error {
8889
if registryCredsString != "" {
8990
creds, err := common.ParseRegistryCreds(registryCredsString)
9091
if err != nil {
91-
return err
92+
if err == common.ErrNoPassword {
93+
fmt.Print("Password: ")
94+
password, err := terminal.ReadPassword(0)
95+
if err != nil {
96+
return errors.Wrapf(err, "could not read password from terminal")
97+
}
98+
creds.Password = string(password)
99+
} else {
100+
return err
101+
}
92102
}
93103
registryCreds = creds
94104
}

libkpod/common/common.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
package common
22

33
import (
4-
"errors"
54
"io"
65
"strings"
6+
"syscall"
77

88
cp "github.com/containers/image/copy"
99
"github.com/containers/image/signature"
1010
"github.com/containers/image/types"
11+
"github.com/pkg/errors"
12+
)
13+
14+
var (
15+
// ErrNoPassword is returned if the user did not supply a password
16+
ErrNoPassword = errors.Wrapf(syscall.EINVAL, "password was not supplied")
1117
)
1218

1319
// GetCopyOptions constructs a new containers/image/copy.Options{} struct from the given parameters
@@ -78,7 +84,10 @@ func ParseRegistryCreds(creds string) (*types.DockerAuthConfig, error) {
7884
return nil, errors.New("no credentials supplied")
7985
}
8086
if !strings.Contains(creds, ":") {
81-
return nil, errors.New("user name supplied, but no password supplied")
87+
return &types.DockerAuthConfig{
88+
Username: creds,
89+
Password: "",
90+
}, ErrNoPassword
8291
}
8392
v := strings.SplitN(creds, ":", 2)
8493
cfg := &types.DockerAuthConfig{

0 commit comments

Comments
 (0)