Skip to content

Commit

Permalink
fix: mysql support kbadmin (#8670)
Browse files Browse the repository at this point in the history
  • Loading branch information
xuriwuyun authored Dec 19, 2024
1 parent 93ac774 commit 6d112a4
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions pkg/lorry/engines/mysql/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,8 @@ func NewConfig(properties map[string]string) (*Config, error) {
config.URL = "root:@tcp(127.0.0.1:3306)/mysql?multiStatements=true"
}

if viper.IsSet(constant.KBEnvServiceUser) {
config.Username = viper.GetString(constant.KBEnvServiceUser)
} else if username, ok := properties["username"]; ok {
config.Username = username
}

if viper.IsSet(constant.KBEnvServicePassword) {
config.Password = viper.GetString(constant.KBEnvServicePassword)
}
config.Username = getUserName()
config.Password = getPassword()

if viper.IsSet(constant.KBEnvServicePort) {
config.port = viper.GetString(constant.KBEnvServicePort)
Expand Down Expand Up @@ -148,6 +141,28 @@ func NewConfig(properties map[string]string) (*Config, error) {
return config, nil
}

func getUserName() string {
if viper.IsSet("MYSQL_ADMIN_USER") {

Check failure on line 145 in pkg/lorry/engines/mysql/config.go

View workflow job for this annotation

GitHub Actions / push-pre-check (lint)

ifElseChain: rewrite if-else to switch statement (gocritic)

Check failure on line 145 in pkg/lorry/engines/mysql/config.go

View workflow job for this annotation

GitHub Actions / release-test (lint)

ifElseChain: rewrite if-else to switch statement (gocritic)
return viper.GetString("MYSQL_ADMIN_USER")
} else if viper.IsSet(constant.KBEnvServiceUser) {
return viper.GetString(constant.KBEnvServiceUser)
} else if viper.IsSet("MYSQL_ROOT_USER") {
return viper.GetString("MYSQL_ROOT_USER")
}
return ""
}

func getPassword() string {
if viper.IsSet("MYSQL_ADMIN_PASSWORD") {

Check failure on line 156 in pkg/lorry/engines/mysql/config.go

View workflow job for this annotation

GitHub Actions / push-pre-check (lint)

ifElseChain: rewrite if-else to switch statement (gocritic)

Check failure on line 156 in pkg/lorry/engines/mysql/config.go

View workflow job for this annotation

GitHub Actions / release-test (lint)

ifElseChain: rewrite if-else to switch statement (gocritic)
return viper.GetString("MYSQL_ADMIN_PASSWORD")
} else if viper.IsSet(constant.KBEnvServicePassword) {
return viper.GetString(constant.KBEnvServicePassword)
} else if viper.IsSet("MYSQL_ROOT_PASSWORD") {
return viper.GetString("MYSQL_ROOT_PASSWORD")
}
return ""
}

func (config *Config) GetLocalDBConn() (*sql.DB, error) {
mysqlConfig, err := mysql.ParseDSN(config.URL)
if err != nil {
Expand Down

0 comments on commit 6d112a4

Please sign in to comment.