mirror of
https://github.com/restic/rest-server.git
synced 2025-12-07 09:36:13 -08:00
command line args
This commit is contained in:
13
auth.go
13
auth.go
@@ -6,14 +6,25 @@ import (
|
||||
)
|
||||
|
||||
func Authorize(r *http.Request) error {
|
||||
|
||||
htpasswd, err := NewHtpasswdFromFile("/tmp/restic/.htpasswd")
|
||||
if err != nil {
|
||||
return errors.New("internal server error")
|
||||
}
|
||||
|
||||
username, password, ok := r.BasicAuth()
|
||||
if !ok {
|
||||
return errors.New("malformed basic auth credentials")
|
||||
}
|
||||
|
||||
if username != "user" || password != "pass" {
|
||||
if !htpasswd.Validate(username, password) {
|
||||
return errors.New("unknown user")
|
||||
}
|
||||
|
||||
repo, err := RepositoryName(r.RequestURI)
|
||||
if err != nil || repo != username {
|
||||
return errors.New("wrong repository")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user