-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
166 lines (161 loc) · 3.62 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
package main
import (
"fmt"
"os"
"github.com/sam701/awstools/assume"
"github.com/sam701/awstools/cf"
"github.com/sam701/awstools/config"
"github.com/sam701/awstools/cw"
"github.com/sam701/awstools/ddb"
"github.com/sam701/tcolor"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "awstools"
app.Version = "0.13.2"
app.Usage = "AWS tools"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config, c",
Usage: "path to config.toml file (default: ~/.config/awstools/config.toml)",
},
cli.BoolFlag{
Name: "no-color",
Usage: "turn off color output",
},
}
app.Commands = []cli.Command{
assume.Command,
{
Name: "accounts",
Usage: "print known accounts",
Action: actionPrintKnownAccounts,
},
{
Name: "ec2",
Usage: "print EC2 instances and ELBs",
ArgsUsage: "<EC2 instance tag substring>",
Action: actionDescribeEC2,
},
cf.Command(),
{
Name: "rotate-main-account-key",
ShortName: "r",
Usage: "create a new access key for main account and delete the current one",
Action: assume.RotateMainAccountKeyAction,
},
ddb.Command(),
{
Name: "kms",
Usage: "encrypt/decrypt text",
ArgsUsage: "<text to de-/encrypt>",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "list-keys, l",
Usage: "list KMS keys",
},
cli.BoolFlag{
Name: "decrypt, d",
Usage: "decrypt base64 encoded string",
},
cli.BoolFlag{
Name: "encrypt, e",
Usage: "encrypt and base64 encode string",
},
cli.StringFlag{
Name: "key-id",
Usage: "use `KEYID` for encryption/decryption",
},
cli.BoolFlag{
Name: "quiet, q",
Usage: "print only de-/encrypted text",
},
},
Action: kmsAction,
},
{
Name: "kinesis",
Usage: "print records from kinesis streams",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "list-streams, l",
Usage: "list kinesis streams",
},
cli.StringFlag{
Name: "search-stream, s",
Usage: "search `STREAM`",
},
cli.StringFlag{
Name: "at-timestamp",
Usage: "start reading events from the specified `TIMESTAMP`",
},
cli.BoolFlag{
Name: "trim-horizon",
Usage: "Search from the last untrimmed record in the shards",
},
cli.StringSliceFlag{
Name: "pattern, p",
Usage: "search for (case sensitive) `PATTERN`",
},
cli.BoolFlag{
Name: "no-timestamp",
Usage: "do not print record timestamps",
},
cli.BoolFlag{
Name: "gunzip",
Usage: "gunzip event content",
},
},
Action: kinesisPrintRecords,
},
{
Name: "cloudwatch",
ShortName: "cw",
Usage: "search in cloudwatch logs",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "list-groups, l",
Usage: "list CloudWatch groups",
},
cli.StringFlag{
Name: "group, g",
Usage: "`GROUP` to grab (or a unique substring)",
},
cli.StringFlag{
Name: "pattern, p",
Usage: "`PATTERN` to grab",
},
cli.StringFlag{
Name: "start",
Usage: "start `TIME` to grab",
Value: "-24h",
},
cli.StringFlag{
Name: "end",
Usage: "end `TIME` to grab",
Value: "now",
},
cli.IntFlag{
Name: "duration",
Usage: "duration in seconds",
},
},
Action: cw.CloudwatchAction,
},
}
app.Before = func(c *cli.Context) error {
config.Read(c.String("config"))
if c.GlobalBool("no-color") {
tcolor.ColorOn = false
}
return nil
}
app.Run(os.Args)
}
func actionPrintKnownAccounts(c *cli.Context) error {
for name, accountId := range config.Current.Accounts {
fmt.Println(name, "=", accountId)
}
return nil
}