Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL encode password #113

Merged
merged 2 commits into from
Jan 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions backends/postgres/postgres_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (
"embed"
"errors"
"fmt"
"net/url"
"os"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -336,15 +338,24 @@ 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",
pgxCfg.User,
pgxCfg.Password,
url.QueryEscape(pgxCfg.Password),
pgxCfg.Host,
pgxCfg.Database,
sslMode)
Expand Down
Loading