diff --git a/configuration/config.go b/configuration/config.go index 5787d0d661507f2fed91d3a664d86147f82d3892..be25fb69e12875962685a8388fb6ebdd2b97d3ab 100644 --- a/configuration/config.go +++ b/configuration/config.go @@ -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 }