The Wayback Machine - https://web.archive.org./web/20201125064018/https://github.com/go-sql-driver/mysql/issues/926
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 on Feb 28, 2019 · 4 comments
Open

Allow to specify tls certificate path though DSN #926

condemil opened this issue on Feb 28, 2019 · 4 comments

Comments

@condemil
Copy link

@condemil condemil commented on Feb 28, 2019

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 methane commented on 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 condemil commented on 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 methane commented on 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 condemil commented on 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.