mirror of
https://github.com/restic/rest-server.git
synced 2025-10-19 07:33:21 +00:00
28 lines
440 B
Go
28 lines
440 B
Go
package main
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
)
|
|
|
|
func Authorize(r *http.Request) error {
|
|
username, password, ok := r.BasicAuth()
|
|
if !ok {
|
|
return errors.New("malformed basic auth credentials")
|
|
}
|
|
|
|
repo, err := RepositoryName(r.RequestURI)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if username != "user" || password != "pass" {
|
|
return errors.New("unknown user")
|
|
}
|
|
|
|
if username != repo {
|
|
return errors.New("unauthorized")
|
|
}
|
|
|
|
return nil
|
|
}
|