From af1447d5c031ea0d727f12aa87d0d011c9e803d9 Mon Sep 17 00:00:00 2001 From: Dmitry Kochetov Date: Tue, 4 Jun 2024 12:50:59 +0300 Subject: [PATCH] added support ssl mode --- config/config.go | 4 +--- main.go | 11 ++++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/config/config.go b/config/config.go index 04b51aa..69c0c80 100644 --- a/config/config.go +++ b/config/config.go @@ -29,6 +29,7 @@ type Config struct { MysqlUser string `hcl:"mysql_user"` MysqlHost string `hcl:"mysql_host"` MysqlPort string `hcl:"mysql_port"` + MysqlSslMode bool `hcl:"mysql_ssl_mode"` CommandRestartService string `hcl:"mysql_restart_service"` MysqlConfDir string `hcl:"mysql_cnf_dir"` ReleemConfDir string `hcl:"releem_cnf_dir"` @@ -52,9 +53,6 @@ func LoadConfig(filename string, logger logging.Logger) (*Config, error) { } func LoadConfigFromString(data string, logger logging.Logger) (*Config, error) { - if logger == nil { - logger = logging.NewSimpleLogger("config") - } config := &Config{} err := hcl.Decode(&config, data) if err != nil { diff --git a/main.go b/main.go index 5eda73f..3a473a2 100644 --- a/main.go +++ b/main.go @@ -160,14 +160,19 @@ func (service *Service) Manage(logger logging.Logger, configFile string, command // Init connection DB var db *sql.DB - var TypeConnection string + var TypeConnection, MysqlSslMode string + if configuration.MysqlSslMode { + MysqlSslMode = "?tls=skip-verify" + } else { + MysqlSslMode = "" + } if IsPath(configuration.MysqlHost, logger) { - db, err = sql.Open("mysql", configuration.MysqlUser+":"+configuration.MysqlPassword+"@unix("+configuration.MysqlHost+")/mysql") + db, err = sql.Open("mysql", configuration.MysqlUser+":"+configuration.MysqlPassword+"@unix("+configuration.MysqlHost+")/mysql"+MysqlSslMode) TypeConnection = "unix" } else { - db, err = sql.Open("mysql", configuration.MysqlUser+":"+configuration.MysqlPassword+"@tcp("+configuration.MysqlHost+":"+configuration.MysqlPort+")/mysql") + db, err = sql.Open("mysql", configuration.MysqlUser+":"+configuration.MysqlPassword+"@tcp("+configuration.MysqlHost+":"+configuration.MysqlPort+")/mysql"+MysqlSslMode) TypeConnection = "tcp" } if err != nil {