-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Allow to specify tls certificate path though DSN #926
Comments
Unlike pq, we choosed URL style for DSN. It's difficult to write path in config. From v1.5, I want to promote Connector interface instead of DSN. DSN is too complicated already. |
pq also have URL style for DSN, you can check it here: https://godoc.org/github.com/lib/pq example from docs: connStr := "postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full" |
Is it be able to specify certificate path easily, without |
I extracted the code from pq project to test it out and I see that you don't need to specify package main
import "fmt"
import nurl "net/url"
import "strings"
func main() {
url := "postgres://bob:secret@1.2.3.4:5432/mydb?sslrootcert=/test/root.crt"
u, _ := nurl.Parse(url)
var kvs []string
escaper := strings.NewReplacer(` `, `\ `, `'`, `\'`, `\`, `\\`)
accrue := func(k, v string) {
if v != "" {
kvs = append(kvs, k+"="+escaper.Replace(v))
}
}
q := u.Query()
for k := range q {
accrue(k, q.Get(k))
}
fmt.Println(q)
} Result:
Playground: https://play.golang.org/p/FxM9doANUnI |
Hi. Is this supported already? |
Feature request description
For now the only way to add TLS validation is though code with RegisterTLSConfig. With providing certificate path though DSN (like pq is doing it) all existing applications will receive TLS certificate validation out of the box without code changes. It will also help the applications that supports both pq and mysql as this will eliminate mysql-specific initialisation code before
sql.Open()
call.The text was updated successfully, but these errors were encountered: