MCPcopy
hub / github.com/kopia/kopia / getPasswordFromFlags

Method getPasswordFromFlags

cli/password.go:72–94  ·  view source on GitHub ↗
(ctx context.Context, isCreate, allowPersistent bool)

Source from the content-addressed store, hash-verified

70}
71
72func (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.
97func askPass(out io.Writer, prompt string) (string, error) {

Callers 2

openRepositoryMethod · 0.95

Calls 5

GetPasswordMethod · 0.65

Tested by

no test coverage detected