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

Allow to specify tls certificate path though DSN #926

Open
condemil opened this issue Feb 28, 2019 · 5 comments
Open

Allow to specify tls certificate path though DSN #926

condemil opened this issue Feb 28, 2019 · 5 comments

Comments

@condemil
Copy link

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.

@methane
Copy link
Member

methane commented Apr 4, 2019

Unlike pq, we choosed URL style for DSN. It's difficult to write path in config.
We need to write %2F instead of /.

From v1.5, I want to promote Connector interface instead of DSN. DSN is too complicated already.

@condemil
Copy link
Author

condemil commented Apr 4, 2019

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"

@methane
Copy link
Member

methane commented Apr 4, 2019

pq also have URL style for DSN

Is it be able to specify certificate path easily, without %2F?

@condemil
Copy link
Author

condemil commented Apr 5, 2019

I extracted the code from pq project to test it out and I see that you don't need to specify %2F in path. Here is the code to test:

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:

map[sslrootcert:[/test/root.crt]]

Playground: https://play.golang.org/p/FxM9doANUnI

@allenvino1
Copy link

Hi. Is this supported already?

@methane methane modified the milestones: v1.7.0, v1.8.0 May 2, 2023
@methane methane removed this from the v1.8.0 milestone May 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants