Skip to content

Commit

Permalink
Fix support for sslmode too
Browse files Browse the repository at this point in the history
  • Loading branch information
pconstantinou authored and acaloiaro committed Jan 28, 2024
1 parent b2aa389 commit 95ff915
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion backends/postgres/postgres_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"net/url"
"os"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -337,10 +338,19 @@ func (p *PgBackend) initializeDB() (err error) {
return
}

sslMode := "verify-ca"
// nil TLSConfig means "sslmode=disable" was set on the connection
sslMode := "verify-ca"
if pgxCfg.TLSConfig == nil {
sslMode = "disable"
} else if pgxCfg.TLSConfig.InsecureSkipVerify {
sslMode = "require"
}
if dbURL, err := url.Parse(pgxCfg.ConnString()); err == nil &&
strings.HasPrefix(dbURL.Scheme, "postgres") {
val := dbURL.Query()
if v := val.Get("sslmode"); v != "" {
sslMode = v // set sslmode from existing connection string
}
}

pqConnectionString := fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s&x-migrations-table=neoq_schema_migrations",
Expand Down

0 comments on commit 95ff915

Please sign in to comment.