Skip to content

Commit e1c4a35

Browse files
committed
Enable SSL flag
1 parent 6ccad75 commit e1c4a35

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Usage of pdd:
2222
--database string Database name (default "postgres")
2323
--user string Database user (default "postgres")
2424
--pass string Database password (default "postgres")
25+
--enable-ssl Use TSL/SSL for connection
2526
--dial-timeout duration Dial timeout for establishing new connections (default 5s)
2627
--read-timeout duration Timeout for socket reads. If reached, commands will fail (default 30s)
2728
--max-retry int Maximum number of retries before giving up.

cmd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func main() {
6060
flag.StringVar(&dbc.Database, "database", database.DefaultDatabase, "Database name")
6161
flag.StringVar(&dbc.User, "user", database.DefaultUser, "Database user")
6262
flag.StringVar(&dbc.Password, "pass", database.DefaultPassword, "Database password")
63+
flag.BoolVar(&dbc.EnableSSL, "enable-ssl", false, "Use TSL/SSL for connection")
6364
flag.DurationVar(&dbc.DialTimeout, "dial-timeout", database.DefaultDialTimeout, "Dial timeout for establishing new connections")
6465
flag.DurationVar(&dbc.ReadTimeout, "read-timeout", database.DefaultReadTimeout, "Timeout for socket reads. If reached, commands will fail")
6566
flag.IntVar(&dbc.MaxRetries, "max-retry", database.DefaultMaxRetries, "Maximum number of retries before giving up.")

database/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Config struct {
1919
Database string
2020
User string
2121
Password string
22+
EnableSSL bool
2223
MaxRetries int
2324
DialTimeout time.Duration
2425
ReadTimeout time.Duration

database/database.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ type db struct {
3232

3333
// ConnectDB connects to a database using provided options.
3434
func ConnectDB(logger log.Logger, cfg *Config) (DB, error) {
35+
var tlsConfig tls.Config
36+
37+
if cfg.EnableSSL {
38+
serverName := strings.Split(cfg.Addr, ":")[0]
39+
tlsConfig = tls.Config{ServerName: serverName}
40+
}
41+
3542
pgdb := pg.Connect(
3643
&pg.Options{
3744
Addr: cfg.Addr,
@@ -41,7 +48,7 @@ func ConnectDB(logger log.Logger, cfg *Config) (DB, error) {
4148
MaxRetries: cfg.MaxRetries,
4249
DialTimeout: cfg.DialTimeout,
4350
ReadTimeout: cfg.ReadTimeout,
44-
TLSConfig: &tls.Config{InsecureSkipVerify: true},
51+
TLSConfig: &tlsConfig,
4552
},
4653
)
4754

0 commit comments

Comments
 (0)