fix JSON error on details pages (#117)

* fix JSON error on details pages

* test HTTP requests to dashboard as part of CI
This commit is contained in:
Bobby Brennan
2019-05-20 11:04:59 -04:00
committed by GitHub
parent bfe388c41b
commit f29e79841a
4 changed files with 21 additions and 7 deletions

View File

@@ -37,6 +37,19 @@ references:
go test ./pkg/... -coverprofile=coverage.txt -covermode=count
bash <(curl -s https://codecov.io/bash)
test_dashboard: &test_dashboard
run:
name: Test Dashboard
command: |
go run main.go --dashboard --dashboard-port 3000 --audit-path ./deploy/dashboard.yaml &
sleep 5
curl -f http://localhost:3000 > /dev/null
curl -f http://localhost:3000/health > /dev/null
curl -f http://localhost:3000/favicon.ico > /dev/null
curl -f http://localhost:3000/static/css/main.css > /dev/null
curl -f http://localhost:3000/results.json > /dev/null
curl -f http://localhost:3000/details/security > /dev/null
jobs:
build:
docker:
@@ -58,6 +71,7 @@ jobs:
- run: go list ./... | grep -v vendor | xargs golint -set_exit_status
- run: go list ./... | grep -v vendor | xargs go vet
- *update_coverage
- *test_dashboard
test-deploy:
docker:

View File

@@ -89,19 +89,19 @@ func main() {
if *webhook {
startWebhookServer(c, *disableWebhookConfigInstaller, *webhookPort)
} else if *dashboard {
startDashboardServer(c, *dashboardPort)
startDashboardServer(c, *auditPath, *dashboardPort)
} else if *audit {
runAudit(c, *auditPath, *auditOutputFile, *auditOutputURL)
}
}
func startDashboardServer(c conf.Configuration, port int) {
func startDashboardServer(c conf.Configuration, auditPath string, port int) {
router := mux.NewRouter()
router.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("OK"))
})
router.HandleFunc("/results.json", func(w http.ResponseWriter, r *http.Request) {
k, err := kube.CreateResourceProvider("")
k, err := kube.CreateResourceProvider(auditPath)
if err != nil {
logrus.Errorf("Error fetching Kubernetes resources %v", err)
http.Error(w, "Error fetching Kubernetes resources", http.StatusInternalServerError)
@@ -124,7 +124,7 @@ func startDashboardServer(c conf.Configuration, port int) {
http.NotFound(w, r)
return
}
k, err := kube.CreateResourceProvider("")
k, err := kube.CreateResourceProvider(auditPath)
if err != nil {
logrus.Errorf("Error fetching Kubernetes resources %v", err)
http.Error(w, "Error fetching Kubernetes resources", http.StatusInternalServerError)

View File

@@ -14,8 +14,5 @@
<link rel="stylesheet" href="/static/css/dashboard.css">
<script type="text/javascript" src="/static/js/Chart-2.7.2.min.js"></script>
<script type="text/javascript" src="/static/js/cash-4.1.2.min.js"></script>
<script>
window.polarisAuditData = {{ .JSON }};
</script>
<script type="text/javascript" src="/static/js/main.js"></script>
{{ end }}

View File

@@ -2,6 +2,9 @@
<html>
<head>
<script>
window.polarisAuditData = {{ .JSON }};
</script>
{{ template "head" . }}
</head>