Skip to content

Commit

Permalink
Include depproxy version in dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
AGWA committed Mar 30, 2024
1 parent 66bd981 commit 5e6fcc2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
17 changes: 14 additions & 3 deletions internal/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,19 @@ import (
"html/template"
"io"
"net/http"
"runtime/debug"

"golang.org/x/sync/errgroup"
"src.agwa.name/depproxy/internal/goproxy"
)

var dashboardTemplate = template.Must(template.ParseFS(content, "templates/dashboard.html"))

type dashboard struct {
Modules []allowedModuleInfo
BuildInfo *debug.BuildInfo
}

type allowedModuleInfo struct {
AllowedModule
CurrentInfo *goproxy.ModuleInfo
Expand Down Expand Up @@ -137,14 +143,19 @@ func (s *Server) serveDashboard(w http.ResponseWriter, req *http.Request) {
http.Error(w, "Invalid request", http.StatusBadRequest)
return
}
modules, err := s.getAllowedModulesInfo(req.Context())
if err != nil {

var dash dashboard
dash.BuildInfo, _ = debug.ReadBuildInfo()
if modules, err := s.getAllowedModulesInfo(req.Context()); err != nil {
http.Error(w, fmt.Sprintf("error getting allowed modules info: %s", err), http.StatusInternalServerError)
return
} else {
dash.Modules = modules
}

w.Header().Set("Content-Type", "text/html")
w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("X-Xss-Protection", "0")
w.WriteHeader(http.StatusOK)
dashboardTemplate.Execute(w, modules)
dashboardTemplate.Execute(w, dash)
}
8 changes: 7 additions & 1 deletion internal/templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
.outofdate {
background: #fde;
}
.buildinfo {
font-style: italic;
}
</style>
</head>
<body>
Expand All @@ -29,7 +32,7 @@ <h1>Go Dependency Proxy</h1>
<tr><th>Module</th><th>Allowed</th><th>Latest</th><th>Diff</th></tr>
</thead>
<tbody>
{{ range . }}
{{ range .Modules }}
<tr class="{{ if .OutOfDate }}outofdate{{ end }}">
<td>
{{- if .Path.IsSet -}}
Expand Down Expand Up @@ -65,5 +68,8 @@ <h1>Go Dependency Proxy</h1>
{{ end }}
</tbody>
</table>
{{ if .BuildInfo }}
<p class="buildinfo">{{ .BuildInfo.Main.Path }}@{{ .BuildInfo.Main.Version }} ({{ .BuildInfo.Main.Sum }})</p>
{{ end }}
</body>
</html>

0 comments on commit 5e6fcc2

Please sign in to comment.