Skip to content

Commit 3d4310a

Browse files
Julien Rioundyakov
Julien Riou
andauthored
feat(options): add skip_verify param (#3216)
* feat(options): Add skip_verify param When parsing a URL, add a "skip_verify" query param to disable TLS certificate verification. Inspired by various Go drivers: * ClickHouse: https://github.com/ClickHouse/clickhouse-go/blob/v2.30.0/clickhouse_options.go#L259 * MongoDB: https://github.com/mongodb/mongo-go-driver/blob/v2.0.0/x/mongo/driver/connstring/connstring.go#L609 * MySQL: https://github.com/go-sql-driver/mysql/blob/v1.8.1/dsn.go#L175 Signed-off-by: Julien Riou <[email protected]> * docs(options): Add skip_verify to ParseURL Signed-off-by: Julien Riou <[email protected]> --------- Signed-off-by: Julien Riou <[email protected]> Co-authored-by: Nedyalko Dyakov <[email protected]>
1 parent d8a9655 commit 3d4310a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

options.go

+4
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ func NewDialer(opt *Options) func(context.Context, string, string) (net.Conn, er
267267
// URL attributes (scheme, host, userinfo, resp.), query parameters using these
268268
// names will be treated as unknown parameters
269269
// - unknown parameter names will result in an error
270+
// - use "skip_verify=true" to ignore TLS certificate validation
270271
//
271272
// Examples:
272273
//
@@ -487,6 +488,9 @@ func setupConnParams(u *url.URL, o *Options) (*Options, error) {
487488
if q.err != nil {
488489
return nil, q.err
489490
}
491+
if o.TLSConfig != nil && q.has("skip_verify") {
492+
o.TLSConfig.InsecureSkipVerify = q.bool("skip_verify")
493+
}
490494

491495
// any parameters left?
492496
if r := q.remaining(); len(r) > 0 {

options_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ func TestParseURL(t *testing.T) {
3030
}, {
3131
url: "rediss://localhost:123",
3232
o: &Options{Addr: "localhost:123", TLSConfig: &tls.Config{ /* no deep comparison */ }},
33+
}, {
34+
url: "rediss://localhost:123/?skip_verify=true",
35+
o: &Options{Addr: "localhost:123", TLSConfig: &tls.Config{InsecureSkipVerify: true}},
3336
}, {
3437
url: "redis://:bar@localhost:123",
3538
o: &Options{Addr: "localhost:123", Password: "bar"},

0 commit comments

Comments
 (0)