Skip to content

Commit

Permalink
Merge pull request #10 from hooncp/bugfix/reorder-priority-of-host-po…
Browse files Browse the repository at this point in the history
…rt-and-region

Order priority of host port over region + Remove boe information
  • Loading branch information
trantaiBD authored Sep 28, 2023
2 parents d795732 + f8c4cdf commit 269d861
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
2 changes: 0 additions & 2 deletions conn/region_volc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand Down
6 changes: 5 additions & 1 deletion sdk/dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -271,3 +271,7 @@ func parseUint(s string) (uint64, error) {
}
return strconv.ParseUint(s, 10, 64)
}

func isEmpty(host string) bool {
return host == "" || host == ":"
}
20 changes: 17 additions & 3 deletions sdk/dsn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,22 @@ 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: "",
authentication: conn.NewPasswordAuthentication("default", ""),
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,
},
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 269d861

Please sign in to comment.