summaryrefslogtreecommitdiff
path: root/cmd/authelia
diff options
context:
space:
mode:
authorAmir Zarrinkafsh <nightah@me.com>2021-01-17 10:23:35 +1100
committerGitHub <noreply@github.com>2021-01-17 10:23:35 +1100
commit296efe2b32d2d99b9f689698ae80bba181a0fe77 (patch)
tree34f32ee6fd0b8b7d1c092d89cbf09917ab02f6a3 /cmd/authelia
parent8bab8d47ef1d49c5a5442ef1d84df767a4a8e786 (diff)
[MISC] Add missing CLI suite test (#1607)
* [MISC] Add missing CLI suite test * Add missing test for `authelia version` command in CLI suite. * Standardise logger calls and swap CSP switch order
Diffstat (limited to 'cmd/authelia')
-rw-r--r--cmd/authelia/main.go28
1 files changed, 15 insertions, 13 deletions
diff --git a/cmd/authelia/main.go b/cmd/authelia/main.go
index 63e8f845c..1bb57dc35 100644
--- a/cmd/authelia/main.go
+++ b/cmd/authelia/main.go
@@ -25,11 +25,12 @@ var configPathFlag string
//nolint:gocyclo // TODO: Consider refactoring/simplifying, time permitting.
func startServer() {
+ logger := logging.Logger()
config, errs := configuration.Read(configPathFlag)
if len(errs) > 0 {
for _, err := range errs {
- logging.Logger().Error(err)
+ logger.Error(err)
}
os.Exit(1)
@@ -38,7 +39,7 @@ func startServer() {
autheliaCertPool, errs, nonFatalErrs := utils.NewX509CertPool(config.CertificatesDirectory, config)
if len(errs) > 0 {
for _, err := range errs {
- logging.Logger().Error(err)
+ logger.Error(err)
}
os.Exit(2)
@@ -46,28 +47,28 @@ func startServer() {
if len(nonFatalErrs) > 0 {
for _, err := range nonFatalErrs {
- logging.Logger().Warn(err)
+ logger.Warn(err)
}
}
if err := logging.InitializeLogger(config.LogFormat, config.LogFilePath); err != nil {
- logging.Logger().Fatalf("Cannot initialize logger: %v", err)
+ logger.Fatalf("Cannot initialize logger: %v", err)
}
switch config.LogLevel {
case "info":
- logging.Logger().Info("Logging severity set to info")
+ logger.Info("Logging severity set to info")
logging.SetLevel(logrus.InfoLevel)
case "debug":
- logging.Logger().Info("Logging severity set to debug")
+ logger.Info("Logging severity set to debug")
logging.SetLevel(logrus.DebugLevel)
case "trace":
- logging.Logger().Info("Logging severity set to trace")
+ logger.Info("Logging severity set to trace")
logging.SetLevel(logrus.TraceLevel)
}
if os.Getenv("ENVIRONMENT") == "dev" {
- logging.Logger().Info("===> Authelia is running in development mode. <===")
+ logger.Info("===> Authelia is running in development mode. <===")
}
var storageProvider storage.Provider
@@ -80,7 +81,7 @@ func startServer() {
case config.Storage.Local != nil:
storageProvider = storage.NewSQLiteProvider(config.Storage.Local.Path)
default:
- logging.Logger().Fatalf("Unrecognized storage backend")
+ logger.Fatalf("Unrecognized storage backend")
}
var userProvider authentication.UserProvider
@@ -91,7 +92,7 @@ func startServer() {
case config.AuthenticationBackend.Ldap != nil:
userProvider = authentication.NewLDAPUserProvider(*config.AuthenticationBackend.Ldap, autheliaCertPool)
default:
- logging.Logger().Fatalf("Unrecognized authentication backend")
+ logger.Fatalf("Unrecognized authentication backend")
}
var notifier notification.Notifier
@@ -102,13 +103,13 @@ func startServer() {
case config.Notifier.FileSystem != nil:
notifier = notification.NewFileNotifier(*config.Notifier.FileSystem)
default:
- logging.Logger().Fatalf("Unrecognized notifier")
+ logger.Fatalf("Unrecognized notifier")
}
if !config.Notifier.DisableStartupCheck {
_, err := notifier.StartupCheck()
if err != nil {
- logging.Logger().Fatalf("Error during notifier startup check: %s", err)
+ logger.Fatalf("Error during notifier startup check: %s", err)
}
}
@@ -129,6 +130,7 @@ func startServer() {
}
func main() {
+ logger := logging.Logger()
rootCmd := &cobra.Command{
Use: "authelia",
Run: func(cmd *cobra.Command, args []string) {
@@ -150,6 +152,6 @@ func main() {
commands.ValidateConfigCmd, commands.CertificatesCmd)
if err := rootCmd.Execute(); err != nil {
- logging.Logger().Fatal(err)
+ logger.Fatal(err)
}
}