-
Notifications
You must be signed in to change notification settings - Fork 26
/
s3.go
60 lines (52 loc) · 1.67 KB
/
s3.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
package view
import (
"context"
"github.com/gdamore/tcell/v2"
"github.com/one2nc/cloudlens/internal"
"github.com/one2nc/cloudlens/internal/ui"
)
type S3 struct {
ResourceViewer
}
func NewS3(resource string) ResourceViewer {
var s3 S3
s3.ResourceViewer = NewBrowser(resource)
s3.AddBindKeysFn(s3.bindKeys)
// s3.GetTable().SetEnterFn(s3.describeInstace)
return &s3
}
func (s3 *S3) bindKeys(aa ui.KeyActions) {
aa.Add(ui.KeyActions{
ui.KeyShiftB: ui.NewKeyAction("Sort Bucket-Name", s3.GetTable().SortColCmd("Bucket-Name", true), true),
ui.KeyShiftT: ui.NewKeyAction("Sort Creation-Time", s3.GetTable().SortColCmd("Creation-Time", true), true),
tcell.KeyEscape: ui.NewKeyAction("Back", s3.App().PrevCmd, false),
tcell.KeyEnter: ui.NewKeyAction("View", s3.enterCmd, false),
ui.KeyD: ui.NewKeyAction("Describe", s3.describeBucket, true),
})
}
func (s3 *S3) describeBucket(evt *tcell.EventKey) *tcell.EventKey {
bName := s3.GetTable().GetSelectedItem()
f := describeResource
if s3.GetTable().enterFn != nil {
f = s3.GetTable().enterFn
}
if bName != "" {
s3.App().Flash().Info("Bucket-Name: " + bName)
f(s3.App(), s3.GetTable().GetModel(), s3.Resource(), bName)
}
return nil
}
func (s3 *S3) enterCmd(evt *tcell.EventKey) *tcell.EventKey {
bName := s3.GetTable().GetSelectedItem()
if bName != "" {
o := NewS3FileViewer("s3://", bName)
ctx := context.WithValue(s3.App().GetContext(), internal.BucketName, bName)
s3.App().SetContext(ctx)
ctx = context.WithValue(s3.App().GetContext(), internal.FolderName, "")
s3.App().SetContext(ctx)
s3.App().Flash().Info("Bucket Name: " + bName)
s3.App().inject(o)
o.GetTable().SetTitle(o.path)
}
return nil
}