1package auth
2
3import (
4	"fmt"
5	"net/http"
6
7	"github.com/fabiolb/fabio/config"
8)
9
10type AuthScheme interface {
11	Authorized(request *http.Request, response http.ResponseWriter) bool
12}
13
14func LoadAuthSchemes(cfg map[string]config.AuthScheme) (map[string]AuthScheme, error) {
15	auths := map[string]AuthScheme{}
16	for _, a := range cfg {
17		switch a.Type {
18		case "basic":
19			b, err := newBasicAuth(a.Basic)
20			if err != nil {
21				return nil, err
22			}
23			auths[a.Name] = b
24		default:
25			return nil, fmt.Errorf("unknown auth type '%s'", a.Type)
26		}
27	}
28
29	return auths, nil
30}
31