/
route53_health_checks.go
88 lines (79 loc) · 1.84 KB
/
route53_health_checks.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
package main
import (
r53Types "github.com/aws/aws-sdk-go-v2/service/route53/types"
"github.com/bporter816/aws-tui/repo"
"github.com/bporter816/aws-tui/ui"
"github.com/bporter816/aws-tui/view"
"github.com/gdamore/tcell/v2"
)
type Route53HealthChecks struct {
*ui.Table
view.Route53
repo *repo.Route53
app *Application
}
func NewRoute53HealthChecks(repo *repo.Route53, app *Application) *Route53HealthChecks {
r := &Route53HealthChecks{
Table: ui.NewTable([]string{
"ID",
"NAME",
"TYPE",
"DESCRIPTION",
}, 1, 0),
repo: repo,
app: app,
}
return r
}
func (r Route53HealthChecks) GetLabels() []string {
return []string{"Health Checks"}
}
func (r Route53HealthChecks) tagsHandler() {
healthCheckId, err := r.GetColSelection("ID")
if err != nil {
return
}
tagsView := NewTags(r.repo, r.GetService(), string(r53Types.TagResourceTypeHealthcheck)+":"+healthCheckId, r.app)
r.app.AddAndSwitch(tagsView)
}
func (r Route53HealthChecks) GetKeyActions() []KeyAction {
return []KeyAction{
{
Key: tcell.NewEventKey(tcell.KeyRune, 't', tcell.ModNone),
Description: "Tags",
Action: r.tagsHandler,
},
}
}
func (r Route53HealthChecks) Render() {
model, err := r.repo.ListHealthChecks()
if err != nil {
panic(err)
}
var data [][]string
for _, v := range model {
var id, name, checkType, description string
if v.Id != nil {
id = *v.Id
// name comes from the Name tag
tags, err := r.repo.ListTags(string(r53Types.TagResourceTypeHealthcheck) + ":" + *v.Id)
if err != nil {
panic(err)
}
if n, ok := tags.Get("Name"); ok {
name = n
}
}
if v.HealthCheckConfig != nil {
checkType = string(v.HealthCheckConfig.Type)
description = getHealthCheckDescription(*v.HealthCheckConfig)
}
data = append(data, []string{
id,
name,
checkType,
description,
})
}
r.SetData(data)
}