generated from accelerator-blueprints/base-blueprint
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (55 loc) · 1.43 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
package main
import (
"fmt"
"os"
"strings"
flag "github.com/spf13/pflag"
legacy "awshowto/aws"
. "awshowto/internal"
)
func main() {
var isListRoles, isSts, isCreateRole, isDeleteRole, isAttachInlinePolicies bool
flags := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
flags.Usage = func() {
printHelp(flags)
}
flags.BoolVar(&isListRoles, "list-roles", false, "AWS IAM list all roles.")
flags.BoolVar(&isCreateRole, "create-role", false, "AWS IAM create role.")
flags.BoolVar(&isDeleteRole, "delete-role", false, "AWS IAM delete role.")
flags.BoolVar(&isAttachInlinePolicies, "attach-inline", false, "AWS IAM attach inline policies to a role.")
flags.BoolVar(&isSts, "show-sts", false, "Show STS config.")
_ = flags.Parse(os.Args[0:])
args := flags.Args()
if len(args) == 0 {
printHelp(flags)
return
}
cmp := legacy.New()
if isListRoles {
cmp.ListRoles()
}
if isCreateRole {
cmp.CreateRole()
}
if isDeleteRole {
cmp.DeleteRole()
}
if isAttachInlinePolicies {
cmp.AttachInlinePolicies()
}
if isSts {
acc, err := cmp.AccountAnalyzer()
CheckError("sts", err)
OutputColorizedMessage("blue", fmt.Sprintf("\tAccount:: %s. Aliases: %s\n", acc.Account, acc.Aliases))
}
}
func printHelp(fs *flag.FlagSet) {
_, _ = fmt.Fprintf(os.Stderr, "\n"+strings.TrimSpace(help)+"\n")
fs.PrintDefaults()
}
const help = `
awshowto - how to code AWS resources with aws-go-sdk.
USAGE:
$ awshowto [flags]
FLAGS:
`