Skip to content

Commit f697ddc

Browse files
committed
Export prompt functions to be used by external users.
1 parent bd26e26 commit f697ddc

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

file.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (k *fileKeyring) unlock() error {
6767
}
6868

6969
if k.password == "" {
70-
pwd, err := k.passwordFunc(fmt.Sprintf("Enter passphrase to unlock %s", dir))
70+
pwd, err := k.passwordFunc(fmt.Sprintf("Enter passphrase to unlock %q", dir))
7171
if err != nil {
7272
return err
7373
}

file_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
func TestFileKeyringSetWhenEmpty(t *testing.T) {
99
k := &fileKeyring{
1010
dir: os.TempDir(),
11-
passwordFunc: fixedStringPrompt("no more secrets"),
11+
passwordFunc: FixedStringPrompt("no more secrets"),
1212
}
1313
item := Item{Key: "llamas", Data: []byte("llamas are great")}
1414

@@ -33,7 +33,7 @@ func TestFileKeyringSetWhenEmpty(t *testing.T) {
3333
func TestFileKeyringGetWithSlashes(t *testing.T) {
3434
k := &fileKeyring{
3535
dir: os.TempDir(),
36-
passwordFunc: fixedStringPrompt("no more secrets"),
36+
passwordFunc: FixedStringPrompt("no more secrets"),
3737
}
3838

3939
item := Item{Key: "https://aws-sso-portal.awsapps.com/start", Data: []byte("https://aws-sso-portal.awsapps.com/start")}

keychain_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestOSXKeychainKeyringSet(t *testing.T) {
1717

1818
k := &keychain{
1919
path: path,
20-
passwordFunc: fixedStringPrompt("test password"),
20+
passwordFunc: FixedStringPrompt("test password"),
2121
service: "test",
2222
isTrusted: true,
2323
}
@@ -57,7 +57,7 @@ func TestOSXKeychainKeyringOverwrite(t *testing.T) {
5757

5858
k := &keychain{
5959
path: path,
60-
passwordFunc: fixedStringPrompt("test password"),
60+
passwordFunc: FixedStringPrompt("test password"),
6161
service: "test",
6262
isTrusted: true,
6363
}
@@ -110,7 +110,7 @@ func TestOSXKeychainKeyringListKeysWhenEmpty(t *testing.T) {
110110
k := &keychain{
111111
path: path,
112112
service: "test",
113-
passwordFunc: fixedStringPrompt("test password"),
113+
passwordFunc: FixedStringPrompt("test password"),
114114
isTrusted: true,
115115
}
116116

@@ -130,7 +130,7 @@ func TestOSXKeychainKeyringListKeysWhenNotEmpty(t *testing.T) {
130130
k := &keychain{
131131
path: path,
132132
service: "test",
133-
passwordFunc: fixedStringPrompt("test password"),
133+
passwordFunc: FixedStringPrompt("test password"),
134134
isTrusted: true,
135135
}
136136

@@ -175,7 +175,7 @@ func TestOSXKeychainGetKeyWhenEmpty(t *testing.T) {
175175

176176
k := &keychain{
177177
path: path,
178-
passwordFunc: fixedStringPrompt("test password"),
178+
passwordFunc: FixedStringPrompt("test password"),
179179
service: "test",
180180
isTrusted: true,
181181
}
@@ -192,7 +192,7 @@ func TestOSXKeychainGetKeyWhenNotEmpty(t *testing.T) {
192192

193193
k := &keychain{
194194
path: path,
195-
passwordFunc: fixedStringPrompt("test password"),
195+
passwordFunc: FixedStringPrompt("test password"),
196196
service: "test",
197197
isTrusted: true,
198198
}
@@ -222,7 +222,7 @@ func TestOSXKeychainRemoveKeyWhenEmpty(t *testing.T) {
222222

223223
k := &keychain{
224224
path: path,
225-
passwordFunc: fixedStringPrompt("test password"),
225+
passwordFunc: FixedStringPrompt("test password"),
226226
service: "test",
227227
isTrusted: true,
228228
}
@@ -239,7 +239,7 @@ func TestOSXKeychainRemoveKeyWhenNotEmpty(t *testing.T) {
239239

240240
k := &keychain{
241241
path: path,
242-
passwordFunc: fixedStringPrompt("test password"),
242+
passwordFunc: FixedStringPrompt("test password"),
243243
service: "test",
244244
isTrusted: true,
245245
}

prompt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
// PromptFunc is a function used to prompt the user for a password
1111
type PromptFunc func(string) (string, error)
1212

13-
func terminalPrompt(prompt string) (string, error) {
13+
func TerminalPrompt(prompt string) (string, error) {
1414
fmt.Printf("%s: ", prompt)
1515
b, err := terminal.ReadPassword(int(os.Stdin.Fd()))
1616
if err != nil {
@@ -20,7 +20,7 @@ func terminalPrompt(prompt string) (string, error) {
2020
return string(b), nil
2121
}
2222

23-
func fixedStringPrompt(value string) PromptFunc {
23+
func FixedStringPrompt(value string) PromptFunc {
2424
return func(_ string) (string, error) {
2525
return value, nil
2626
}

0 commit comments

Comments
 (0)