forked from 99designs/aws-vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rm.go
42 lines (35 loc) · 909 Bytes
/
rm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"fmt"
"github.com/99designs/aws-vault/keyring"
"github.com/99designs/aws-vault/prompt"
)
type RemoveCommandInput struct {
Profile string
Keyring keyring.Keyring
SessionsOnly bool
}
func RemoveCommand(ui Ui, input RemoveCommandInput) {
if !input.SessionsOnly {
provider := &KeyringProvider{Keyring: input.Keyring, Profile: input.Profile}
r, err := prompt.TerminalPrompt(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)
}
ui.Printf("Deleted credentials.")
}
sessions, err := NewKeyringSessions(input.Keyring)
if err != nil {
ui.Error.Fatal(err)
}
n, err := sessions.Delete(input.Profile)
if err != nil {
ui.Error.Fatal(err)
}
ui.Printf("Deleted %d sessions.", n)
}