-
Notifications
You must be signed in to change notification settings - Fork 26
/
iam_user_group.go
56 lines (49 loc) · 1.74 KB
/
iam_user_group.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
package view
import (
"context"
"github.com/gdamore/tcell/v2"
"github.com/one2nc/cloudlens/internal"
"github.com/one2nc/cloudlens/internal/ui"
)
type IAMUG struct {
ResourceViewer
}
// NewUG returns a new viewer.
func NewIAMUG(resource string) ResourceViewer {
var iamug IAMUG
iamug.ResourceViewer = NewBrowser(resource)
iamug.AddBindKeysFn(iamug.bindKeys)
return &iamug
}
func (iamug IAMUG) bindKeys(aa ui.KeyActions) {
aa.Add(ui.KeyActions{
ui.KeyShiftI: ui.NewKeyAction("Sort Group-Id ", iamug.GetTable().SortColCmd("Group-Id", true), true),
ui.KeyShiftN: ui.NewKeyAction("Sort Group-Name", iamug.GetTable().SortColCmd("Group-Name", true), true),
ui.KeyShiftD: ui.NewKeyAction("Sort Created-Date", iamug.GetTable().SortColCmd("Created-Date", true), true),
tcell.KeyEscape: ui.NewKeyAction("Back", iamug.App().PrevCmd, false),
tcell.KeyEnter: ui.NewKeyAction("Group Users", iamug.enterCmd, false),
ui.KeyShiftP: ui.NewKeyAction("View", iamug.policyCmd, true),
})
}
func (iamug *IAMUG) policyCmd(evt *tcell.EventKey) *tcell.EventKey {
grpName := iamug.GetTable().GetSecondColumn()
if grpName != "" {
up := NewIamUserGroupPloicy("User Group Policy")
ctx := context.WithValue(iamug.App().GetContext(), internal.GroupName, grpName)
iamug.App().SetContext(ctx)
iamug.App().Flash().Info("userName: " + grpName)
iamug.App().inject(up)
}
return nil
}
func (iamug *IAMUG) enterCmd(evt *tcell.EventKey) *tcell.EventKey {
grpName := iamug.GetTable().GetSecondColumn()
if grpName != "" {
gu := NewIamGroupUser("Group Users")
ctx := context.WithValue(iamug.App().GetContext(), internal.GroupName, grpName)
iamug.App().SetContext(ctx)
iamug.App().Flash().Info("userName: " + grpName)
iamug.App().inject(gu)
}
return nil
}