Skip to content
Snippets Groups Projects
Commit 2fc512d1 authored by gjahn's avatar gjahn
Browse files

Database password must be a file path

parent 1cfe05ff
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,8 @@ package configuration
import (
"errors"
"fmt"
"os"
fp "path/filepath"
configParser "github.com/caarlos0/env/v9"
)
......@@ -60,5 +62,25 @@ func New() ( *Config, error ){
}
if len( cfg.DatabaseHost ) >= 1 && len( cfg.DatabasePassword ) >= 2 {
if ! fp.IsLocal( cfg.DatabasePassword ) && ! fp.IsAbs( cfg.DatabasePassword ) {
return nil, errors.New(
fmt.Sprintln( "Database password must be a file path" ),
)
}
_, err := os.Stat( cfg.DatabasePassword )
if err != nil {
if errors.Is( err, os.ErrNotExist ){
return nil, errors.New(
fmt.Sprintln( "Database password file does not exist" ),
)
}
return nil, errors.New(
fmt.Sprintln( "Database password file not accessible" ),
)
}
}
return &cfg, nil
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment