Skip to content

Commit

Permalink
Merge pull request #39 from pehlicd/feat-dump-of-new-features
Browse files Browse the repository at this point in the history
feat: updates on graph and table
  • Loading branch information
pehlicd authored May 21, 2024
2 parents 958573b + 39840bb commit 81a9e14
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 169 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

# RBAC Wizard

![go version](https://img.shields.io/github/go-mod/go-version/pehlicd/rbac-wizard)
![release](https://img.shields.io/github/v/release/pehlicd/rbac-wizard)
![license](https://img.shields.io/github/license/pehlicd/rbac-wizard) ![go report](https://img.shields.io/badge/go%20report-A+-brightgreen.svg?style=flat)

RBAC Wizard is a tool that helps you visualize and analyze the RBAC configurations of your Kubernetes cluster. It provides a graphical representation of the Kubernetes RBAC objects.

<div align="center">
Expand Down
12 changes: 9 additions & 3 deletions cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func serve(port string) {

func dashboardHandler(w http.ResponseWriter, r *http.Request) {
// Set cache control headers
cacheControllers(w)

statikFS, err := fs.New()
if err != nil {
Expand All @@ -107,9 +108,7 @@ func dashboardHandler(w http.ResponseWriter, r *http.Request) {

func dataHandler(w http.ResponseWriter, r *http.Request) {
// Set cache control headers
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Expires", "0")
cacheControllers(w)

// Get the bindings
bindings, err := internal.Generator(app).GetBindings()
Expand All @@ -129,3 +128,10 @@ func dataHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write(byteData)
}

func cacheControllers(w http.ResponseWriter) {
// Set cache control headers
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Set("Pragma", "no-cache")
w.Header().Set("Expires", "0")
}
32 changes: 30 additions & 2 deletions internal/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package internal
import (
"context"
"fmt"
"gopkg.in/yaml.v2"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer/json"
"k8s.io/client-go/kubernetes/scheme"
)

func (app App) GetBindings() (*Bindings, error) {
Expand Down Expand Up @@ -37,7 +41,7 @@ func GenerateData(bindings *Bindings) []Data {
Kind: "ClusterRoleBinding",
Subjects: crb.Subjects,
RoleRef: crb.RoleRef,
Raw: crb.String(),
Raw: yamlParser(&crb),
})
}

Expand All @@ -48,9 +52,33 @@ func GenerateData(bindings *Bindings) []Data {
Kind: "RoleBinding",
Subjects: rb.Subjects,
RoleRef: rb.RoleRef,
Raw: rb.String(),
Raw: yamlParser(&rb),
})
}

return data
}

func yamlParser(obj runtime.Object) string {
// Convert the object to YAML
s := json.NewSerializerWithOptions(json.DefaultMetaFactory, scheme.Scheme, scheme.Scheme, json.SerializerOptions{Yaml: true, Pretty: true})
o, err := runtime.Encode(s, obj)
if err != nil {
return ""
}

// Unmarshal the JSON into a generic map
var yamlObj map[string]interface{}
err = yaml.Unmarshal(o, &yamlObj)
if err != nil {
return err.Error()
}

// Marshal the map back into YAML
yamlData, err := yaml.Marshal(yamlObj)
if err != nil {
return err.Error()
}

return string(yamlData)
}
2 changes: 1 addition & 1 deletion internal/statik/statik.go

Large diffs are not rendered by default.

Loading

0 comments on commit 81a9e14

Please sign in to comment.