Skip to content

Commit

Permalink
chore: allow read db password from env (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing authored Dec 8, 2023
1 parent 64b9fcc commit 702b18b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,11 @@ func ParseServerConfigFromFile(filePath string) *ServerConfig {
panic(err)
}

if config.DBConfig.Username == "" || config.DBConfig.Password == "" { // read password from ENV
config.DBConfig.Username, config.DBConfig.Password = GetDBUsernamePasswordFromEnv()
}
if config.DBConfig.Username == "" || config.DBConfig.Password == "" { // read password from AWS secret
config.DBConfig.Username, config.DBConfig.Password = GetDBUsernamePassword(config.DBConfig)
config.DBConfig.Username, config.DBConfig.Password = GetDBUsernamePasswordFromSM(config.DBConfig) // get from env
}

return &config
Expand Down Expand Up @@ -87,14 +90,23 @@ func ParseMonitorConfigFromFile(filePath string) *MonitorConfig {
panic(err)
}

if config.DBConfig.Username == "" || config.DBConfig.Password == "" { // read password from ENV
config.DBConfig.Username, config.DBConfig.Password = GetDBUsernamePasswordFromEnv()
}
if config.DBConfig.Username == "" || config.DBConfig.Password == "" { // read password from AWS secret
config.DBConfig.Username, config.DBConfig.Password = GetDBUsernamePassword(config.DBConfig)
config.DBConfig.Username, config.DBConfig.Password = GetDBUsernamePasswordFromSM(config.DBConfig) // get from env
}

return &config
}

func GetDBUsernamePassword(cfg *DBConfig) (string, string) {
func GetDBUsernamePasswordFromEnv() (string, string) {
username := os.Getenv("DB_USERNAME")
password := os.Getenv("DB_PASSWORD")
return username, password
}

func GetDBUsernamePasswordFromSM(cfg *DBConfig) (string, string) {
result, err := GetSecret(cfg.AWSSecretName, cfg.AWSRegion)
if err != nil {
panic(err)
Expand Down

0 comments on commit 702b18b

Please sign in to comment.