From c5777122db0cfdf1850c65e947c22205ebf7d42a Mon Sep 17 00:00:00 2001 From: Steve Cliff Date: Sat, 2 May 2026 13:08:23 +0100 Subject: [PATCH] Add-host: default repo username to hostname; always show htpasswd snippet MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pending page suppressed the htpasswd snippet when repo_username was blank — but with --private-repos the username is required for auth, and operators routinely leave the field blank assuming the system will pick something sensible. * handleUIAddHostPost defaults repo_username to the typed hostname when blank. Matches what --private-repos expects (URL path segment == username). * pending_host.html: snippet now renders whenever a password is present (always true after the generate-on-blank logic landed earlier). * Form help-text updated to describe the default explicitly. Co-Authored-By: Claude Opus 4.7 (1M context) --- internal/server/http/ui_handlers.go | 12 +++++++++++- web/templates/pages/add_host.html | 4 ++-- web/templates/pages/pending_host.html | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) 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}}