Feature: Basic authentication support

This commit is contained in:
Ralph Slooten
2022-08-04 17:18:07 +12:00
parent 9a27f33079
commit 6fe1bdb579
7 changed files with 116 additions and 50 deletions
+17 -1
View File
@@ -3,6 +3,8 @@ package config
import (
"errors"
"regexp"
"github.com/tg123/go-htpasswd"
)
var (
@@ -21,13 +23,19 @@ var (
// VerboseLogging for console output
VerboseLogging = false
// NoLogging for testing
// NoLogging for tests
NoLogging = false
// SSLCert @TODO
SSLCert string
// SSLKey @TODO
SSLKey string
// AuthFile for basic authentication
AuthFile string
// Auth used for euthentication
Auth *htpasswd.File
)
// VerifyConfig wil do some basic checking
@@ -40,5 +48,13 @@ func VerifyConfig() error {
return errors.New("HTTP bind should be in the format of <ip>:<port>")
}
if AuthFile != "" {
a, err := htpasswd.New(AuthFile, htpasswd.DefaultSystems, nil)
if err != nil {
return err
}
Auth = a
}
return nil
}