mirror of https://github.com/knative/func.git
Improve usability of `func` CLI for IDE plugins (#1091)
* Better input handling for non-tty Signed-off-by: Matej Vasek <mvasek@redhat.com> * Make cred-helper 'not implemented' non fatal error Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
parent
5c211a6778
commit
80505979f9
|
@ -318,18 +318,42 @@ you can install docker credential helper https://github.com/docker/docker-creden
|
|||
return "", nil
|
||||
}
|
||||
|
||||
isTerm := term.IsTerminal(int(os.Stdin.Fd()))
|
||||
|
||||
var resp string
|
||||
err := survey.AskOne(&survey.Select{
|
||||
Message: "Choose credentials helper",
|
||||
Options: append(availableHelpers, "None"),
|
||||
}, &resp, survey.WithValidator(survey.Required))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if resp == "None" {
|
||||
fmt.Fprintf(os.Stderr, "No helper selected. Credentials will not be saved.\n")
|
||||
return "", nil
|
||||
|
||||
if isTerm {
|
||||
err := survey.AskOne(&survey.Select{
|
||||
Message: "Choose credentials helper",
|
||||
Options: append(availableHelpers, "None"),
|
||||
}, &resp, survey.WithValidator(survey.Required))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if resp == "None" {
|
||||
fmt.Fprintf(os.Stderr, "No helper selected. Credentials will not be saved.\n")
|
||||
return "", nil
|
||||
}
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "Available credential helpers:\n")
|
||||
for _, helper := range availableHelpers {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", helper)
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Choose credentials helper: ")
|
||||
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
|
||||
var err error
|
||||
resp, err = reader.ReadString('\n')
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
resp = strings.Trim(resp, "\r\n")
|
||||
if resp == "" {
|
||||
fmt.Fprintf(os.Stderr, "No helper selected. Credentials will not be saved.\n")
|
||||
}
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
}
|
||||
|
|
|
@ -255,6 +255,13 @@ func (c *credentialsProvider) getCredentials(ctx context.Context, registry strin
|
|||
if err == nil {
|
||||
err = setCredentialsByCredentialHelper(c.authFilePath, registry, result.Username, result.Password)
|
||||
if err != nil {
|
||||
|
||||
// This shouldn't be fatal error.
|
||||
if strings.Contains(err.Error(), "not implemented") {
|
||||
fmt.Fprintf(os.Stderr, "the cred-helper does not support write operation (consider changing the cred-helper it in auth.json)\n")
|
||||
return docker.Credentials{}, nil
|
||||
}
|
||||
|
||||
if !errors.Is(err, errNoCredentialHelperConfigured) {
|
||||
return docker.Credentials{}, err
|
||||
}
|
||||
|
@ -269,8 +276,17 @@ func (c *credentialsProvider) getCredentials(ctx context.Context, registry strin
|
|||
return docker.Credentials{}, fmt.Errorf("faild to set the helper to the config: %w", err)
|
||||
}
|
||||
err = setCredentialsByCredentialHelper(c.authFilePath, registry, result.Username, result.Password)
|
||||
if err != nil && !errors.Is(err, errNoCredentialHelperConfigured) {
|
||||
return docker.Credentials{}, err
|
||||
if err != nil {
|
||||
|
||||
// This shouldn't be fatal error.
|
||||
if strings.Contains(err.Error(), "not implemented") {
|
||||
fmt.Fprintf(os.Stderr, "the cred-helper does not support write operation (consider changing the cred-helper it in auth.json)\n")
|
||||
return docker.Credentials{}, nil
|
||||
}
|
||||
|
||||
if !errors.Is(err, errNoCredentialHelperConfigured) {
|
||||
return docker.Credentials{}, err
|
||||
}
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
|
|
Loading…
Reference in New Issue