1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-06-27 05:28:44 +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:

View File

@ -1,21 +0,0 @@
package bypass
// ByPass authentification backend
// By pass password check, open your streaming server to everyone!
type ByPass struct {
}
// Login always return success
func (a ByPass) Login(username string, password string) (bool, error) {
return true, nil
}
// Close has no connection to close
func (a ByPass) Close() {
}
// New instanciates a new Basic authentification backend
func New() (ByPass, error) {
backend := ByPass{}
return backend, nil
}

View File

@ -1,14 +0,0 @@
package bypass
import (
"testing"
)
func TestBypassLogin(t *testing.T) {
backend, _ := New()
ok, err := backend.Login("demo", "demo")
if !ok {
t.Error("Error while logging with the bypass authentication:", err)
}
backend.Close()
}