-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
group.go
50 lines (41 loc) 路 1.24 KB
/
group.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
package view
import (
"context"
"github.com/derailed/k9s/internal"
"github.com/derailed/k9s/internal/client"
"github.com/derailed/k9s/internal/render"
"github.com/derailed/k9s/internal/ui"
"github.com/gdamore/tcell/v2"
)
// Group presents a RBAC group viewer.
type Group struct {
ResourceViewer
}
// NewGroup returns a new subject viewer.
func NewGroup(gvr client.GVR) ResourceViewer {
g := Group{ResourceViewer: NewBrowser(gvr)}
g.GetTable().SetColorerFn(render.Subject{}.ColorerFunc())
g.AddBindKeysFn(g.bindKeys)
g.SetContextFn(g.subjectCtx)
return &g
}
func (g *Group) bindKeys(aa ui.KeyActions) {
aa.Delete(ui.KeyShiftA, ui.KeyShiftP, tcell.KeyCtrlSpace, ui.KeySpace)
aa.Add(ui.KeyActions{
tcell.KeyEnter: ui.NewKeyAction("Rules", g.policyCmd, true),
ui.KeyShiftK: ui.NewKeyAction("Sort Kind", g.GetTable().SortColCmd("KIND", true), false),
})
}
func (g *Group) subjectCtx(ctx context.Context) context.Context {
return context.WithValue(ctx, internal.KeySubjectKind, "Group")
}
func (g *Group) policyCmd(evt *tcell.EventKey) *tcell.EventKey {
path := g.GetTable().GetSelectedItem()
if path == "" {
return evt
}
if err := g.App().inject(NewPolicy(g.App(), "Group", path)); err != nil {
g.App().Flash().Err(err)
}
return nil
}