mirror of
https://github.com/restic/rest-server.git
synced 2025-12-07 09:36:13 -08:00
Make Server use the new repo.Handler
This contains all the glue to make Server use the new repo.Handler: - Remove all old handlers - Add ServeHTTP to make Server a single http.Handler - Remove Goji routing and replace by net/http and custom routing logic Additionally, this implements two-level backup repositories.
This commit is contained in:
committed by
Alexander Neumann
parent
55e549e92c
commit
1f593fafaf
@@ -75,21 +75,6 @@ func tlsSettings() (bool, string, string, error) {
|
||||
return server.TLS, key, cert, nil
|
||||
}
|
||||
|
||||
func getHandler(server restserver.Server) (http.Handler, error) {
|
||||
mux := restserver.NewHandler(server)
|
||||
if server.NoAuth {
|
||||
log.Println("Authentication disabled")
|
||||
return mux, nil
|
||||
}
|
||||
|
||||
log.Println("Authentication enabled")
|
||||
htpasswdFile, err := restserver.NewHtpasswdFromFile(filepath.Join(server.Path, ".htpasswd"))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot load .htpasswd (use --no-auth to disable): %v", err)
|
||||
}
|
||||
return server.AuthHandler(htpasswdFile, mux), nil
|
||||
}
|
||||
|
||||
func runRoot(cmd *cobra.Command, args []string) error {
|
||||
if showVersion {
|
||||
fmt.Printf("rest-server %s compiled with %v on %v/%v\n", version, runtime.Version(), runtime.GOOS, runtime.GOARCH)
|
||||
@@ -112,7 +97,13 @@ func runRoot(cmd *cobra.Command, args []string) error {
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
|
||||
handler, err := getHandler(server)
|
||||
if server.NoAuth {
|
||||
log.Println("Authentication disabled")
|
||||
} else {
|
||||
log.Println("Authentication enabled")
|
||||
}
|
||||
|
||||
handler, err := restserver.NewHandler(&server)
|
||||
if err != nil {
|
||||
log.Fatalf("error: %v", err)
|
||||
}
|
||||
|
||||
@@ -86,14 +86,16 @@ func TestGetHandler(t *testing.T) {
|
||||
}
|
||||
}()
|
||||
|
||||
getHandler := restserver.NewHandler
|
||||
|
||||
// With NoAuth = false and no .htpasswd
|
||||
_, err = getHandler(restserver.Server{Path: dir})
|
||||
_, err = getHandler(&restserver.Server{Path: dir})
|
||||
if err == nil {
|
||||
t.Errorf("NoAuth=false: expected error, got nil")
|
||||
}
|
||||
|
||||
// With NoAuth = true and no .htpasswd
|
||||
_, err = getHandler(restserver.Server{NoAuth: true, Path: dir})
|
||||
_, err = getHandler(&restserver.Server{NoAuth: true, Path: dir})
|
||||
if err != nil {
|
||||
t.Errorf("NoAuth=true: expected no error, got %v", err)
|
||||
}
|
||||
@@ -112,7 +114,7 @@ func TestGetHandler(t *testing.T) {
|
||||
}()
|
||||
|
||||
// With NoAuth = false and with .htpasswd
|
||||
_, err = getHandler(restserver.Server{Path: dir})
|
||||
_, err = getHandler(&restserver.Server{Path: dir})
|
||||
if err != nil {
|
||||
t.Errorf("NoAuth=false with .htpasswd: expected no error, got %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user