From f8c4cdff7ab9ce39feb68d8c357fa4398c1bdaaf Mon Sep 17 00:00:00 2001 From: Chee Ping Date: Thu, 28 Sep 2023 14:31:44 +0800 Subject: [PATCH] Order priority of host port over region + Remove boe information --- conn/region_volc.go | 2 -- sdk/dsn.go | 6 +++++- sdk/dsn_test.go | 20 +++++++++++++++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/conn/region_volc.go b/conn/region_volc.go index a43b29f..1521911 100644 --- a/conn/region_volc.go +++ b/conn/region_volc.go @@ -6,12 +6,10 @@ import ( ) const ( - RegionBoe = "BOE" RegionCnBeijing = "CN-BEIJING" ) var hostPortByVolcRegion = map[string]string{ - RegionBoe: "gateway.volc-boe.offline.bytehouse.cn:19000", RegionCnBeijing: "bytehouse-cn-beijing.volces.com:19000", } diff --git a/sdk/dsn.go b/sdk/dsn.go index 5d6acfe..2523ad2 100644 --- a/sdk/dsn.go +++ b/sdk/dsn.go @@ -123,7 +123,7 @@ func makeConnConfigs(host string, urlValues url.Values, logf func(s string, i .. opts = append(opts, conn.OptionLogf(logf)) } - if region := urlValues.Get(param.REGION); region != "" { + if region := urlValues.Get(param.REGION); region != "" && isEmpty(host) { host = "" if volcano := urlValues.Get(param.VOLCANO); volcano != "" { isVolc, err := strconv.ParseBool(volcano) @@ -271,3 +271,7 @@ func parseUint(s string) (uint64, error) { } return strconv.ParseUint(s, 10, 64) } + +func isEmpty(host string) bool { + return host == "" || host == ":" +} diff --git a/sdk/dsn_test.go b/sdk/dsn_test.go index d01893b..f4a0023 100644 --- a/sdk/dsn_test.go +++ b/sdk/dsn_test.go @@ -80,7 +80,7 @@ func TestParseDSN(t *testing.T) { { name: "Can accept volcano region and map accordingly", args: args{ - dsn: "?region=" + conn.RegionBoe + "&volcano=true", + dsn: "?region=" + conn.RegionCnBeijing + "&volcano=true", }, want: &Config{ databaseName: "", @@ -88,14 +88,14 @@ func TestParseDSN(t *testing.T) { querySettings: map[string]interface{}{}, }, wantOpts: []conn.OptionConfig{ - conn.OptionHostName("gateway.volc-boe.offline.bytehouse.cn:19000"), + conn.OptionHostName("bytehouse-cn-beijing.volces.com:19000"), conn.OptionSecure(true), }, }, { name: "Can reject volcano region if no volcano flag is given", args: args{ - dsn: "?region=" + conn.RegionBoe, + dsn: "?region=" + conn.RegionCnBeijing, }, wantErr: true, }, @@ -184,6 +184,20 @@ func TestParseDSN(t *testing.T) { conn.OptionRegion(conn.RegionCnNorth1), }, }, + { + name: "When both region and host port is provided in signature authentication, priority is host > region", + args: args{ + dsn: "tcp://XXX.XXX.XXX.XXX.XX:19000?region=mock_region&volcano=true&access_key=ABC&secret_key=XYZ", + }, + want: &Config{ + databaseName: "", + authentication: conn.NewSignatureAuthentication("ABC", "XYZ", "mock_region"), + querySettings: map[string]interface{}{}, + }, + wantOpts: []conn.OptionConfig{ + conn.OptionHostName("XXX.XXX.XXX.XXX.XX:19000"), + }, + }, { name: "Can accept system Authentication", args: args{