(ctx context.Context, isCreate, allowPersistent bool)
| 70 | } |
| 71 | |
| 72 | func (c *App) getPasswordFromFlags(ctx context.Context, isCreate, allowPersistent bool) (string, error) { |
| 73 | switch { |
| 74 | case c.password != "": |
| 75 | // password provided via --password flag or KOPIA_PASSWORD environment variable |
| 76 | return strings.TrimSpace(c.password), nil |
| 77 | case isCreate: |
| 78 | // this is a new repository, ask for password |
| 79 | return askForNewRepositoryPassword(c.stdoutWriter) |
| 80 | case allowPersistent: |
| 81 | // try fetching the password from persistent storage specific to the configuration file. |
| 82 | pass, err := c.passwordPersistenceStrategy().GetPassword(ctx, c.repositoryConfigFileName()) |
| 83 | if err == nil { |
| 84 | return pass, nil |
| 85 | } |
| 86 | |
| 87 | if !errors.Is(err, passwordpersist.ErrPasswordNotFound) { |
| 88 | return "", errors.Wrap(err, "cannot get persistent password") |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | // fall back to asking for existing password |
| 93 | return askForExistingRepositoryPassword(c.stdoutWriter) |
| 94 | } |
| 95 | |
| 96 | // askPass presents a given prompt and asks the user for password. |
| 97 | func askPass(out io.Writer, prompt string) (string, error) { |
no test coverage detected