command line args

This commit is contained in:
Chapuis Bertil
2015-09-07 15:29:24 +02:00
parent 436de7f687
commit 738e78c439
6 changed files with 110 additions and 74 deletions

13
auth.go
View File

@@ -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
}