-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathkeys.go
More file actions
110 lines (81 loc) · 1.87 KB
/
keys.go
File metadata and controls
110 lines (81 loc) · 1.87 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package parser
import (
"github.com/deis/workflow/client/cmd"
docopt "github.com/docopt/docopt-go"
)
// Keys routes key commands to the specific function.
func Keys(argv []string) error {
usage := `
Valid commands for SSH keys:
keys:list list SSH keys for the logged in user
keys:add add an SSH key
keys:remove remove an SSH key
Use 'deis help [command]' to learn more.
`
switch argv[0] {
case "keys:list":
return keysList(argv)
case "keys:add":
return keyAdd(argv)
case "keys:remove":
return keyRemove(argv)
default:
if printHelp(argv, usage) {
return nil
}
if argv[0] == "keys" {
argv[0] = "keys:list"
return keysList(argv)
}
PrintUsage()
return nil
}
}
func keysList(argv []string) error {
usage := `
Lists SSH keys for the logged in user.
Usage: deis keys:list [options]
Options:
-l --limit=<num>
the maximum number of results to display, defaults to config setting
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
results, err := responseLimit(safeGetValue(args, "--limit"))
if err != nil {
return err
}
return cmd.KeysList(results)
}
func keyAdd(argv []string) error {
usage := `
Adds SSH keys for the logged in user.
Usage: deis keys:add [<key>]
Arguments:
<key>
a local file path to an SSH public key used to push application code.
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
key := safeGetValue(args, "<key>")
return cmd.KeyAdd(key)
}
func keyRemove(argv []string) error {
usage := `
Removes an SSH key for the logged in user.
Usage: deis keys:remove <key>
Arguments:
<key>
the SSH public key to revoke source code push access.
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
key := safeGetValue(args, "<key>")
return cmd.KeyRemove(key)
}