refact client apis
parent
1e0f48b9b3
commit
0b87a4e26c
|
|
@ -26,12 +26,18 @@ const NA = "n/a"
|
|||
var supportedMetricsAPIVersions = []string{"v1beta1"}
|
||||
|
||||
type (
|
||||
// GKV tracks api resource version info.
|
||||
GKV struct {
|
||||
Group, Kind, Version string
|
||||
}
|
||||
|
||||
// APIGroup represents a K8s resource descriptor.
|
||||
APIGroup struct {
|
||||
Resource string
|
||||
Group, Kind, Version string
|
||||
Plural, Singular string
|
||||
Aliases []string
|
||||
GKV
|
||||
|
||||
Resource string
|
||||
Plural, Singular string
|
||||
Aliases []string
|
||||
}
|
||||
|
||||
// Collection of empty interfaces.
|
||||
|
|
@ -114,10 +120,9 @@ func (a *APIClient) CheckNSAccess(n string) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// CanIAccess checks if user has access to a certain resource.
|
||||
func (a *APIClient) canIAccess(ns, name, resURL string, verbs []string) (bool, error) {
|
||||
func makeSAR(ns, name, resURL string) *authorizationv1.SelfSubjectAccessReview {
|
||||
_, gr := schema.ParseResourceArg(strings.ToLower(resURL))
|
||||
sar := &authorizationv1.SelfSubjectAccessReview{
|
||||
return &authorizationv1.SelfSubjectAccessReview{
|
||||
Spec: authorizationv1.SelfSubjectAccessReviewSpec{
|
||||
ResourceAttributes: &authorizationv1.ResourceAttributes{
|
||||
Namespace: ns,
|
||||
|
|
@ -128,32 +133,24 @@ func (a *APIClient) canIAccess(ns, name, resURL string, verbs []string) (bool, e
|
|||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
user, _ := a.Config().CurrentUserName()
|
||||
groups, _ := a.Config().CurrentGroupNames()
|
||||
log.Debug().Msgf("AuthInfo user/groups: %s:%v", user, groups)
|
||||
|
||||
var (
|
||||
resp *authorizationv1.SelfSubjectAccessReview
|
||||
err error
|
||||
allow bool
|
||||
)
|
||||
// CanIAccess checks if user has access to a certain resource.
|
||||
func (a *APIClient) canIAccess(ns, name, resURL string, verbs []string) (bool, error) {
|
||||
sar := makeSAR(ns, name, resURL)
|
||||
dial := a.DialOrDie().AuthorizationV1().SelfSubjectAccessReviews()
|
||||
for _, v := range verbs {
|
||||
sar.Spec.ResourceAttributes.Verb = v
|
||||
resp, err = a.DialOrDie().AuthorizationV1().SelfSubjectAccessReviews().Create(sar)
|
||||
resp, err := dial.Create(sar)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msgf("CanIAccess")
|
||||
return false, err
|
||||
}
|
||||
log.Debug().Msgf("CHECKING ACCESS group:%q|resource:%q|namespace:%q|name:%q, verb:%s access:%t -- %s", gr.Group, gr.Resource, ns, name, v, resp.Status.Allowed, resp.Status.Reason)
|
||||
if !resp.Status.Allowed {
|
||||
return false, err
|
||||
}
|
||||
allow = true
|
||||
}
|
||||
log.Debug().Msgf("GRANT ACCESS? >>> %t", allow)
|
||||
|
||||
return allow, nil
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// CurrentNamespaceName return namespace name set via either cli arg or cluster config.
|
||||
|
|
@ -330,16 +327,23 @@ func (a *APIClient) supportsMxServer() bool {
|
|||
return false
|
||||
}
|
||||
|
||||
for _, discoveredAPIGroup := range apiGroups.Groups {
|
||||
if discoveredAPIGroup.Name != metricsapi.GroupName {
|
||||
for _, grp := range apiGroups.Groups {
|
||||
if grp.Name != metricsapi.GroupName {
|
||||
continue
|
||||
}
|
||||
if checkMetricsVersion(grp) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
for _, version := range discoveredAPIGroup.Versions {
|
||||
for _, supportedVersion := range supportedMetricsAPIVersions {
|
||||
if version.Version == supportedVersion {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func checkMetricsVersion(grp metav1.APIGroup) bool {
|
||||
for _, version := range grp.Versions {
|
||||
for _, supportedVersion := range supportedMetricsAPIVersions {
|
||||
if version.Version == supportedVersion {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,13 +14,19 @@ const (
|
|||
helpTitleFmt = " [aqua::b]%s "
|
||||
)
|
||||
|
||||
type helpView struct {
|
||||
*tview.TextView
|
||||
type (
|
||||
helpItem struct {
|
||||
key, description string
|
||||
}
|
||||
|
||||
app *appView
|
||||
current igniter
|
||||
actions keyActions
|
||||
}
|
||||
helpView struct {
|
||||
*tview.TextView
|
||||
|
||||
app *appView
|
||||
current igniter
|
||||
actions keyActions
|
||||
}
|
||||
)
|
||||
|
||||
func newHelpView(app *appView, current igniter) *helpView {
|
||||
v := helpView{TextView: tview.NewTextView(), app: app, actions: make(keyActions)}
|
||||
|
|
@ -58,10 +64,41 @@ func (v *helpView) backCmd(evt *tcell.EventKey) *tcell.EventKey {
|
|||
func (v *helpView) init(_ context.Context, _ string) {
|
||||
v.resetTitle()
|
||||
|
||||
type helpItem struct {
|
||||
key, description string
|
||||
}
|
||||
v.showGeneral()
|
||||
v.showNav()
|
||||
v.showHelp()
|
||||
v.app.setHints(v.hints())
|
||||
}
|
||||
|
||||
func (v *helpView) showHelp() {
|
||||
views := []helpItem{
|
||||
{"?", "Help"},
|
||||
{"Ctrl-a", "Aliases view"},
|
||||
}
|
||||
fmt.Fprintf(v, "️️\n😱 [aqua::b]%s\n", "Help")
|
||||
for _, h := range views {
|
||||
v.printHelp(h.key, h.description)
|
||||
}
|
||||
}
|
||||
|
||||
func (v *helpView) showNav() {
|
||||
navigation := []helpItem{
|
||||
{"g", "Goto Top"},
|
||||
{"G", "Goto Bottom"},
|
||||
{"Ctrl-b", "Page Down"},
|
||||
{"Ctrl-f", "Page Up"},
|
||||
{"h", "Left"},
|
||||
{"l", "Right"},
|
||||
{"k", "Up"},
|
||||
{"j", "Down"},
|
||||
}
|
||||
fmt.Fprintf(v, "\n🤖 [aqua::b]%s\n", "View Navigation")
|
||||
for _, h := range navigation {
|
||||
v.printHelp(h.key, h.description)
|
||||
}
|
||||
}
|
||||
|
||||
func (v *helpView) showGeneral() {
|
||||
general := []helpItem{
|
||||
{":<cmd>", "Command mode"},
|
||||
{"/<term>", "Filter mode"},
|
||||
|
|
@ -77,31 +114,6 @@ func (v *helpView) init(_ context.Context, _ string) {
|
|||
for _, h := range general {
|
||||
v.printHelp(h.key, h.description)
|
||||
}
|
||||
|
||||
navigation := []helpItem{
|
||||
{"g", "Goto Top"},
|
||||
{"G", "Goto Bottom"},
|
||||
{"Ctrl-b", "Page Down"},
|
||||
{"Ctrl-f", "Page Up"},
|
||||
{"h", "Left"},
|
||||
{"l", "Right"},
|
||||
{"k", "Up"},
|
||||
{"j", "Down"},
|
||||
}
|
||||
fmt.Fprintf(v, "\n🤖 [aqua::b]%s\n", "View Navigation")
|
||||
for _, h := range navigation {
|
||||
v.printHelp(h.key, h.description)
|
||||
}
|
||||
|
||||
views := []helpItem{
|
||||
{"?", "Help"},
|
||||
{"Ctrl-a", "Aliases view"},
|
||||
}
|
||||
fmt.Fprintf(v, "️️\n😱 [aqua::b]%s\n", "Help")
|
||||
for _, h := range views {
|
||||
v.printHelp(h.key, h.description)
|
||||
}
|
||||
v.app.setHints(v.hints())
|
||||
}
|
||||
|
||||
func (v *helpView) printHelp(key, desc string) {
|
||||
|
|
|
|||
|
|
@ -100,7 +100,6 @@ func (v *logsView) doLoad(path, co string, prevLogs bool) error {
|
|||
|
||||
l := v.CurrentPage().Item.(*logView)
|
||||
l.logs.Clear()
|
||||
l.path = path
|
||||
l.setTitle(path, co)
|
||||
|
||||
c := make(chan string, 10)
|
||||
|
|
|
|||
|
|
@ -50,9 +50,11 @@ func allCRDs(c k8s.Connection, m map[string]resCmd) {
|
|||
ff := crd.ExtFields()
|
||||
|
||||
grp := k8s.APIGroup{
|
||||
Group: ff["group"].(string),
|
||||
Kind: ff["kind"].(string),
|
||||
Version: ff["version"].(string),
|
||||
GKV: k8s.GKV{
|
||||
Group: ff["group"].(string),
|
||||
Kind: ff["kind"].(string),
|
||||
Version: ff["version"].(string),
|
||||
},
|
||||
}
|
||||
|
||||
res := resCmd{
|
||||
|
|
|
|||
Loading…
Reference in New Issue