Skip to content

Commit

Permalink
fix JSON error on details pages (#117)
Browse files Browse the repository at this point in the history
* fix JSON error on details pages

* test HTTP requests to dashboard as part of CI
  • Loading branch information
rbren authored May 20, 2019
1 parent bfe388c commit f29e798
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
14 changes: 14 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 0 additions & 3 deletions pkg/dashboard/templates/head.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
3 changes: 3 additions & 0 deletions pkg/dashboard/templates/main.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<html>

<head>
<script>
window.polarisAuditData = {{ .JSON }};
</script>
{{ template "head" . }}
</head>

Expand Down

0 comments on commit f29e798

Please sign in to comment.