-
Notifications
You must be signed in to change notification settings - Fork 19
/
sshkey_delete.go
53 lines (43 loc) · 1.06 KB
/
sshkey_delete.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
43
44
45
46
47
48
49
50
51
52
53
package cmd
import (
"fmt"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
// deleteCmd represents the delete command
var sshkeyDeleteCmd = &cobra.Command{
Use: "delete <name>",
Short: "Delete SSH key pair",
Aliases: gDeleteAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return cmd.Usage()
}
force, err := cmd.Flags().GetBool("force")
if err != nil {
return err
}
if !force {
if !askQuestion(fmt.Sprintf("Are you sure you want to delete %q SSH key pair", args[0])) {
return nil
}
}
res, err := deleteSSHKey(args[0])
if err != nil {
return err
}
fmt.Println(res)
return nil
},
}
func deleteSSHKey(name string) (string, error) {
sshKey := &egoscale.DeleteSSHKeyPair{Name: name}
if err := cs.BooleanRequestWithContext(gContext, sshKey); err != nil {
return "", err
}
return sshKey.Name, nil
}
func init() {
sshkeyDeleteCmd.Flags().BoolP("force", "f", false, "Attempt to remove SSH key pair without prompting for confirmation")
sshkeyCmd.AddCommand(sshkeyDeleteCmd)
}