From 8ad2096ce4540b6eeeb20b4be10579c2128862f5 Mon Sep 17 00:00:00 2001 From: Phil Constantinou Date: Sun, 21 Jan 2024 01:06:51 -0800 Subject: [PATCH 1/2] URL encode password --- backends/postgres/postgres_backend.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backends/postgres/postgres_backend.go b/backends/postgres/postgres_backend.go index 3d98dbb..0331b2d 100644 --- a/backends/postgres/postgres_backend.go +++ b/backends/postgres/postgres_backend.go @@ -5,6 +5,7 @@ import ( "embed" "errors" "fmt" + "net/url" "os" "sync" "time" @@ -344,7 +345,7 @@ func (p *PgBackend) initializeDB() (err error) { pqConnectionString := fmt.Sprintf("postgres://%s:%s@%s/%s?sslmode=%s&x-migrations-table=neoq_schema_migrations", pgxCfg.User, - pgxCfg.Password, + url.QueryEscape(pgxCfg.Password), pgxCfg.Host, pgxCfg.Database, sslMode) From 27cd1bb694c87675da7875fdb298e9cae89043a7 Mon Sep 17 00:00:00 2001 From: Phil Constantinou Date: Mon, 22 Jan 2024 11:47:14 -0800 Subject: [PATCH 2/2] Fix support for sslmode too --- backends/postgres/postgres_backend.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/backends/postgres/postgres_backend.go b/backends/postgres/postgres_backend.go index 0331b2d..c077823 100644 --- a/backends/postgres/postgres_backend.go +++ b/backends/postgres/postgres_backend.go @@ -7,6 +7,7 @@ import ( "fmt" "net/url" "os" + "strings" "sync" "time" @@ -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",