/
elb_listeners.go
120 lines (111 loc) · 2.54 KB
/
elb_listeners.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
package main
import (
"strconv"
"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"
)
// TODO support load balancer lists by lb arns
// TODO better manage name/arn
type ELBListeners struct {
*ui.Table
view.ELB
repo *repo.ELB
lbArn string
lbName string
app *Application
model []model.ELBListener
}
func NewELBListeners(repo *repo.ELB, lbArn string, lbName string, app *Application) *ELBListeners {
e := &ELBListeners{
Table: ui.NewTable([]string{
"PROTOCOL",
"PORT",
"RULES",
"SSL POLICY",
"DEFAULT CERTIFICATE",
"MTLS MODE",
}, 1, 0),
repo: repo,
lbArn: lbArn,
lbName: lbName,
app: app,
}
return e
}
func (e ELBListeners) GetLabels() []string {
return []string{e.lbName, "Listeners"}
}
func (e ELBListeners) tagsHandler() {
row, err := e.GetRowSelection()
if err != nil {
return
}
/*
protocol, err := e.GetColSelection("PROTOCOL")
if err != nil {
return
}
port, err := e.GetColSelection("PORT")
if err != nil {
return
}
*/
if arn := e.model[row-1].ListenerArn; arn != nil {
// TODO display protocol and port
tagsView := NewTags(e.repo, e.GetService(), *arn, e.app)
e.app.AddAndSwitch(tagsView)
}
}
func (e ELBListeners) GetKeyActions() []KeyAction {
return []KeyAction{
{
Key: tcell.NewEventKey(tcell.KeyRune, 't', tcell.ModNone),
Description: "Tags",
Action: e.tagsHandler,
},
}
}
func (e *ELBListeners) Render() {
model, err := e.repo.ListListeners(e.lbArn)
if err != nil {
panic(err)
}
e.model = model
var data [][]string
for _, v := range model {
var protocol, port, rules, sslPolicy, defaultCertificate, mtlsMode string
protocol = string(v.Protocol)
if v.Port != nil {
port = strconv.Itoa(int(*v.Port))
}
rules = strconv.Itoa(v.Rules)
if v.SslPolicy != nil {
sslPolicy = *v.SslPolicy
}
for _, c := range v.Certificates {
if c.IsDefault != nil && *c.IsDefault && c.CertificateArn != nil {
defaultCertificate = *c.CertificateArn
break
}
}
if len(v.Certificates) == 1 && v.Certificates[0].CertificateArn != nil {
defaultCertificate = *v.Certificates[0].CertificateArn
}
if v.MutualAuthentication != nil && v.MutualAuthentication.Mode != nil {
mtlsMode = utils.AutoCase(*v.MutualAuthentication.Mode)
}
data = append(data, []string{
protocol,
port,
rules,
sslPolicy,
defaultCertificate,
mtlsMode,
})
}
e.SetData(data)
}