Skip to content

Commit

Permalink
SNOW-1855886 gracefully ignore when default region us-west-2 is used …
Browse files Browse the repository at this point in the history
…in DSN or NewConnector (#1278)
  • Loading branch information
sfc-gh-dszmolka authored Dec 18, 2024
1 parent 45b3d45 commit 7d34091
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
12 changes: 11 additions & 1 deletion dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,16 @@ func (c *Config) ocspMode() string {

// DSN constructs a DSN for Snowflake db.
func DSN(cfg *Config) (dsn string, err error) {
if cfg.Region == "us-west-2" {
if strings.ToLower(cfg.Region) == "us-west-2" {
cfg.Region = ""
}
// in case account includes region
region, posDot := extractRegionFromAccount(cfg.Account)
if strings.ToLower(region) == "us-west-2" {
region = ""
cfg.Account = cfg.Account[:posDot]
logger.Info("Ignoring default region .us-west-2 in DSN from Account configuration.")
}
if region != "" {
if cfg.Region != "" {
return "", errRegionConflict()
Expand Down Expand Up @@ -587,6 +592,11 @@ func transformAccountToHost(cfg *Config) (err error) {
// account name is specified instead of host:port
cfg.Account = cfg.Host
region, posDot := extractRegionFromAccount(cfg.Account)
if strings.ToLower(region) == "us-west-2" {
region = ""
cfg.Account = cfg.Account[:posDot]
logger.Info("Ignoring default region .us-west-2 from Account configuration.")
}
if region != "" {
cfg.Region = region
cfg.Account = cfg.Account[:posDot]
Expand Down
16 changes: 16 additions & 0 deletions dsn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1297,6 +1297,22 @@ func TestDSN(t *testing.T) {
},
dsn: "u:p@account-name.cn-region.snowflakecomputing.cn:443?account=account-name&ocspFailOpen=true&region=cn-region&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "account.us-west-2",
},
dsn: "u:p@account.snowflakecomputing.com:443?ocspFailOpen=true&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "account_us-west-2",
},
dsn: "u:p@account_us-west-2.snowflakecomputing.com:443?ocspFailOpen=true&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Expand Down

0 comments on commit 7d34091

Please sign in to comment.