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]>

Closes: #415
Approved by: rhatdan
  • Loading branch information
TomSweeneyRedHat authored and rh-atomic-bot committed Jan 26, 2018
1 parent b68f88c commit 4981b32
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
29 changes: 20 additions & 9 deletions cmd/buildah/common.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

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

is "github.com/containers/image/storage"
Expand All @@ -15,6 +15,7 @@ import (
"github.com/pkg/errors"
"github.com/projectatomic/buildah"
"github.com/urfave/cli"
"golang.org/x/crypto/ssh/terminal"
)

var needToShutdownStore = false
Expand Down Expand Up @@ -146,25 +147,35 @@ func systemContextFromOptions(c *cli.Context) (*types.SystemContext, error) {
return ctx, nil
}

func parseCreds(creds string) (string, string, error) {
func parseCreds(creds string) (string, string) {
if creds == "" {
return "", "", errors.Wrapf(syscall.EINVAL, "credentials can't be empty")
return "", ""
}
up := strings.SplitN(creds, ":", 2)
if len(up) == 1 {
return up[0], "", nil
return up[0], ""
}
if up[0] == "" {
return "", "", errors.Wrapf(syscall.EINVAL, "username can't be empty")
return "", up[1]
}
return up[0], up[1], nil
return up[0], up[1]
}

func getDockerAuth(creds string) (*types.DockerAuthConfig, error) {
username, password, err := parseCreds(creds)
if err != nil {
return nil, err
username, password := parseCreds(creds)
if username == "" {
fmt.Print("Username: ")
fmt.Scanln(&username)
}
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 4981b32

Please sign in to comment.