-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcerts.go
More file actions
120 lines (92 loc) · 2.52 KB
/
certs.go
File metadata and controls
120 lines (92 loc) · 2.52 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
111
112
113
114
115
116
117
118
119
120
package parser
import (
"fmt"
"github.com/deis/deis/client-go/cmd"
docopt "github.com/docopt/docopt-go"
)
// Certs routes certs commands to their specific function.
func Certs(argv []string) error {
usage := `
Valid commands for certs:
certs:list list SSL certificates for an app
certs:add add an SSL certificate to an app
certs:remove remove an SSL certificate from an app
Use 'deis help [command]' to learn more.
`
if len(argv) < 2 {
return certsList([]string{"certs:list"})
}
switch argv[1] {
case "list":
return certsList(combineCommand(argv))
case "add":
return certAdd(combineCommand(argv))
case "remove":
return certRemove(combineCommand(argv))
case "--help":
fmt.Print(usage)
return nil
default:
PrintUsage()
return nil
}
}
func certsList(argv []string) error {
usage := `
Show certificate information for an SSL application.
Usage: deis certs: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.CertsList(results)
}
func certAdd(argv []string) error {
usage := `
Binds a certificate/key pair to an application.
Usage: deis certs:add <cert> <key> [options]
Arguments:
<cert>
The public key of the SSL certificate.
<key>
The private key of the SSL certificate.
Options:
--common-name=<cname>
The common name of the certificate. If none is provided, the controller will
interpret the common name from the certificate.
--subject-alt-names=<sans>
The subject alternate names (SAN) of the certificate, separated by commas. This will
create multiple Certificate objects in the controller, one for each SAN.
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
cert := args["<cert>"].(string)
key := args["<key>"].(string)
commonName := safeGetValue(args, "--common-name")
sans := safeGetValue(args, "--subject-alt-names")
return cmd.CertAdd(cert, key, commonName, sans)
}
func certRemove(argv []string) error {
usage := `
removes a certificate/key pair from the application.
Usage: deis certs:remove <cn> [options]
Arguments:
<cn>
the common name of the cert to remove from the app.
`
args, err := docopt.Parse(usage, argv, true, "", false, true)
if err != nil {
return err
}
return cmd.CertRemove(safeGetValue(args, "<cn>"))
}