-
Notifications
You must be signed in to change notification settings - Fork 26
/
vpc.go
57 lines (49 loc) · 1.49 KB
/
vpc.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
package view
import (
"context"
"github.com/gdamore/tcell/v2"
"github.com/one2nc/cloudlens/internal"
"github.com/one2nc/cloudlens/internal/ui"
)
type VPC struct {
ResourceViewer
}
// NewPod returns a new viewer.
func NewVPC(resource string) ResourceViewer {
var v VPC
v.ResourceViewer = NewBrowser(resource)
v.AddBindKeysFn(v.bindKeys)
return &v
}
func (v *VPC) bindKeys(aa ui.KeyActions) {
aa.Add(ui.KeyActions{
ui.KeyShiftI: ui.NewKeyAction("Sort VPC-Id", v.GetTable().SortColCmd("VPC-Id", true), true),
ui.KeyShiftS: ui.NewKeyAction("Sort VPC-State", v.GetTable().SortColCmd("VPC-State", true), true),
tcell.KeyEscape: ui.NewKeyAction("Back", v.App().PrevCmd, false),
tcell.KeyEnter: ui.NewKeyAction("View", v.enterCmd, true),
ui.KeyS: ui.NewKeyAction("View Subnets", v.subnetCmd, true),
})
}
func (v *VPC) enterCmd(evt *tcell.EventKey) *tcell.EventKey {
vpcId := v.GetTable().GetSelectedItem()
if vpcId != "" {
f := describeResource
if v.GetTable().enterFn != nil {
f = v.GetTable().enterFn
}
f(v.App(), v.GetTable().GetModel(), v.Resource(), vpcId)
v.App().Flash().Info("VPC Id: " + vpcId)
}
return nil
}
func (iamug *VPC) subnetCmd(evt *tcell.EventKey) *tcell.EventKey {
vpcId := iamug.GetTable().GetSelectedItem()
if vpcId != "" {
sn := NewSubnet("subnet")
ctx := context.WithValue(iamug.App().GetContext(), internal.VpcId, vpcId)
iamug.App().SetContext(ctx)
iamug.App().Flash().Info("VPC ID: " + vpcId)
iamug.App().inject(sn)
}
return nil
}