diff --git a/main.go b/main.go index 8bffa0fb5..73e60ed6b 100644 --- a/main.go +++ b/main.go @@ -41,8 +41,9 @@ func main() { execServer = exec.Flag("server", "Run the server in the background for credentials").Short('s').Bool() execCmd = exec.Arg("cmd", "Command to execute").Default(os.Getenv("SHELL")).String() execCmdArgs = exec.Arg("args", "Command arguments").Strings() - rm = kingpin.Command("rm", "Removes credentials") + rm = kingpin.Command("rm", "Removes credentials, including sessions") rmProfile = rm.Arg("profile", "Name of the profile").Required().String() + rmSessionsOnly = rm.Flag("sessions-only", "Only remove sessions, leave credentials intact").Short('s').Bool() login = kingpin.Command("login", "Generate a login link for the AWS Console") loginProfile = login.Arg("profile", "Name of the profile").Required().String() loginMfaToken = login.Flag("mfa-token", "The mfa token to use").Short('t').String() @@ -83,8 +84,9 @@ func main() { case rm.FullCommand(): RemoveCommand(ui, RemoveCommandInput{ - Profile: *rmProfile, - Keyring: keyring, + Profile: *rmProfile, + Keyring: keyring, + SessionsOnly: *rmSessionsOnly, }) case add.FullCommand(): diff --git a/rm.go b/rm.go index 737dbcef8..ce34b232c 100644 --- a/rm.go +++ b/rm.go @@ -7,23 +7,26 @@ import ( ) type RemoveCommandInput struct { - Profile string - Keyring keyring.Keyring + Profile string + Keyring keyring.Keyring + SessionsOnly bool } func RemoveCommand(ui Ui, input RemoveCommandInput) { - provider := &KeyringProvider{Keyring: input.Keyring, Profile: input.Profile} - r, err := prompt(fmt.Sprintf("Delete credentials for profile %q? (Y|n)", input.Profile)) - if err != nil { - ui.Error.Fatal(err) - } else if r == "N" || r == "n" { - return - } + if !input.SessionsOnly { + provider := &KeyringProvider{Keyring: input.Keyring, Profile: input.Profile} + r, err := prompt(fmt.Sprintf("Delete credentials for profile %q? (Y|n)", input.Profile)) + if err != nil { + ui.Error.Fatal(err) + } else if r == "N" || r == "n" { + return + } - if err := provider.Delete(); err != nil { - ui.Error.Fatal(err) + if err := provider.Delete(); err != nil { + ui.Error.Fatal(err) + } + ui.Printf("Deleted credentials.") } - ui.Printf("Deleted credentials.") sessions, err := NewKeyringSessions(input.Keyring) if err != nil {