provider: support for username and password file (#1455)

Signed-off-by: patrickap <patrick.schlageter@web.de>
This commit is contained in:
patrickap 2023-11-24 20:28:51 +01:00 committed by GitHub
parent 62854e4802
commit a91cf22e0f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View file

@ -327,7 +327,9 @@ func Init() {
Host: "", Host: "",
Port: 0, Port: 0,
Username: "", Username: "",
UsernameFile: "",
Password: "", Password: "",
PasswordFile: "",
ConnectionString: "", ConnectionString: "",
SQLTablesPrefix: "", SQLTablesPrefix: "",
SSLMode: 0, SSLMode: 0,
@ -2067,7 +2069,9 @@ func setViperDefaults() {
viper.SetDefault("data_provider.host", globalConf.ProviderConf.Host) viper.SetDefault("data_provider.host", globalConf.ProviderConf.Host)
viper.SetDefault("data_provider.port", globalConf.ProviderConf.Port) viper.SetDefault("data_provider.port", globalConf.ProviderConf.Port)
viper.SetDefault("data_provider.username", globalConf.ProviderConf.Username) viper.SetDefault("data_provider.username", globalConf.ProviderConf.Username)
viper.SetDefault("data_provider.username_file", globalConf.ProviderConf.UsernameFile)
viper.SetDefault("data_provider.password", globalConf.ProviderConf.Password) viper.SetDefault("data_provider.password", globalConf.ProviderConf.Password)
viper.SetDefault("data_provider.password_file", globalConf.ProviderConf.PasswordFile)
viper.SetDefault("data_provider.sslmode", globalConf.ProviderConf.SSLMode) viper.SetDefault("data_provider.sslmode", globalConf.ProviderConf.SSLMode)
viper.SetDefault("data_provider.disable_sni", globalConf.ProviderConf.DisableSNI) viper.SetDefault("data_provider.disable_sni", globalConf.ProviderConf.DisableSNI)
viper.SetDefault("data_provider.target_session_attrs", globalConf.ProviderConf.TargetSessionAttrs) viper.SetDefault("data_provider.target_session_attrs", globalConf.ProviderConf.TargetSessionAttrs)

View file

@ -355,8 +355,10 @@ type Config struct {
Port int `json:"port" mapstructure:"port"` Port int `json:"port" mapstructure:"port"`
// Database username // Database username
Username string `json:"username" mapstructure:"username"` Username string `json:"username" mapstructure:"username"`
UsernameFile string `json:"username_file" mapstructure:"username_file"`
// Database password // Database password
Password string `json:"password" mapstructure:"password"` Password string `json:"password" mapstructure:"password"`
PasswordFile string `json:"password_file" mapstructure:"password_file"`
// Used for drivers mysql and postgresql. // Used for drivers mysql and postgresql.
// 0 disable SSL/TLS connections. // 0 disable SSL/TLS connections.
// 1 require ssl. // 1 require ssl.
@ -875,6 +877,22 @@ func Initialize(cnf Config, basePath string, checkAdmins bool) error {
config.Actions.ExecuteOn = util.RemoveDuplicates(config.Actions.ExecuteOn, true) config.Actions.ExecuteOn = util.RemoveDuplicates(config.Actions.ExecuteOn, true)
config.Actions.ExecuteFor = util.RemoveDuplicates(config.Actions.ExecuteFor, true) config.Actions.ExecuteFor = util.RemoveDuplicates(config.Actions.ExecuteFor, true)
if config.Username == "" && config.UsernameFile != "" {
user, err := os.ReadFile(config.UsernameFile)
if err != nil {
return err
}
config.Username = string(user)
}
if config.Password == "" && config.PasswordFile != "" {
password, err := os.ReadFile(config.PasswordFile)
if err != nil {
return err
}
config.Password = string(password)
}
cnf.BackupsPath = getConfigPath(cnf.BackupsPath, basePath) cnf.BackupsPath = getConfigPath(cnf.BackupsPath, basePath)
if cnf.BackupsPath == "" { if cnf.BackupsPath == "" {
return fmt.Errorf("required directory is invalid, backup path %q", cnf.BackupsPath) return fmt.Errorf("required directory is invalid, backup path %q", cnf.BackupsPath)