POSTGRES_SSL environment variable for ssl_mode

pull/130/head
hunterlong 2019-01-28 14:45:46 -08:00
parent 1af2e1b929
commit 98f26a62fc
3 changed files with 9 additions and 2 deletions

View File

@ -226,6 +226,7 @@ func HelpEcho() {
fmt.Println(" DB_PASS - Database password")
fmt.Println(" DB_PORT - Database port (5432, 3306, ...)")
fmt.Println(" DB_DATABASE - Database connection's database name")
fmt.Println(" POSTGRES_SSL - Enable Postgres SSL Mode 'ssl_mode=enabled' (true/false)")
fmt.Println(" GO_ENV - Run Statping in testmode, will bypass HTTP authentication (if set as 'true')")
fmt.Println(" NAME - Set a name for the Statping status page")
fmt.Println(" DESCRIPTION - Set a description for the Statping status page")

View File

@ -26,6 +26,7 @@ import (
_ "github.com/jinzhu/gorm/dialects/postgres"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"os"
"strconv"
"time"
)
@ -238,6 +239,7 @@ func (db *DbConfig) InsertCore() (*Core, error) {
// Connect will attempt to connect to the sqlite, postgres, or mysql database
func (db *DbConfig) Connect(retry bool, location string) error {
postgresSSL, _ := strconv.ParseBool(os.Getenv("POSTGRES_SSL"))
if DbSession != nil {
return nil
}
@ -255,7 +257,11 @@ func (db *DbConfig) Connect(retry bool, location string) error {
host := fmt.Sprintf("%v:%v", Configs.DbHost, Configs.DbPort)
conn = fmt.Sprintf("%v:%v@tcp(%v)/%v?charset=utf8&parseTime=True&loc=UTC", Configs.DbUser, Configs.DbPass, host, Configs.DbData)
case "postgres":
conn = fmt.Sprintf("host=%v port=%v user=%v dbname=%v password=%v timezone=UTC sslmode=disable", Configs.DbHost, Configs.DbPort, Configs.DbUser, Configs.DbData, Configs.DbPass)
sslMode := "disabled"
if postgresSSL {
sslMode = "enabled"
}
conn = fmt.Sprintf("host=%v port=%v user=%v dbname=%v password=%v timezone=UTC sslmode=%t", Configs.DbHost, Configs.DbPort, Configs.DbUser, Configs.DbData, Configs.DbPass, sslMode)
case "mssql":
host := fmt.Sprintf("%v:%v", Configs.DbHost, Configs.DbPort)
conn = fmt.Sprintf("sqlserver://%v:%v@%v?database=%v", Configs.DbUser, Configs.DbPass, host, Configs.DbData)

View File

@ -1 +1 @@
0.80.38
0.80.39