snap/auth/auth.go

36 lines
624 B
Go
Raw Permalink Normal View History

2018-01-24 02:26:26 +00:00
package auth
2018-02-07 22:25:00 +00:00
import (
"net/http"
)
2018-01-24 02:26:26 +00:00
type AuthData struct {
2021-05-29 21:14:15 +00:00
User string
Group string
Properties map[string]string
2023-08-18 03:30:47 +00:00
KVs map[string]interface{}
}
2018-01-24 02:26:26 +00:00
type AuthManager interface {
AddUser(user string, group string, password string) error
DeleteUser(user string) error
DoAuth(w http.ResponseWriter, r *http.Request) (*AuthData, int)
2018-01-24 02:26:26 +00:00
}
2021-01-19 03:02:59 +00:00
type Authenticator interface {
DoAuth(w http.ResponseWriter, r *http.Request) (*AuthData, int)
2021-01-19 03:02:59 +00:00
}
func NewAuth(kind string) AuthManager {
switch kind {
case "basic":
return NewBasicAuth()
case "token":
return NewTokenAuth()
default:
return NewNoAuth()
}
2021-01-19 03:23:52 +00:00
}