mirror of
https://github.com/amir20/dozzle.git
synced 2025-12-21 13:23:07 +01:00
feat: Add support for both .yml and .yaml files and prioritize .yml for users file (#3789)
This commit is contained in:
@@ -10,7 +10,11 @@ If you do not have an authentication solution, then Dozzle has a simple file-bas
|
||||
|
||||
## File-Based User Management
|
||||
|
||||
Dozzle supports multi-user authentication by setting `--auth-provider` to `simple`. In this mode, Dozzle will try to read `/data/users.yml`.
|
||||
**Dozzle** supports multi-user authentication by setting `--auth-provider` to `simple`. In this mode, Dozzle will attempt to read the users file from `/data/`, prioritizing `users.yml` over `users.yaml` if both files are present. If only one of the files exists, it will be used. The log will indicate which file is being read (e.g., `Reading users.yml file`).
|
||||
|
||||
### Example file paths:
|
||||
- `/data/users.yml`
|
||||
- `/data/users.yaml`
|
||||
|
||||
The content of the file looks like:
|
||||
|
||||
|
||||
24
main.go
24
main.go
@@ -129,6 +129,14 @@ func main() {
|
||||
log.Debug().Msg("shut down complete")
|
||||
}
|
||||
|
||||
func fileExists(filename string) bool {
|
||||
_, err := os.Stat(filename)
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return err == nil
|
||||
}
|
||||
|
||||
func createServer(args cli.Args, hostService web.HostService) *http.Server {
|
||||
_, dev := os.LookupEnv("DEV")
|
||||
|
||||
@@ -142,19 +150,19 @@ func createServer(args cli.Args, hostService web.HostService) *http.Server {
|
||||
log.Debug().Msg("Using simple authentication")
|
||||
provider = web.SIMPLE
|
||||
|
||||
path, err := filepath.Abs("./data/users.yml")
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Could not get absolute path")
|
||||
userFilePath := "./data/users.yml"
|
||||
if !fileExists(userFilePath) {
|
||||
userFilePath = "./data/users.yaml"
|
||||
if !fileExists(userFilePath) {
|
||||
log.Fatal().Msg("No users.yaml or users.yml file found.")
|
||||
}
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
log.Fatal().Msg("users.yml file does not exist")
|
||||
}
|
||||
|
||||
log.Debug().Str("path", path).Msg("Reading users.yml file")
|
||||
log.Debug().Msgf("Reading %s file", filepath.Base(userFilePath))
|
||||
|
||||
db, err := auth.ReadUsersFromFile(path)
|
||||
db, err := auth.ReadUsersFromFile(userFilePath)
|
||||
if err != nil {
|
||||
log.Fatal().Err(err).Msg("Could not read users.yml file")
|
||||
log.Fatal().Err(err).Msgf("Could not read users file: %s", userFilePath)
|
||||
}
|
||||
|
||||
log.Debug().Int("users", len(db.Users)).Msg("Loaded users")
|
||||
|
||||
Reference in New Issue
Block a user