/
elasticache_groups.go
87 lines (78 loc) · 1.68 KB
/
elasticache_groups.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
package main
import (
"fmt"
"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 ElastiCacheGroups struct {
*ui.Table
view.ElastiCache
repo *repo.ElastiCache
app *Application
model []model.ElastiCacheGroup
}
func NewElastiCacheGroups(repo *repo.ElastiCache, app *Application) *ElastiCacheGroups {
e := &ElastiCacheGroups{
Table: ui.NewTable([]string{
"ID",
"STATUS",
"USERS",
"CLUSTERS",
}, 1, 0),
repo: repo,
app: app,
}
return e
}
func (e ElastiCacheGroups) GetLabels() []string {
return []string{"Groups"}
}
func (e ElastiCacheGroups) tagsHandler() {
row, err := e.GetRowSelection()
if err != nil {
return
}
if arn := e.model[row-1].ARN; arn != nil {
tagsView := NewTags(e.repo, e.GetService(), *arn, e.app)
e.app.AddAndSwitch(tagsView)
}
}
func (e ElastiCacheGroups) GetKeyActions() []KeyAction {
return []KeyAction{
{
Key: tcell.NewEventKey(tcell.KeyRune, 't', tcell.ModNone),
Description: "Tags",
Action: e.tagsHandler,
},
}
}
func (e *ElastiCacheGroups) Render() {
model, err := e.repo.ListGroups()
if err != nil {
panic(err)
}
e.model = model
var data [][]string
for _, v := range model {
var id, status, users, clusters string
if v.UserGroupId != nil {
id = *v.UserGroupId
}
if v.Status != nil {
status = utils.TitleCase(*v.Status)
}
users = fmt.Sprintf("%v", len(v.UserIds))
clusters = fmt.Sprintf("%v", len(v.ReplicationGroups))
data = append(data, []string{
id,
status,
users,
clusters,
})
}
e.SetData(data)
}