Skip to content

Commit

Permalink
Replace NewCLIPromptV2.
Browse files Browse the repository at this point in the history
  • Loading branch information
Joerger committed Oct 24, 2024
1 parent 21fb710 commit f72be93
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 22 deletions.
2 changes: 1 addition & 1 deletion lib/client/mfa.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ type WebauthnLoginFunc = libmfa.WebauthnLoginFunc
func (tc *TeleportClient) NewMFAPrompt(opts ...mfa.PromptOpt) mfa.Prompt {
cfg := tc.newPromptConfig(opts...)

var prompt mfa.Prompt = libmfa.NewCLIPromptV2(&libmfa.CLIPromptConfig{
var prompt mfa.Prompt = libmfa.NewCLIPrompt(&libmfa.CLIPromptConfig{
PromptConfig: *cfg,
Writer: tc.Stderr,
PreferOTP: tc.PreferOTP,
Expand Down
25 changes: 8 additions & 17 deletions lib/client/mfa/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,8 @@ type CLIPrompt struct {
cfg CLIPromptConfig
}

// NewCLIPrompt returns a new CLI mfa prompt with the config and writer.
// TODO(Joerger): Delete once /e is no longer dependent on it.
func NewCLIPrompt(cfg *PromptConfig, writer io.Writer) *CLIPrompt {
// If no config is provided, use defaults (zero value).
if cfg == nil {
cfg = new(PromptConfig)
}
return NewCLIPromptV2(&CLIPromptConfig{
PromptConfig: *cfg,
Writer: writer,
})
}

// NewCLIPromptV2 returns a new CLI mfa prompt with the given config.
// TODO(Joerger): this is V2 because /e depends on a different function
// signature for NewCLIPrompt, so this requires a couple follow up PRs to fix.
func NewCLIPromptV2(cfg *CLIPromptConfig) *CLIPrompt {
// NewCLIPrompt returns a new CLI mfa prompt with the given config.
func NewCLIPrompt(cfg *CLIPromptConfig) *CLIPrompt {
// If no config is provided, use defaults (zero value).
if cfg == nil {
cfg = new(CLIPromptConfig)
Expand All @@ -87,6 +72,12 @@ func NewCLIPromptV2(cfg *CLIPromptConfig) *CLIPrompt {
}
}

// NewCLIPromptV2 returns a new CLI mfa prompt with the given config.
// TODO(Joerger): remove once /e is no longer dependent on this.
func NewCLIPromptV2(cfg *CLIPromptConfig) *CLIPrompt {
return NewCLIPrompt(cfg)
}

func (c *CLIPrompt) stdin() prompt.StdinReader {
if c.cfg.StdinFunc == nil {
return prompt.Stdin()
Expand Down
2 changes: 1 addition & 1 deletion lib/client/mfa/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ Enter your security key PIN:
buffer := make([]byte, 0, 100)
out := bytes.NewBuffer(buffer)

prompt := mfa.NewCLIPromptV2(&mfa.CLIPromptConfig{
prompt := mfa.NewCLIPrompt(&mfa.CLIPromptConfig{
PromptConfig: *cfg,
Writer: out,
AllowStdinHijack: true,
Expand Down
2 changes: 1 addition & 1 deletion lib/client/mfa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestPromptMFAChallenge_usingNonRegisteredDevice(t *testing.T) {
test.customizePrompt(cliConfig)
}

_, err := mfa.NewCLIPromptV2(cliConfig).Run(ctx, test.challenge)
_, err := mfa.NewCLIPrompt(cliConfig).Run(ctx, test.challenge)
if !errors.Is(err, wancli.ErrUsingNonRegisteredDevice) {
t.Errorf("PromptMFAChallenge returned err=%q, want %q", err, wancli.ErrUsingNonRegisteredDevice)
}
Expand Down
2 changes: 1 addition & 1 deletion tool/tctl/common/admin_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,7 +1029,7 @@ func newAdminActionTestSuite(t *testing.T) *adminActionTestSuite {
promptCfg := libmfa.NewPromptConfig(proxyPublicAddr.String(), opts...)
promptCfg.WebauthnLoginFunc = mockWebauthnLogin
promptCfg.WebauthnSupported = true
return libmfa.NewCLIPromptV2(&libmfa.CLIPromptConfig{
return libmfa.NewCLIPrompt(&libmfa.CLIPromptConfig{
PromptConfig: *promptCfg,
})
}
Expand Down
2 changes: 1 addition & 1 deletion tool/tctl/common/tctl.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ func TryRun(commands []CLICommand, args []string) error {
proxyAddr := resp.ProxyPublicAddr
client.SetMFAPromptConstructor(func(opts ...mfa.PromptOpt) mfa.Prompt {
promptCfg := libmfa.NewPromptConfig(proxyAddr, opts...)
return libmfa.NewCLIPromptV2(&libmfa.CLIPromptConfig{
return libmfa.NewCLIPrompt(&libmfa.CLIPromptConfig{
PromptConfig: *promptCfg,
})
})
Expand Down

0 comments on commit f72be93

Please sign in to comment.