-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
238 lines (229 loc) · 5.76 KB
/
main.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
package main
import (
"fmt"
"log"
"os"
"runtime"
"time"
"github.com/clok/cdocs"
"github.com/clok/sm/cmd"
"github.com/clok/sm/info"
"github.com/urfave/cli/v2"
)
var version string
func main() {
// Generate the install-manpage command
im, err := cdocs.InstallManpageCommand(&cdocs.InstallManpageCommandInput{
AppName: info.AppName,
Hidden: true,
})
if err != nil {
log.Fatal(err)
}
app := &cli.App{
Name: info.AppName,
Version: version,
Compiled: time.Now(),
Authors: []*cli.Author{
{
Name: info.AppRepoOwner,
},
},
Copyright: "(c) 2021 Derek Smith",
HelpName: info.AppName,
Usage: "AWS Secrets Manager CLI Tool",
EnableBashCompletion: true,
Commands: []*cli.Command{
{
// get-secret-value
Name: "get",
Aliases: []string{"view"},
Usage: "select from list or pass in specific secret",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "secret-id",
Aliases: []string{"s"},
Usage: "Specific Secret to view, will bypass select/search",
},
&cli.BoolFlag{
Name: "binary",
Aliases: []string{"b"},
Usage: "get the SecretBinary value",
DefaultText: info.SecretBinaryHelp,
},
},
Action: cmd.ViewSecret,
},
{
Name: "edit",
Aliases: []string{"e"},
Usage: "interactive edit of a secret String Value",
// TODO: add UsageText
Flags: []cli.Flag{
&cli.StringFlag{
Name: "secret-id",
Aliases: []string{"s"},
Usage: "Specific Secret to edit, will bypass select/search",
},
&cli.BoolFlag{
Name: "binary",
Aliases: []string{"b"},
Usage: "get the SecretBinary value",
DefaultText: info.SecretBinaryHelp,
},
// TODO: add flag for passing version stage
},
Action: cmd.EditSecret,
},
{
// create-secret
Name: "create",
Aliases: []string{"c"},
Usage: "create new secret in Secrets Manager",
// TODO: add UsageText
Flags: []cli.Flag{
&cli.StringFlag{
Name: "secret-id",
Aliases: []string{"s"},
Usage: "Secret name",
Required: true,
},
&cli.BoolFlag{
Name: "binary",
Aliases: []string{"b"},
Usage: "get the SecretBinary value",
DefaultText: info.SecretBinaryHelp,
},
&cli.StringFlag{
Name: "value",
Aliases: []string{"v"},
Usage: "Secret Value. Will store as a string, unless binary flag is set.",
},
&cli.BoolFlag{
Name: "interactive",
Aliases: []string{"i"},
Usage: "Open interactive editor to create secret value. If no 'value' is provided, an editor will be opened by default.",
},
&cli.StringFlag{
Name: "description",
Aliases: []string{"d"},
Usage: "Additional description text.",
},
&cli.StringFlag{
Name: "tags",
Aliases: []string{"t"},
Usage: "key=value tags (CSV list)",
},
},
Action: cmd.CreateSecret,
},
{
// put-secret-value
Name: "put",
Usage: "non-interactive update to a specific secret",
UsageText: `
Stores a new encrypted secret value in the specified secret. To do this, the
operation creates a new version and attaches it to the secret. The version
can contain a new SecretString value or a new SecretBinary value.
This will put the value to AWSCURRENT and retain one previous version
with AWSPREVIOUS.
`,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "secret-id",
Aliases: []string{"s"},
Usage: "Secret name",
Required: true,
},
&cli.BoolFlag{
Name: "binary",
Aliases: []string{"b"},
Usage: "get the SecretBinary value",
DefaultText: info.SecretBinaryHelp,
},
&cli.StringFlag{
Name: "value",
Aliases: []string{"v"},
Usage: "Secret Value. Will store as a string, unless binary flag is set.",
},
&cli.BoolFlag{
Name: "interactive",
Aliases: []string{"i"},
Usage: "Override and open interactive editor to verify and modify the new secret value.",
},
// TODO: add flag for passing version stage
},
Action: cmd.PutSecret,
},
{
Name: "delete",
Aliases: []string{"del"},
Usage: "delete a specific secret",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "secret-id",
Aliases: []string{"s"},
Usage: "Specific Secret to delete",
Required: true,
},
&cli.BoolFlag{
Name: "force",
Aliases: []string{"f"},
Usage: "Bypass recovery window (30 days) and immediately delete Secret.",
},
},
Action: cmd.DeleteSecret,
},
{
// list-secrets
Name: "list",
Usage: "display table of all secrets with meta data",
Action: cmd.ListSecrets,
},
{
// describe-secret
Name: "describe",
Usage: "print description of secret to `STDOUT`",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "secret-id",
Aliases: []string{"s"},
Usage: "Specific Secret to describe, will bypass select/search",
},
},
Action: cmd.DescribeSecret,
},
im,
{
Name: "version",
Aliases: []string{"v"},
Usage: "Print version info",
Hidden: true,
Action: func(c *cli.Context) error {
fmt.Printf("%s %s (%s/%s)\n", info.AppName, version, runtime.GOOS, runtime.GOARCH)
return nil
},
},
},
}
if os.Getenv("DOCS_MD") != "" {
docs, err := cdocs.ToMarkdown(app)
if err != nil {
panic(err)
}
fmt.Println(docs)
return
}
if os.Getenv("DOCS_MAN") != "" {
docs, err := cdocs.ToMan(app)
if err != nil {
panic(err)
}
fmt.Println(docs)
return
}
err = app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}