Skip to content

Commit

Permalink
Merge pull request #1754 from hanks/fix/optional-arn-aws-role
Browse files Browse the repository at this point in the history
fix(config): make ARN of AWS role input optional
  • Loading branch information
r2d4 authored Aug 29, 2017
2 parents 54395a6 + 5556ce9 commit 3f10427
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/minikube/cmd/config/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var addonsConfigureCmd = &cobra.Command{
awsAccessKey = AskForStaticValue("-- Enter AWS Secret Access Key: ")
awsRegion = AskForStaticValue("-- Enter AWS Region: ")
awsAccount = AskForStaticValue("-- Enter 12 digit AWS Account ID: ")
awsRole = AskForStaticValue("-- (Optional) Enter ARN of AWS role to assume: ")
awsRole = AskForStaticValueOptional("-- (Optional) Enter ARN of AWS role to assume: ")
}

enableGCR := AskForYesNoConfirmation("\nDo you want to enable Google Container Registry?", posResponses, negResponses)
Expand Down
33 changes: 23 additions & 10 deletions cmd/minikube/cmd/config/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ package config
import (
"bufio"
"fmt"
"golang.org/x/crypto/ssh/terminal"
"io"
"log"
"os"
"strings"

"golang.org/x/crypto/ssh/terminal"
)

// AskForYesNoConfirmation asks the user for confirmation. A user must type in "yes" or "no" and
Expand Down Expand Up @@ -59,24 +60,36 @@ func AskForStaticValue(s string) string {
reader := bufio.NewReader(os.Stdin)

for {
fmt.Printf("%s", s)

response, err := reader.ReadString('\n')
if err != nil {
log.Fatal(err)
}

response = strings.TrimSpace(response)
response := getStaticValue(reader, s)

// Can't have zero length
if len(response) == 0 {
fmt.Println("--Error, please enter a value:")
return AskForStaticValue(s)
continue
}
return response
}
}

// AskForStaticValueOptional asks for a optional single value to enter, can just skip enter
func AskForStaticValueOptional(s string) string {
reader := bufio.NewReader(os.Stdin)

return getStaticValue(reader, s)
}

func getStaticValue(reader *bufio.Reader, s string) string {
fmt.Printf("%s", s)

response, err := reader.ReadString('\n')
if err != nil {
log.Fatal(err)
}

response = strings.TrimSpace(response)
return response
}

func concealableAskForStaticValue(readWriter io.ReadWriter, promptString string, hidden bool) (string, error) {
for {
var (
Expand Down

0 comments on commit 3f10427

Please sign in to comment.