mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2025-06-29 11:00:55 +02:00
Add basic and bypass auth methods
This commit is contained in:
28
auth/auth.go
28
auth/auth.go
@ -2,13 +2,18 @@ package auth
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"gitlab.crans.org/nounous/ghostream/auth/basic"
|
||||
"gitlab.crans.org/nounous/ghostream/auth/bypass"
|
||||
"gitlab.crans.org/nounous/ghostream/auth/ldap"
|
||||
)
|
||||
|
||||
// Options holds package configuration
|
||||
type Options struct {
|
||||
Backend string
|
||||
Basic basic.Options
|
||||
LDAP ldap.Options
|
||||
}
|
||||
|
||||
@ -23,16 +28,23 @@ func New(cfg *Options) (Backend, error) {
|
||||
var backend Backend
|
||||
var err error
|
||||
|
||||
if cfg.Backend == "LDAP" {
|
||||
backend, err = ldap.NewLDAP(&cfg.LDAP)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
switch strings.ToLower(cfg.Backend) {
|
||||
case "basic":
|
||||
backend, err = basic.New(&cfg.Basic)
|
||||
case "bypass":
|
||||
backend, err = bypass.New()
|
||||
case "ldap":
|
||||
backend, err = ldap.New(&cfg.LDAP)
|
||||
default:
|
||||
// Package is misconfigured
|
||||
return nil, errors.New("Authentification backend not found")
|
||||
backend, err = nil, errors.New("Authentification backend not found")
|
||||
}
|
||||
|
||||
// Init and return backend
|
||||
if err != nil {
|
||||
// Backend init failed
|
||||
return nil, err
|
||||
}
|
||||
|
||||
log.Printf("%s backend successfully initialized", cfg.Backend)
|
||||
return backend, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user