-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcerts.go
More file actions
170 lines (152 loc) · 5.55 KB
/
certs.go
File metadata and controls
170 lines (152 loc) · 5.55 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package parser
import (
"github.com/drycc/workflow-cli/internal/commands"
"github.com/drycc/workflow-cli/internal/completion"
"github.com/drycc/workflow-cli/internal/template"
"github.com/drycc/workflow-cli/pkg/i18n"
"github.com/spf13/cobra"
)
// NewCertsCommand creates the certs command
func NewCertsCommand(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "certs",
Short: i18n.T("Manage SSL endpoints for an app"),
RunE: func(cmd *cobra.Command, args []string) error {
results, _ := commands.ResponseLimit(limit)
return cmdr.CertsList(app, results)
},
}
cmd.PersistentFlags().StringVarP(&app, "app", "a", "", i18n.T("The uniquely identifiable name for the application"))
cmd.Flags().IntVarP(&limit, "limit", "l", 0, i18n.T("The maximum number of results to display"))
appCompletion := completion.AppCompletion{ArgsLen: -1, ConfigFile: &cmdr.ConfigFile}
cmd.RegisterFlagCompletionFunc("app", appCompletion.CompletionFunc)
cmd.AddCommand(certsListCommand(cmdr))
cmd.AddCommand(certAddCommand(cmdr))
cmd.AddCommand(certRemoveCommand(cmdr))
cmd.AddCommand(certInfoCommand(cmdr))
cmd.AddCommand(certAttachCommand(cmdr))
cmd.AddCommand(certDetachCommand(cmdr))
return cmd
}
func certsListCommand(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: i18n.T("List SSL certificates for an application"),
Long: i18n.T("Show certificate information for an SSL application"),
RunE: func(cmd *cobra.Command, args []string) error {
results, _ := commands.ResponseLimit(limit)
return cmdr.CertsList(app, results)
},
}
cmd.Flags().IntVarP(&limit, "limit", "l", 0, i18n.T("The maximum number of results to display"))
return cmd
}
func certAddCommand(cmdr *commands.DryccCmd) *cobra.Command {
cmd := &cobra.Command{
Use: "add <name> <cert> <key>",
Example: template.CustomExample(
"drycc certs add cert-name default.crt default.key",
map[string]string{
"<name>": i18n.T("Name of the certificate to reference it by"),
"<cert>": i18n.T("The public key of the SSL certificate"),
"<key>": i18n.T("The private key of the SSL certificate"),
},
),
Args: cobra.ExactArgs(3),
Short: i18n.T("Add an SSL certificate to an app"),
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
cert := args[1]
key := args[2]
return cmdr.CertAdd(app, cert, key, name)
},
}
return cmd
}
func certRemoveCommand(cmdr *commands.DryccCmd) *cobra.Command {
certCompletion := completion.CertCompletion{AppID: &app, ArgsLen: 0, ConfigFile: &cmdr.ConfigFile}
cmd := &cobra.Command{
Use: "remove <name>",
Example: template.CustomExample(
"drycc certs remove cert-name",
map[string]string{
"<name>": i18n.T("The name of the cert to remove from the app"),
},
),
Args: cobra.ExactArgs(1),
Short: i18n.T("Remove an SSL certificate from an app"),
ValidArgsFunction: certCompletion.CompletionFunc,
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
return cmdr.CertRemove(app, name)
},
}
return cmd
}
func certInfoCommand(cmdr *commands.DryccCmd) *cobra.Command {
certCompletion := completion.CertCompletion{AppID: &app, ArgsLen: 0, ConfigFile: &cmdr.ConfigFile}
cmd := &cobra.Command{
Use: "info <name>",
Example: template.CustomExample(
"drycc certs info cert-name",
map[string]string{
"<name>": i18n.T("The name of the cert to get information from"),
},
),
Args: cobra.ExactArgs(1),
Short: i18n.T("Get detailed informaton about the certificate"),
Long: i18n.T("Fetch more detailed information about a certificate"),
ValidArgsFunction: certCompletion.CompletionFunc,
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
return cmdr.CertInfo(app, name)
},
}
return cmd
}
func certAttachCommand(cmdr *commands.DryccCmd) *cobra.Command {
certTachCompletion := completion.CertDomainTachCompletion{AppID: &app, ConfigFile: &cmdr.ConfigFile}
cmd := &cobra.Command{
Use: "attach <name> <domain>",
Example: template.CustomExample(
"drycc certs attach cert-name id.example.com",
map[string]string{
"<name>": i18n.T("Name of the certificate to attach domain to"),
"<domain>": i18n.T("Common name of the domain to attach to (needs to already be in the system)"),
},
),
Args: cobra.ExactArgs(2),
Short: i18n.T("Attach an SSL certificate to a domain"),
Long: i18n.T("Attach a certificate to a domain"),
ValidArgsFunction: certTachCompletion.CompletionFunc,
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
domain := args[1]
return cmdr.CertAttach(app, name, domain)
},
}
return cmd
}
func certDetachCommand(cmdr *commands.DryccCmd) *cobra.Command {
certTachCompletion := completion.CertDomainTachCompletion{AppID: &app, ConfigFile: &cmdr.ConfigFile}
cmd := &cobra.Command{
Use: "detach <name> <domain>",
Example: template.CustomExample(
"drycc certs attach cert-name id.example.com",
map[string]string{
"<name>": i18n.T("Name of the certificate to deatch from a domain"),
"<domain>": i18n.T("Common name of the domain to detach from"),
},
),
Args: cobra.ExactArgs(2),
Short: i18n.T("Detach an SSL certificate from a domain"),
Long: i18n.T("Detach certificate from a domain"),
ValidArgsFunction: certTachCompletion.CompletionFunc,
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]
domain := args[1]
return cmdr.CertDetach(app, name, domain)
},
}
return cmd
}