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-752633: honour KeepSessionAlive config in DSN #762

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions dsn.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ func DSN(cfg *Config) (dsn string, err error) {
params.Add(k, *v)
}
}
if cfg.KeepSessionAlive {
params.Add("client_session_keep_alive", strconv.FormatBool(cfg.KeepSessionAlive))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we stick to the variable name and naming conventions? I'd prefer calling this parameter keepSessionAlive.

}
if cfg.PrivateKey != nil {
privateKeyInBytes, err := marshalPKCS8PrivateKey(cfg.PrivateKey)
if err != nil {
Expand Down Expand Up @@ -597,6 +600,11 @@ func parseDSNParams(cfg *Config, params string) (err error) {

case "token":
cfg.Token = value
case "client_session_keep_alive":
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

cfg.KeepSessionAlive, err = strconv.ParseBool(value)
if err != nil {
return
}
case "privateKey":
var decodeErr error
block, decodeErr := base64.URLEncoding.DecodeString(value)
Expand Down
27 changes: 27 additions & 0 deletions dsn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,20 @@ func TestParseDSN(t *testing.T) {
ocspMode: ocspModeFailOpen,
err: nil,
},
{
dsn: "u:p@a?database=d?client_session_keep_alive=true",
config: &Config{
Account: "a", User: "u", Password: "p",
Protocol: "https", Host: "a.snowflakecomputing.com", Port: 443,
Database: "d", Schema: "",
JWTExpireTimeout: defaultJWTTimeout,
OCSPFailOpen: OCSPFailOpenTrue,
ValidateDefaultParameters: ConfigBoolTrue,
ClientTimeout: defaultClientTimeout,
KeepSessionAlive: true,
},
ocspMode: ocspModeFailOpen,
},
}

for i, test := range testcases {
Expand Down Expand Up @@ -573,6 +587,10 @@ func TestParseDSN(t *testing.T) {
t.Fatalf("%d: Failed to match ClientTimeout. expected: %v, got: %v",
i, test.config.ClientTimeout, cfg.ClientTimeout)
}
if test.config.KeepSessionAlive != cfg.KeepSessionAlive {
t.Fatalf("%d: Failed to match KeepSessionAlive. expected: %v, got: %v",
i, test.config.KeepSessionAlive, cfg.KeepSessionAlive)
}
case test.err != nil:
driverErrE, okE := test.err.(*SnowflakeError)
driverErrG, okG := err.(*SnowflakeError)
Expand Down Expand Up @@ -856,6 +874,15 @@ func TestDSN(t *testing.T) {
},
dsn: "u:[email protected]:443?clientTimeout=300&ocspFailOpen=true&region=b.c&validateDefaultParameters=true",
},
{
cfg: &Config{
User: "u",
Password: "p",
Account: "a-aofnadsf.somewhere.azure",
KeepSessionAlive: true,
},
dsn: "u:[email protected]:443?ocspFailOpen=true&region=somewhere.azure&validateDefaultParameters=true&client_session_keep_alive=true",
},
}
for _, test := range testcases {
dsn, err := DSN(test.cfg)
Expand Down