Skip to content

Commit

Permalink
Adding flag to utilize the SSL support for the backend connection
Browse files Browse the repository at this point in the history
  • Loading branch information
javuto committed Oct 3, 2024
1 parent 496abb9 commit c8e7b0f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions admin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,13 @@ func init() {
EnvVars: []string{"DB_PASS"},
Destination: &dbConfigValues.Password,
},
&cli.StringFlag{
Name: "db-sslmode",
Value: "disable",
Usage: "SSL native support to encrypt the connection to the backend",
EnvVars: []string{"DB_SSLMODE"},
Destination: &dbConfigValues.SSLMode,
},
&cli.IntFlag{
Name: "db-max-idle-conns",
Value: 20,
Expand Down
7 changes: 7 additions & 0 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@ func init() {
EnvVars: []string{"DB_PASS"},
Destination: &dbConfigValues.Password,
},
&cli.StringFlag{
Name: "db-sslmode",
Value: "disable",
Usage: "SSL native support to encrypt the connection to the backend",
EnvVars: []string{"DB_SSLMODE"},
Destination: &dbConfigValues.SSLMode,
},
&cli.IntFlag{
Name: "db-max-idle-conns",
Value: 20,
Expand Down
5 changes: 3 additions & 2 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

const (
// DBString to format connection string to database for postgres
DBString = "host=%s port=%s dbname=%s user=%s password=%s sslmode=disable"
DBString = "host=%s port=%s dbname=%s user=%s password=%s sslmode=%s"
// DBKey to identify the configuration JSON key
DBKey = "db"
)
Expand All @@ -31,6 +31,7 @@ type JSONConfigurationDB struct {
Name string `json:"name"`
Username string `json:"username"`
Password string `json:"password"`
SSLMode string `json:"sslmode"`
MaxIdleConns int `json:"maxIdleConns"`
MaxOpenConns int `json:"maxOpenConns"`
ConnMaxLifetime int `json:"connMaxLifetime"`
Expand All @@ -57,7 +58,7 @@ func LoadConfiguration(file, key string) (JSONConfigurationDB, error) {
// PrepareDSN to generate DB connection string
func PrepareDSN(config JSONConfigurationDB) string {
return fmt.Sprintf(
DBString, config.Host, config.Port, config.Name, config.Username, config.Password)
DBString, config.Host, config.Port, config.Name, config.Username, config.Password, config.SSLMode)
}

// GetDB to get PostgreSQL DB using GORM
Expand Down
1 change: 1 addition & 0 deletions deploy/config/db.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"name": "_DB_NAME",
"username": "_DB_USERNAME",
"password": "_DB_PASSWORD",
"sslmode": "disable",
"maxIdleConns": 20,
"maxOpenConns": 100,
"connMaxLifetime": 30,
Expand Down
7 changes: 7 additions & 0 deletions tls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,13 @@ func init() {
EnvVars: []string{"DB_PASS"},
Destination: &dbConfigValues.Password,
},
&cli.StringFlag{
Name: "db-sslmode",
Value: "disable",
Usage: "SSL native support to encrypt the connection to the backend",
EnvVars: []string{"DB_SSLMODE"},
Destination: &dbConfigValues.SSLMode,
},
&cli.IntFlag{
Name: "db-max-idle-conns",
Value: 20,
Expand Down

0 comments on commit c8e7b0f

Please sign in to comment.