-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaliases.go
85 lines (67 loc) · 1.68 KB
/
aliases.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
package main
import (
"flag"
"fmt"
"os"
"strings"
"github.com/mitchellh/cli"
"github.com/pr8kerl/organizer/aws"
)
// List Aliases
type ListAliasesCommand struct {
AccountId string
Report bool
Region string
Ui cli.Ui
}
func listAliasesCmdFactory() (cli.Command, error) {
ui := &cli.BasicUi{
Reader: os.Stdin,
Writer: os.Stdout,
ErrorWriter: os.Stderr,
}
return &ListAliasesCommand{
AccountId: "",
Report: false,
Region: "",
Ui: ui,
}, nil
}
func (c *ListAliasesCommand) Run(args []string) int {
cmdFlags := flag.NewFlagSet("list aliases", flag.ContinueOnError)
cmdFlags.StringVar(&c.AccountId, "accountid", "", "list account aliases for a specific account")
cmdFlags.Usage = func() { c.Ui.Output(c.Help()); os.Exit(1) }
if err := cmdFlags.Parse(args); err != nil {
return 1
}
org, err := aws.NewOrganization()
if err != nil {
fmt.Printf("error: could not initialize organization: %s\n", err)
return 1
}
if len(c.AccountId) > 0 {
err = org.PrintAliasesForAccount(c.AccountId)
if err != nil {
fmt.Printf("error: could not list aliases for account: %s\n", err)
return 1
}
} else {
err = org.PrintAliases()
if err != nil {
fmt.Printf("error: could not list all account aliases: %s\n", err)
return 1
}
}
return 0
}
func (c *ListAliasesCommand) Help() string {
helpText := `usage: organizer list aliases [<args>]
List account aliases for accounts within an organization
Options:
-accountid list all iam users for a specific account only
`
return strings.TrimSpace(helpText)
}
func (c *ListAliasesCommand) Synopsis() string {
return "list account aliases for all accounts within an organization"
}