mirror of
				https://gitlab.crans.org/nounous/ghostream.git
				synced 2025-11-04 15:42:26 +01:00 
			
		
		
		
	Fix #7: make each module optional
This commit is contained in:
		
							
								
								
									
										11
									
								
								auth/auth.go
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								auth/auth.go
									
									
									
									
									
								
							@@ -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:
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
}
 | 
			
		||||
@@ -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()
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user