1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-06-29 09:50:56 +02:00

Fix #7: make each module optional

This commit is contained in:
Alexandre Iooss
2020-10-09 22:06:30 +02:00
parent 99bfc5e109
commit 45c6b5dba5
9 changed files with 64 additions and 45 deletions

View File

@ -6,12 +6,12 @@ import (
"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 {
Enabled bool
Backend string
Basic basic.Options
LDAP ldap.Options
@ -25,14 +25,17 @@ type Backend interface {
// New initialize authentification backend
func New(cfg *Options) (Backend, error) {
var backend Backend
var backend Backend = nil
var err error
if !cfg.Enabled {
// Authentification is disabled
return nil, nil
}
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: