Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit 5c020c2

Browse files
committed
Factor out asking for passphrase
1 parent 9d142c5 commit 5c020c2

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

internals/secrethub/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ func (cmd *InitCommand) Run() error {
251251
var passphrase string
252252
if !cmd.credentialStore.IsPassphraseSet() && !cmd.force {
253253
var err error
254-
passphrase, err = ui.AskPassphrase(cmd.io, "Please enter a passphrase to protect your local credential (leave empty for no passphrase): ", "Enter the same passphrase again: ", 3)
254+
passphrase, err = askCredentialPassphrase(cmd.io)
255255
if err != nil {
256256
return err
257257
}

internals/secrethub/signup.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func (cmd *SignUpCommand) Run() error {
132132
var passphrase string
133133
if !cmd.credentialStore.IsPassphraseSet() && !cmd.force {
134134
var err error
135-
passphrase, err = ui.AskPassphrase(cmd.io, "Please enter a passphrase to protect your local credential (leave empty for no passphrase): ", "Enter the same passphrase again: ", 3)
135+
passphrase, err = askCredentialPassphrase(cmd.io)
136136
if err != nil {
137137
return err
138138
}
@@ -254,3 +254,8 @@ func writeNewCredential(credential *credentials.KeyCreator, passphrase string, c
254254

255255
return credentialFile.Write(encodedCredential)
256256
}
257+
258+
// askCredentialPassphrase prompts the user for a passphrase to protect the local credential.
259+
func askCredentialPassphrase(io ui.IO) (string, error) {
260+
return ui.AskPassphrase(io, "Please enter a passphrase to protect your local credential (leave empty for no passphrase): ", "Enter the same passphrase again: ", 3)
261+
}

0 commit comments

Comments
 (0)