Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically select the best prompt driver #1138

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion cli/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ func (input ExecCommandInput) validate() error {
return nil
}

func CanExecUseTerminal(input ExecCommandInput) bool {
return !input.StartEcsServer && !input.StartEc2Server
}

func ConfigureExecCommand(app *kingpin.Application, a *AwsVault) {
input := ExecCommandInput{}

Expand Down Expand Up @@ -114,7 +118,7 @@ func ConfigureExecCommand(app *kingpin.Application, a *AwsVault) {
StringsVar(&input.Args)

cmd.Action(func(c *kingpin.ParseContext) (err error) {
input.Config.MfaPromptMethod = a.PromptDriver
input.Config.MfaPromptMethod = a.PromptDriver(CanExecUseTerminal(input))
input.Config.NonChainedGetSessionTokenDuration = input.SessionDuration
input.Config.AssumeRoleDuration = input.SessionDuration
input.Config.SSOUseStdout = input.UseStdout
Expand Down
2 changes: 1 addition & 1 deletion cli/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func ConfigureExportCommand(app *kingpin.Application, a *AwsVault) {
StringVar(&input.ProfileName)

cmd.Action(func(c *kingpin.ParseContext) (err error) {
input.Config.MfaPromptMethod = a.PromptDriver
input.Config.MfaPromptMethod = a.PromptDriver(true)
input.Config.NonChainedGetSessionTokenDuration = input.SessionDuration
input.Config.AssumeRoleDuration = input.SessionDuration
input.Config.SSOUseStdout = input.UseStdout
Expand Down
23 changes: 20 additions & 3 deletions cli/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,30 @@ type AwsVault struct {
Debug bool
KeyringConfig keyring.Config
KeyringBackend string
PromptDriver string
promptDriver string

keyringImpl keyring.Keyring
awsConfigFile *vault.ConfigFile
}

func (a *AwsVault) PromptDriver(canUseTerminal bool) string {
if a.promptDriver == "" {
if canUseTerminal {
return "terminal"
}
for _, driver := range prompt.Available() {
a.promptDriver = driver
if driver != "terminal" {
break
}
}
}

log.Println("Using prompt driver: " + a.promptDriver)

return a.promptDriver
}

func (a *AwsVault) Keyring() (keyring.Keyring, error) {
if a.keyringImpl == nil {
if a.KeyringBackend != "" {
Expand Down Expand Up @@ -89,9 +107,8 @@ func ConfigureGlobals(app *kingpin.Application) *AwsVault {
EnumVar(&a.KeyringBackend, backendsAvailable...)

app.Flag("prompt", fmt.Sprintf("Prompt driver to use %v", promptsAvailable)).
Default("terminal").
Envar("AWS_VAULT_PROMPT").
EnumVar(&a.PromptDriver, promptsAvailable...)
EnumVar(&a.promptDriver, promptsAvailable...)

app.Flag("keychain", "Name of macOS keychain to use, if it doesn't exist it will be created").
Default("aws-vault").
Expand Down
2 changes: 1 addition & 1 deletion cli/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ConfigureLoginCommand(app *kingpin.Application, a *AwsVault) {
StringVar(&input.ProfileName)

cmd.Action(func(c *kingpin.ParseContext) (err error) {
input.Config.MfaPromptMethod = a.PromptDriver
input.Config.MfaPromptMethod = a.PromptDriver(true)
input.Config.NonChainedGetSessionTokenDuration = input.SessionDuration
input.Config.AssumeRoleDuration = input.SessionDuration
input.Config.GetFederationTokenDuration = input.SessionDuration
Expand Down
2 changes: 1 addition & 1 deletion cli/rotate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func ConfigureRotateCommand(app *kingpin.Application, a *AwsVault) {
StringVar(&input.ProfileName)

cmd.Action(func(c *kingpin.ParseContext) (err error) {
input.Config.MfaPromptMethod = a.PromptDriver
input.Config.MfaPromptMethod = a.PromptDriver(true)
keyring, err := a.Keyring()
if err != nil {
return err
Expand Down