Skip to content

Commit

Permalink
added support ssl mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kochetovd committed Jun 4, 2024
1 parent ad6702f commit af1447d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 1 addition & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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 {
Expand Down
11 changes: 8 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit af1447d

Please sign in to comment.