Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1855886 gracefully ignore when default region us-west-2 is used in DSN or NewConnector #1278

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,16 @@

// 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 @@
// 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.")
}

Check warning on line 599 in dsn.go

View check run for this annotation

Codecov / codecov/patch

dsn.go#L596-L599

Added lines #L596 - L599 were not covered by tests
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
Loading