Skip to content

Commit

Permalink
Config: support custom htpasswd path
Browse files Browse the repository at this point in the history
  • Loading branch information
wojas committed Aug 9, 2021
1 parent 97e2a51 commit 383514a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,16 @@ func (s *Server) wrapMetricsAuth(f http.HandlerFunc) http.HandlerFunc {
func NewHandler(server *Server) (http.Handler, error) {
if !server.NoAuth {
var err error
server.htpasswdFile, err = NewHtpasswdFromFile(filepath.Join(server.Path, ".htpasswd"))
htpasswd := server.Config.Auth.HTPasswdFile
if htpasswd == "" {
htpasswd = ".htpasswd"
}
if !filepath.IsAbs(htpasswd) {
htpasswd = filepath.Join(server.Path, htpasswd)
}
server.htpasswdFile, err = NewHtpasswdFromFile(htpasswd)
if err != nil {
return nil, fmt.Errorf("cannot load .htpasswd (use --no-auth to disable): %v", err)
return nil, fmt.Errorf("cannot load htpasswd file (use --no-auth to disable): %s: %v", htpasswd, err)
}
}

Expand Down

0 comments on commit 383514a

Please sign in to comment.