diff --git a/cmd/wasm/main.go b/cmd/wasm/main.go new file mode 100644 index 0000000..aa712c2 --- /dev/null +++ b/cmd/wasm/main.go @@ -0,0 +1,89 @@ +//go:build wasm +// +build wasm + +package main + +import ( + "fmt" + "io" + "strings" + "syscall/js" + + t2html "github.com/buildkite/terminal-to-html" + "github.com/fatih/color" + "github.com/zegl/kube-score/config" + "github.com/zegl/kube-score/domain" + "github.com/zegl/kube-score/parser" + "github.com/zegl/kube-score/renderer/human" + "github.com/zegl/kube-score/score" + "github.com/zegl/kube-score/score/checks" +) + +func main() { + js.Global().Set("handleScore", js.FuncOf(handleScore)) + select {} +} + +type inputReader struct { + *strings.Reader +} + +func (inputReader) Name() string { + return "input" +} + +func handleScore(this js.Value, inputs []js.Value) interface{} { + if len(inputs) == 0 { + fmt.Println("Unexpected number of arguments") + return "Unexpected number of arguments" + } + + fmt.Println(inputs[0].String()) + + reader := &inputReader{ + Reader: strings.NewReader(inputs[0].String()), + } + + files := []domain.NamedReader{reader} + + p, err := parser.New(&parser.Config{}) + if err != nil { + fmt.Println(err) + return string(err.Error()) + } + + allObjs, err := p.ParseFiles(files) + if err != nil { + fmt.Println(err) + return string(err.Error()) + } + + checksConfig := &checks.Config{} + runConfig := &config.RunConfiguration{} + + allChecks := score.RegisterAllChecks(allObjs, checksConfig, runConfig) + + card, err := score.Score(allObjs, allChecks, runConfig) + if err != nil { + fmt.Println(err) + return string(err.Error()) + } + + color.NoColor = false + output, err := human.Human(card, 0, 110, true) + if err != nil { + fmt.Println(err) + return string(err.Error()) + } + + body, err := io.ReadAll(output) + fmt.Println("body", body) + if err != nil { + fmt.Println(err) + return string(err.Error()) + } + + htmlBody := t2html.Render(body) + + return string(htmlBody) +} diff --git a/go.mod b/go.mod index f8481ce..2755883 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( ) require ( + github.com/buildkite/terminal-to-html v3.2.0+incompatible // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-logr/logr v1.4.1 // indirect github.com/gogo/protobuf v1.3.2 // indirect diff --git a/go.sum b/go.sum index c13b84f..d03f60c 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/buildkite/terminal-to-html v3.2.0+incompatible h1:WdXzl7ZmYzCAz4pElZosPaUlRTW+qwVx/SkQSCa1jXs= +github.com/buildkite/terminal-to-html v3.2.0+incompatible/go.mod h1:BFFdFecOxCgjdcarqI+8izs6v85CU/1RA/4Bqh4GR7E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/web/index.html b/web/index.html new file mode 100644 index 0000000..3b0ef93 --- /dev/null +++ b/web/index.html @@ -0,0 +1,1354 @@ + + + +
+ +Kubernetes object analysis with recommendations for improved reliability and security.
+kube-score
is a tool that does static code analysis of your Kubernetes object definitions. The
+ output is
+ a list of
+ recommendations of what you can improve to make your application more secure and resilient.
kube-score
is open-source and available under the
+ MIT-license. For more information about how to use kube-score, see zegl/kube-score on GitHub.
+ Use this website to easily test kube-score, just paste your object definition YAML or JSON in the box below.
+
+ + + + + + + + + + + + + + + + + +Paste an object in the box above to get started...