/
iam_users.go
152 lines (140 loc) · 3.37 KB
/
iam_users.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
package main
import (
"github.com/bporter816/aws-tui/model"
"github.com/bporter816/aws-tui/repo"
"github.com/bporter816/aws-tui/ui"
"github.com/bporter816/aws-tui/utils"
"github.com/bporter816/aws-tui/view"
"github.com/gdamore/tcell/v2"
)
type IAMUsers struct {
*ui.Table
view.IAM
repo *repo.IAM
groupName *string
app *Application
}
func NewIAMUsers(repo *repo.IAM, groupName *string, app *Application) *IAMUsers {
i := &IAMUsers{
Table: ui.NewTable([]string{
"ID",
"NAME",
"PATH",
"CREATED",
"PASSWORD LAST USED",
}, 1, 0),
repo: repo,
groupName: groupName,
app: app,
}
return i
}
func (i IAMUsers) GetLabels() []string {
if i.groupName == nil {
return []string{"Users"}
} else {
return []string{*i.groupName, "Users"}
}
}
func (i IAMUsers) accessKeysHandler() {
userName, err := i.GetColSelection("NAME")
if err != nil {
return
}
accessKeysView := NewIAMAccessKeys(i.repo, userName, i.app)
i.app.AddAndSwitch(accessKeysView)
}
func (i IAMUsers) policiesHandler() {
userName, err := i.GetColSelection("NAME")
if err != nil {
return
}
policiesView := NewIAMPolicies(i.repo, model.IAMIdentityTypeUser, &userName, i.app)
i.app.AddAndSwitch(policiesView)
}
func (i IAMUsers) permissionsBoundaryHandler() {
userName, err := i.GetColSelection("NAME")
if err != nil {
return
}
permissionsBoundaryView := NewIAMPolicy(i.repo, model.IAMIdentityTypeUser, model.IAMPolicyTypePermissionsBoundary, userName, "", "", i.app)
i.app.AddAndSwitch(permissionsBoundaryView)
}
func (i IAMUsers) groupsHandler() {
userName, err := i.GetColSelection("NAME")
if err != nil {
return
}
groupsView := NewIAMGroups(i.repo, &userName, i.app)
i.app.AddAndSwitch(groupsView)
}
func (i IAMUsers) tagsHandler() {
userName, err := i.GetColSelection("NAME")
if err != nil {
return
}
tagsView := NewTags(i.repo, i.GetService(), "user:"+userName, i.app)
i.app.AddAndSwitch(tagsView)
}
func (i IAMUsers) GetKeyActions() []KeyAction {
return []KeyAction{
{
Key: tcell.NewEventKey(tcell.KeyRune, 'a', tcell.ModNone),
Description: "Access Keys",
Action: i.accessKeysHandler,
},
{
Key: tcell.NewEventKey(tcell.KeyRune, 'p', tcell.ModNone),
Description: "Policies",
Action: i.policiesHandler,
},
{
Key: tcell.NewEventKey(tcell.KeyRune, 'b', tcell.ModNone),
Description: "Permissions Boundary",
Action: i.permissionsBoundaryHandler,
},
{
Key: tcell.NewEventKey(tcell.KeyRune, 'r', tcell.ModNone),
Description: "Groups",
Action: i.groupsHandler,
},
{
Key: tcell.NewEventKey(tcell.KeyRune, 't', tcell.ModNone),
Description: "Tags",
Action: i.tagsHandler,
},
}
}
func (i IAMUsers) Render() {
model, err := i.repo.ListUsers(i.groupName)
if err != nil {
panic(err)
}
var data [][]string
for _, v := range model {
var userId, userName, path, created, passwordLastUsed string
if v.UserId != nil {
userId = *v.UserId
}
if v.UserName != nil {
userName = *v.UserName
}
if v.Path != nil {
path = *v.Path
}
if v.CreateDate != nil {
created = v.CreateDate.Format(utils.DefaultTimeFormat)
}
if v.PasswordLastUsed != nil {
passwordLastUsed = v.PasswordLastUsed.Format(utils.DefaultTimeFormat)
}
data = append(data, []string{
userId,
userName,
path,
created,
passwordLastUsed,
})
}
i.SetData(data)
}