Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add token entry/storage functionality to test console #7

Merged
merged 21 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
MODULE_NAME := $(shell go list -m)
MODULE_NAME := scrape
ifneq ($(shell command -v go >/dev/null 2>&1 && echo yes),)
MODULE_NAME := $(shell go list -m)
endif
DOCKER_IMAGE_NAME := ${shell basename ${MODULE_NAME}}-bookworm-slim
CWD := $(shell pwd)
BUILD_DIR := build
Expand Down
13 changes: 9 additions & 4 deletions internal/server/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,10 @@ var home embed.FS

func (h scrapeServer) mustHomeTemplate() *template.Template {
tmpl := template.New("home")
var keyF = func() string { return "" }
if len(h.SigningKey) > 0 {
keyF = func() string {
var authTokenF = func() string { return "" }
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just renamed this to make it a little more descriptive.

var authEnabledF = func() bool { return len(h.SigningKey) > 0 }
if authEnabledF() {
authTokenF = func() string {
c, err := auth.NewClaims(
auth.WithSubject("home"),
auth.ExpiresIn(60*time.Minute),
Expand All @@ -126,7 +127,11 @@ func (h scrapeServer) mustHomeTemplate() *template.Template {
return s
}
}
tmpl = tmpl.Funcs(template.FuncMap{"AuthToken": keyF})
funcMap := template.FuncMap{
"AuthToken": authTokenF,
"AuthEnabled": authEnabledF,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds the hook so we can skip the token entry widget when auth is not enabled

}
tmpl = tmpl.Funcs(funcMap)
homeSource, _ := home.ReadFile("templates/index.html")
tmpl = template.Must(tmpl.Parse(string(homeSource)))
return tmpl
Expand Down
Loading