diff --git a/internal/server/http/ui_handlers.go b/internal/server/http/ui_handlers.go index 5afad0c..ee34408 100644 --- a/internal/server/http/ui_handlers.go +++ b/internal/server/http/ui_handlers.go @@ -370,8 +370,18 @@ func (s *Server) handleUIAddHostPost(w stdhttp.ResponseWriter, r *stdhttp.Reques } } + // Default repo username to the hostname when the operator left it + // blank. With rest-server's --private-repos this is what the URL + // path segment is expected to be anyway, and an htpasswd entry + // always needs *some* user — defaulting saves the operator from + // landing on a pending page with a half-formed snippet. + repoUsername := page.RepoUsername + if repoUsername == "" { + repoUsername = page.Hostname + } + if page.Error == "" { - token, _, err := s.mintEnrollmentToken(r.Context(), page.RepoURL, page.RepoUsername, repoPassword, splitPaths(page.Paths)) + token, _, err := s.mintEnrollmentToken(r.Context(), page.RepoURL, repoUsername, repoPassword, splitPaths(page.Paths)) switch err { case nil: stdhttp.Redirect(w, r, "/hosts/pending/"+token, stdhttp.StatusSeeOther) diff --git a/web/templates/pages/add_host.html b/web/templates/pages/add_host.html index 2876261..8a20cf3 100644 --- a/web/templates/pages/add_host.html +++ b/web/templates/pages/add_host.html @@ -58,9 +58,9 @@
Whatever restic -r would accept. Most fleets terminate at a restic/rest-server; s3: and b2: URLs work equally well.
- + -
For rest-server with htpasswd, this is the per-host user.
+
For rest-server with --private-repos, this is the per-host htpasswd user — and the URL path segment must match. Leave blank and we'll use the hostname above.
diff --git a/web/templates/pages/pending_host.html b/web/templates/pages/pending_host.html index 78d4d87..9c81215 100644 --- a/web/templates/pages/pending_host.html +++ b/web/templates/pages/pending_host.html @@ -27,7 +27,7 @@ the host detail.

- {{if and $page.RepoUsername $page.RepoPassword}} + {{if $page.RepoPassword}}