Skip to content

Commit

Permalink
Merge branch 'master' into SNOW-1789753
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ext-simba-jy authored Dec 18, 2024
2 parents 597fefa + 7d34091 commit 2d86ab9
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:[email protected]:443?account=account-name&ocspFailOpen=true&region=cn-region&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "account.us-west-2",
},
dsn: "u:[email protected]: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 2d86ab9

Please sign in to comment.