fix: handle user parse errors correctly

This commit is contained in:
Stavros
2025-02-07 20:11:16 +02:00
parent d2ee382f92
commit e09f241364
2 changed files with 7 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
package cmd package cmd
import ( import (
"errors"
"os" "os"
"strings" "strings"
"time" "time"
@@ -54,8 +55,10 @@ var rootCmd = &cobra.Command{
log.Info().Msg("Parsing users") log.Info().Msg("Parsing users")
users, usersErr := utils.GetUsers(config.Users, config.UsersFile) users, usersErr := utils.GetUsers(config.Users, config.UsersFile)
if (len(users) == 0 || usersErr != nil) && !utils.OAuthConfigured(config) { HandleError(usersErr, "Failed to parse users")
log.Fatal().Err(usersErr).Msg("Failed to parse users")
if len(users) == 0 && !utils.OAuthConfigured(config) {
HandleError(errors.New("no users or OAuth configured"), "No users or OAuth configured")
} }
// Create oauth whitelist // Create oauth whitelist

View File

@@ -104,7 +104,7 @@ func GetUsers(conf string, file string) (types.Users, error) {
var users string var users string
if conf == "" && file == "" { if conf == "" && file == "" {
return types.Users{}, errors.New("no users provided") return types.Users{}, nil
} }
if conf != "" { if conf != "" {
@@ -128,7 +128,7 @@ func GetUsers(conf string, file string) (types.Users, error) {
} }
func OAuthConfigured(config types.Config) bool { func OAuthConfigured(config types.Config) bool {
return (config.GithubClientId != "" && config.GithubClientSecret != "") || (config.GoogleClientId != "" && config.GoogleClientSecret != "") || (config.GenericClientId != "" && config.GenericClientSecret != "") return (config.GithubClientId != "" && config.GithubClientSecret != "") || (config.GoogleClientId != "" && config.GoogleClientSecret != "") || (config.GenericClientId != "" && config.GenericClientSecret != "") || (config.TailscaleClientId != "" && config.TailscaleClientSecret != "")
} }
func GetTinyauthLabels(labels map[string]string) types.TinyauthLabels { func GetTinyauthLabels(labels map[string]string) types.TinyauthLabels {