Skip to content

Commit 047c945

Browse files
mask password
1 parent 6e66a4d commit 047c945

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

internal/adapters/prompter/prompter.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,12 @@ func (p *prompter) PromptForString(message string) (string, error) {
2626
}
2727
return prompt.Run()
2828
}
29+
30+
func (p *prompter) PromptForSecret(message string) (string, error) {
31+
prompt := promptui.Prompt{
32+
Label: message,
33+
Pointer: promptui.DefaultCursor,
34+
Mask: '*',
35+
}
36+
return prompt.Run()
37+
}

internal/app/configure.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (uc *ConfigureUseCase) Execute(opts *ConfigureOpts) error {
3838
return err
3939
}
4040

41-
cfg.Password, err = uc.getOrPrompt(opts.Password, "Enter AWX password")
41+
cfg.Password, err = uc.getOrPromptSecret(opts.Password, "Enter AWX password")
4242
if err != nil {
4343
return err
4444
}
@@ -57,3 +57,10 @@ func (uc *ConfigureUseCase) getOrPrompt(value, prompt string) (string, error) {
5757
}
5858
return uc.prompter.PromptForString(prompt)
5959
}
60+
61+
func (uc *ConfigureUseCase) getOrPromptSecret(value, prompt string) (string, error) {
62+
if value != "" {
63+
return value, nil
64+
}
65+
return uc.prompter.PromptForSecret(prompt)
66+
}

internal/ports/prompter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package ports
33
type Prompter interface {
44
ChooseFromList([]PrompterItem, string) (PrompterItem, error)
55
PromptForString(message string) (string, error)
6+
PromptForSecret(message string) (string, error)
67
}
78

89
type PrompterItem struct {

0 commit comments

Comments
 (0)