Skip to content

Commit 7d34091

Browse files
SNOW-1855886 gracefully ignore when default region us-west-2 is used in DSN or NewConnector (#1278)
1 parent 45b3d45 commit 7d34091

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

dsn.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,16 @@ func (c *Config) ocspMode() string {
141141

142142
// DSN constructs a DSN for Snowflake db.
143143
func DSN(cfg *Config) (dsn string, err error) {
144-
if cfg.Region == "us-west-2" {
144+
if strings.ToLower(cfg.Region) == "us-west-2" {
145145
cfg.Region = ""
146146
}
147147
// in case account includes region
148148
region, posDot := extractRegionFromAccount(cfg.Account)
149+
if strings.ToLower(region) == "us-west-2" {
150+
region = ""
151+
cfg.Account = cfg.Account[:posDot]
152+
logger.Info("Ignoring default region .us-west-2 in DSN from Account configuration.")
153+
}
149154
if region != "" {
150155
if cfg.Region != "" {
151156
return "", errRegionConflict()
@@ -587,6 +592,11 @@ func transformAccountToHost(cfg *Config) (err error) {
587592
// account name is specified instead of host:port
588593
cfg.Account = cfg.Host
589594
region, posDot := extractRegionFromAccount(cfg.Account)
595+
if strings.ToLower(region) == "us-west-2" {
596+
region = ""
597+
cfg.Account = cfg.Account[:posDot]
598+
logger.Info("Ignoring default region .us-west-2 from Account configuration.")
599+
}
590600
if region != "" {
591601
cfg.Region = region
592602
cfg.Account = cfg.Account[:posDot]

dsn_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,22 @@ func TestDSN(t *testing.T) {
12971297
},
12981298
dsn: "u:[email protected]:443?account=account-name&ocspFailOpen=true&region=cn-region&validateDefaultParameters=true",
12991299
},
1300+
{
1301+
cfg: &Config{
1302+
User: "u",
1303+
Password: "p",
1304+
Account: "account.us-west-2",
1305+
},
1306+
dsn: "u:[email protected]:443?ocspFailOpen=true&validateDefaultParameters=true",
1307+
},
1308+
{
1309+
cfg: &Config{
1310+
User: "u",
1311+
Password: "p",
1312+
Account: "account_us-west-2",
1313+
},
1314+
dsn: "u:p@account_us-west-2.snowflakecomputing.com:443?ocspFailOpen=true&validateDefaultParameters=true",
1315+
},
13001316
{
13011317
cfg: &Config{
13021318
User: "u",

0 commit comments

Comments
 (0)