Unverified Commit c373715b authored by Sebastian Schüpbach's avatar Sebastian Schüpbach
Browse files

print error msg if envvars for db access are not found



Signed-off-by: Sebastian Schüpbach's avatarSebastian Schüpbach <sebastian.schuepbach@unibas.ch>
parent 29b8f6ae
Pipeline #24596 passed with stages
in 3 minutes and 11 seconds
......@@ -95,19 +95,42 @@ func LoadConfig(filepath string) Config {
log.Fatalln("Error on loading config: ", err)
}
dsn := os.Getenv("DSN")
if dsn != "" {
dsn, exists := os.LookupEnv("DSN")
if exists {
conf.ResolverDBMySQL.Dsn = dsn
// removed because of security issues with password in logfile
//log.Printf("DSN from Environment: [%s]", conf.ResolverDBMySQL.Dsn)
} else {
conf.ResolverDBMySQL.Dsn = fmt.Sprintf("%s:%s@tcp(%s:%s)/%s",
os.Getenv("MARIADB_USER"),
os.Getenv("MARIADB_PASSWORD"),
os.Getenv("MARIADB_HOST"),
os.Getenv("MARIADB_PORT"),
os.Getenv("MARIADB_DATABASE"))
mariadb_user, exists := os.LookupEnv("MARIADB_USER")
if !exists {
log.Fatalln("No Mariadb user defined!")
}
mariadb_password, exists := os.LookupEnv("MARIADB_PASSWORD")
if !exists {
log.Fatalln("No Mariadb password defined!")
}
mariadb_host, exists := os.LookupEnv("MARIADB_HOST")
if !exists {
log.Fatalln("No Mariadb host defined!")
}
mariadb_port, exists := os.LookupEnv("MARIADB_PORT")
if !exists {
log.Fatalln("No Mariadb port defined!")
}
mariadb_database, exists := os.LookupEnv("MARIADB_DATABASE")
if !exists {
log.Fatalln("No Mariadb database defined!")
}
conf.ResolverDBMySQL.Dsn = fmt.Sprintf(
"%s:%s@tcp(%s:%s)/%s",
mariadb_user,
mariadb_password,
mariadb_host,
mariadb_port,
mariadb_database,
)
// removed because of security issues with password in logfile
//log.Printf("DSN from Config: [%s]", conf.ResolverDBMySQL.Dsn)
log.Printf("DSN from Config: [%s]", conf.ResolverDBMySQL.Dsn)
}
return conf
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment