auth: add some more auth modes

Change-Id: I1674f5fff8a8ea3490f315844df68a474f8c6d5e
This commit is contained in:
Brad Fitzpatrick 2012-04-12 16:54:25 -07:00
parent 51c99e7d32
commit 93af191e77
1 changed files with 22 additions and 0 deletions

View File

@ -63,6 +63,10 @@ func FromConfig(authConfig string) (AuthMode, error) {
} }
switch authType { switch authType {
case "none":
return None{}, nil
case "localhost":
return Localhost{}, nil
case "userpass": case "userpass":
if len(pieces) < 3 { if len(pieces) < 3 {
return nil, fmt.Errorf("Wrong userpass auth string; needs to be \"userpass:user:password\"") return nil, fmt.Errorf("Wrong userpass auth string; needs to be \"userpass:user:password\"")
@ -129,6 +133,24 @@ func (up *UserPass) AddAuthHeader(req *http.Request) {
req.SetBasicAuth(up.Username, up.Password) req.SetBasicAuth(up.Username, up.Password)
} }
type None struct{}
func (None) IsAuthorized(req *http.Request) bool {
return true
}
type Localhost struct {
None
}
func (Localhost) IsAuthorized(req *http.Request) bool {
return localhostAuthorized(req)
}
func (None) AddAuthHeader(req *http.Request) {
// Nothing.
}
// DevAuth is used when the env var CAMLI_ADVERTISED_PASSWORD // DevAuth is used when the env var CAMLI_ADVERTISED_PASSWORD
// is defined // is defined
type DevAuth struct { type DevAuth struct {