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

Database password is now read from file

Although, password file is checked during config validation, sth may have changed the
file content in the short period of time between validation and DB client initialization,
hence exiting in case of an error
parent 8aba7144
No related branches found
No related tags found
No related merge requests found
Pipeline #51896 passed
......@@ -5,6 +5,8 @@ import (
"runtime"
"context"
"time"
"os"
log "log/slog"
"webservice/configuration"
......@@ -21,11 +23,18 @@ type Persistent struct {
func NewPersistentStore( c *configuration.Config ) *Persistent {
content, err := os.ReadFile( c.DatabasePassword )
if err != nil {
log.Error( fmt.Sprintf( "Database password not able to be read: %v", err ) )
os.Exit( 1 )
}
dbPassword := string( content )
return &Persistent{
client: db.NewClient( &db.Options{
Addr: fmt.Sprintf( "%s:%d", c.DatabaseHost, c.DatabasePort ),
Username: c.DatabaseUsername,
Password: c.DatabasePassword,
Password: dbPassword,
DB: c.DatabaseName,
DialTimeout: time.Second * 3,
......
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