Skip to content

Commit

Permalink
added cert support
Browse files Browse the repository at this point in the history
  • Loading branch information
adubovikov committed Apr 24, 2023
1 parent 7e145e7 commit 7164f8c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
56 changes: 56 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,24 @@ func getDataDBSession() (map[string]*gorm.DB, []model.DatabasesMap) {
connectString += fmt.Sprintf(" port=%d", port)
}

//SSL mode
if sslMode == "verify-full" {
if viper.IsSet(keyData + ".sslrootcert") {
sslRoot := viper.GetString(keyData + ".sslrootcert")
connectString += fmt.Sprintf(" sslrootcert=%s", sslRoot)
}

if viper.IsSet(keyData + ".sslkey") {
sslKey := viper.GetString(keyData + ".sslkey")
connectString += fmt.Sprintf(" sslkey=%s", sslKey)
}

if viper.IsSet(keyData + ".sslcert") {
sslCert := viper.GetString(keyData + ".sslcert")
connectString += fmt.Sprintf(" sslcert=%s", sslCert)
}
}

dbA, err := gorm.Open("postgres", connectString)

if err != nil {
Expand Down Expand Up @@ -1181,6 +1199,25 @@ func getDataDBSession() (map[string]*gorm.DB, []model.DatabasesMap) {
connectString += fmt.Sprintf(" port=%d", port)
}

//SSL mode
if sslMode == "verify-full" {
keyData := "database_data"
if viper.IsSet(keyData + ".sslrootcert") {
sslRoot := viper.GetString(keyData + ".sslrootcert")
connectString += fmt.Sprintf(" sslrootcert=%s", sslRoot)
}

if viper.IsSet(keyData + ".sslkey") {
sslKey := viper.GetString(keyData + ".sslkey")
connectString += fmt.Sprintf(" sslkey=%s", sslKey)
}

if viper.IsSet(keyData + ".sslcert") {
sslCert := viper.GetString(keyData + ".sslcert")
connectString += fmt.Sprintf(" sslcert=%s", sslCert)
}
}

db, err := gorm.Open("postgres", connectString)

db.DB().SetMaxIdleConns(5)
Expand Down Expand Up @@ -1237,6 +1274,25 @@ func getConfigDBSession() *gorm.DB {
connectString += fmt.Sprintf(" port=%d", port)
}

//SSL mode
if sslMode == "verify-full" {
keyData := "database_config"
if viper.IsSet(keyData + ".sslrootcert") {
sslRoot := viper.GetString(keyData + ".sslrootcert")
connectString += fmt.Sprintf(" sslrootcert=%s", sslRoot)
}

if viper.IsSet(keyData + ".sslkey") {
sslKey := viper.GetString(keyData + ".sslkey")
connectString += fmt.Sprintf(" sslkey=%s", sslKey)
}

if viper.IsSet(keyData + ".sslcert") {
sslCert := viper.GetString(keyData + ".sslcert")
connectString += fmt.Sprintf(" sslcert=%s", sslCert)
}
}

logger.Info(fmt.Sprintf("Connecting to the config: [%s, %s, %s, %d]\n", host, user, name, port))

db, err := gorm.Open("postgres", connectString)
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package main

// VERSION
var VERSION_APPLICATION = "1.4.53"
var VERSION_APPLICATION = "1.4.54"

// NAME
var NAME_APPLICATION = "homer-app"
Expand Down

0 comments on commit 7164f8c

Please sign in to comment.