Skip to content

Commit

Permalink
Prompt for un/pwd if not supplied with --creds
Browse files Browse the repository at this point in the history
Signed-off-by: TomSweeneyRedHat <[email protected]>
  • Loading branch information
TomSweeneyRedHat committed Jan 25, 2018
1 parent 2dbb2a1 commit 0c6d02b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
22 changes: 19 additions & 3 deletions cmd/buildah/common.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package main

import (
"fmt"
"os"
"reflect"
"regexp"
"strings"
"syscall"
"time"

"golang.org/x/crypto/ssh/terminal"
is "github.com/containers/image/storage"
"github.com/containers/image/types"
"github.com/containers/storage"
Expand Down Expand Up @@ -148,14 +149,14 @@ func systemContextFromOptions(c *cli.Context) (*types.SystemContext, error) {

func parseCreds(creds string) (string, string, error) {
if creds == "" {
return "", "", errors.Wrapf(syscall.EINVAL, "credentials can't be empty")
return "", "", nil
}
up := strings.SplitN(creds, ":", 2)
if len(up) == 1 {
return up[0], "", nil
}
if up[0] == "" {
return "", "", errors.Wrapf(syscall.EINVAL, "username can't be empty")
return "", up[1], nil
}
return up[0], up[1], nil
}
Expand All @@ -165,6 +166,21 @@ func getDockerAuth(creds string) (*types.DockerAuthConfig, error) {
if err != nil {
return nil, err
}
if username == "" {
fmt.Print("Username: ")
var termUserName string
fmt.Scanln(&termUserName)
username = string(termUserName)
}
if password == "" {
fmt.Print("Password: ")
termPassword, err := terminal.ReadPassword(0)
if err != nil {
return nil, errors.Wrapf(err, "could not read password from terminal")
}
password = string(termPassword)
}

return &types.DockerAuthConfig{
Username: username,
Password: password,
Expand Down
4 changes: 3 additions & 1 deletion docs/buildah-commit.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ Use certificates at *path* (*.crt, *.cert, *.key) to connect to the registry

**--creds** *creds*

The username[:password] to use to authenticate with the registry if required.
The [username[:password]] to use to authenticate with the registry if required.
If one or both values are not supplied, a command line prompt will appear and the
value can be entered. The password is entered without echo.

**--disable-compression, -D**

Expand Down
4 changes: 3 additions & 1 deletion docs/buildah-from.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ Use certificates at *path* (*.crt, *.cert, *.key) to connect to the registry

**--creds** *creds*

The username[:password] to use to authenticate with the registry if required.
The [username[:password]] to use to authenticate with the registry if required.
If one or both values are not supplied, a command line prompt will appear and the
value can be entered. The password is entered without echo.

**--name** *name*

Expand Down
4 changes: 3 additions & 1 deletion docs/buildah-push.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ Use certificates at *path* (*.crt, *.cert, *.key) to connect to the registry

**--creds** *creds*

The username[:password] to use to authenticate with the registry if required.
The [username[:password]] to use to authenticate with the registry if required.
If one or both values are not supplied, a command line prompt will appear and the
value can be entered. The password is entered without echo.

**--disable-compression, -D**

Expand Down

0 comments on commit 0c6d02b

Please sign in to comment.