Skip to content

Commit

Permalink
Merge pull request #52 from 99designs/rm-sessions-only
Browse files Browse the repository at this point in the history
Add a `--sessions-only` flag to rm
  • Loading branch information
lox committed Oct 27, 2015
2 parents c049524 + f788cdf commit 8f1f5cf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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():
Expand Down
27 changes: 15 additions & 12 deletions rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8f1f5cf

Please sign in to comment.