Merge branch 'main' of github.com:komodorio/helm-dashboard

This commit is contained in:
Andrei Pohilko
2022-10-26 08:59:09 +01:00
7 changed files with 123 additions and 1018 deletions

83
go.mod
View File

@@ -3,9 +3,9 @@ module github.com/komodorio/helm-dashboard
go 1.18
require (
github.com/aquasecurity/trivy v0.32.1
github.com/gin-gonic/gin v1.8.1
github.com/hexops/gotextdiff v1.0.3
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/sirupsen/logrus v1.9.0
github.com/toqueteos/webbrowser v1.2.0
gopkg.in/yaml.v3 v3.0.1
@@ -14,111 +14,32 @@ require (
)
require (
github.com/CycloneDX/cyclonedx-go v0.6.0 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/Masterminds/sprig/v3 v3.2.2 // indirect
github.com/Sirupsen/logrus v1.0.6 // indirect
github.com/aquasecurity/go-dep-parser v0.0.0-20220928105313-d3a51fe400e4 // indirect
github.com/aquasecurity/table v1.8.0 // indirect
github.com/aquasecurity/trivy-db v0.0.0-20220627104749-930461748b63 // indirect
github.com/aquasecurity/trivy-kubernetes v0.3.1-0.20220823151349-b90b48958b91 // indirect
github.com/caarlos0/env/v6 v6.10.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/docker/libnetwork v0.5.6 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-errors/errors v1.0.1 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.0 // indirect
github.com/goccy/go-json v0.9.11 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-containerregistry v0.11.0 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/in-toto/in-toto-golang v0.3.4-0.20220709202702-fa494aaa0add // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/knqyf263/go-rpm-version v0.0.0-20220614171824-631e686d1075 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/liamg/tml v0.6.0 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/owenrumney/go-sarif/v2 v2.1.2 // indirect
github.com/package-url/packageurl-go v0.1.1-0.20220203205134-d70459300c8a // indirect
github.com/pelletier/go-toml/v2 v2.0.3 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/samber/lo v1.27.1 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.4.0 // indirect
github.com/shibumi/go-pathspec v1.3.0 // indirect
github.com/shopspring/decimal v1.2.0 // indirect
github.com/spdx/tools-golang v0.3.0 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/cobra v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.4.0 // indirect
github.com/stretchr/testify v1.8.0 // indirect
github.com/ugorji/go/codec v1.2.7 // indirect
github.com/vishvananda/netlink v1.1.0 // indirect
github.com/vishvananda/netns v0.0.0-20220913150850-18c4f4234207 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.23.0 // indirect
golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8 // indirect
golang.org/x/exp v0.0.0-20220823124025-807a23277127 // indirect
golang.org/x/net v0.0.0-20220906165146-f3363e06e74c // indirect
golang.org/x/oauth2 v0.0.0-20220718184931-c8730f7fcb92 // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220818161305-2296e01440c6 // indirect
golang.org/x/term v0.0.0-20220526004731-065cf7ba2467 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/api v0.25.0-alpha.2 // indirect
k8s.io/cli-runtime v0.24.4 // indirect
k8s.io/client-go v0.25.0-alpha.2 // indirect
k8s.io/klog/v2 v2.70.0 // indirect
k8s.io/kube-openapi v0.0.0-20220627174259-011e075b9cb8 // indirect
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/kustomize/api v0.11.4 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)

933
go.sum

File diff suppressed because it is too large Load Diff

View File

@@ -3,8 +3,8 @@ package main
import (
"github.com/gin-gonic/gin"
"github.com/komodorio/helm-dashboard/pkg/dashboard"
"github.com/pkg/browser"
log "github.com/sirupsen/logrus"
"github.com/toqueteos/webbrowser"
"os"
)
@@ -26,7 +26,7 @@ func main() {
if os.Getenv("HD_NOBROWSER") == "" {
log.Infof("Opening web UI: %s", address)
err := webbrowser.Open(address)
err := browser.OpenURL(address)
if err != nil {
log.Warnf("Failed to open Web browser for URL: %s", err)
}

View File

@@ -248,11 +248,11 @@ func handleGetSection(data *subproc.DataLayer, section string, rDiff string, qp
return "", err
}
return res, nil
} else {
res, err := functor(qp.Namespace, qp.Name, qp.Revision, flag)
if err != nil {
return "", err
}
return res, nil
}
res, err := functor(qp.Namespace, qp.Name, qp.Revision, flag)
if err != nil {
return "", err
}
return res, nil
}

View File

@@ -44,6 +44,9 @@
</div>
</div>
<div id="toolVersion">
</div>
<div class="separator-vertical mx-3"><span></span></div>
<ul class="navbar-nav me-auto mb-2 mb-lg-0">

View File

@@ -21,6 +21,12 @@ $(function () {
$("#upgradeModal .btn-scan").hide()
}
})
$.get("/status").fail(function (xhr) {
reportError("Failed to get tool version", xhr)
}).done(function (data) {
fillToolVersion(data)
})
})
function initView() {
@@ -195,4 +201,8 @@ function isNewerVersion(oldVer, newVer) {
if (a < b) return false
}
return false
}
function fillToolVersion(data) {
$("#toolVersion").append($('<a>' + data + '</a>'))
}

View File

@@ -0,0 +1,96 @@
package utils
import (
"github.com/gin-gonic/gin"
"net/http/httptest"
"testing"
)
func TestGetQueryProps(t *testing.T) {
gin.SetMode(gin.TestMode)
tests := []struct {
name string
endpoint string
revRequired bool
wantErr bool
}{
{
name: "Get query props - all set with revRequired true",
wantErr: false,
revRequired: true,
endpoint: "/api/v1/namespaces/komodorio/charts?name=testing&namespace=testing&revision=1",
},
{
name: "Get query props - no revision with revRequired true",
wantErr: true,
revRequired: true,
endpoint: "/api/v1/namespaces/komodorio/charts?name=testing&namespace=testing",
},
{
name: "Get query props - no namespace with revRequired true",
wantErr: false,
revRequired: true,
endpoint: "/api/v1/namespaces/komodorio/charts?name=testing&revision=1",
},
{
name: "Get query props - no name with revRequired true",
wantErr: true,
revRequired: true,
endpoint: "/api/v1/namespaces/komodorio/charts?namespace=testing&revision=1",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
w := httptest.NewRecorder()
c, _ := gin.CreateTestContext(w)
c.Request = httptest.NewRequest("GET", tt.endpoint, nil)
_, err := GetQueryProps(c, tt.revRequired)
if (err != nil) != tt.wantErr {
t.Errorf("GetQueryProps() error = %v, wantErr %v", err, tt.wantErr)
return
}
})
}
}
func TestChartAndVersion(t *testing.T) {
tests := []struct {
name string
params string
wantChart string
wantVer string
wantError bool
}{
{
name: "Chart and version - successfully parsing chart and version",
params: "chart-1.0.0",
wantChart: "chart",
wantVer: "1.0.0",
wantError: false,
},
{
name: "Chart and version - parsing chart without version",
params: "chart",
wantError: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
a, b, err := ChartAndVersion(tt.params)
if (err != nil) != tt.wantError {
t.Errorf("ChartAndVersion() error = %v, wantErr %v", err, tt.wantError)
return
}
if a != tt.wantChart {
t.Errorf("ChartAndVersion() got = %v, want %v", a, tt.wantChart)
}
if b != tt.wantVer {
t.Errorf("ChartAndVersion() got1 = %v, want %v", b, tt.wantVer)
}
})
}
}