Skip to content

Commit

Permalink
chore: update sm format (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing authored Nov 14, 2023
1 parent 998a310 commit 39cdae4
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ func ParseServerConfigFromFile(filePath string) *ServerConfig {
panic(err)
}

if config.DBConfig.Password == "" { // read password from AWS secret
config.DBConfig.Password = GetDBPass(config.DBConfig)
if config.DBConfig.Username == "" || config.DBConfig.Password == "" { // read password from AWS secret
config.DBConfig.Username, config.DBConfig.Password = GetDBUsernamePassword(config.DBConfig)
}

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

if config.DBConfig.Password == "" { // read password from AWS secret
config.DBConfig.Password = GetDBPass(config.DBConfig)
if config.DBConfig.Username == "" || config.DBConfig.Password == "" { // read password from AWS secret
config.DBConfig.Username, config.DBConfig.Password = GetDBUsernamePassword(config.DBConfig)
}

return &config
}

func GetDBPass(cfg *DBConfig) string {
func GetDBUsernamePassword(cfg *DBConfig) (string, string) {
result, err := GetSecret(cfg.AWSSecretName, cfg.AWSRegion)
if err != nil {
panic(err)
}
type DBPass struct {
DbPass string `json:"db_pass"`
Username string `json:"username"`
Password string `json:"password"`
}
var dbPassword DBPass
err = json.Unmarshal([]byte(result), &dbPassword)
if err != nil {
panic(err)
}
return dbPassword.DbPass
return dbPassword.Username, dbPassword.Password
}

0 comments on commit 39cdae4

Please sign in to comment.