Skip to content

Commit 21b8de0

Browse files
committed
feat(connection): enhance Snowflake connection with token support and MFA caching
1 parent b77e545 commit 21b8de0

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

core/dbio/connection/connection.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ func (c *Connection) setURL() (err error) {
749749
// template = "snowflake://{username}:{password}@{host}.snowflakecomputing.com:443/{database}?schema={schema}&warehouse={warehouse}"
750750
setIfMissing("username", c.Data["user"])
751751
setIfMissing("host", c.Data["account"])
752-
setIfMissing("password", "") // make password optional, especially when using a private key
752+
setIfMissing("password", "") // make password optional, especially when using a private key or token
753753
c.Data["host"] = strings.ReplaceAll(cast.ToString(c.Data["host"]), ".snowflakecomputing.com", "")
754754
template = "snowflake://{username}:{password}@{host}.snowflakecomputing.com:443/{database}?"
755755
if _, ok := c.Data["warehouse"]; ok {
@@ -767,6 +767,16 @@ func (c *Connection) setURL() (err error) {
767767
if _, ok := c.Data["passcode"]; ok {
768768
template = template + "&passcode={passcode}"
769769
}
770+
if _, ok := c.Data["token"]; ok {
771+
template = template + "&token={token}"
772+
}
773+
// Enable MFA token caching by default when using username_password_mfa authenticator
774+
if strings.EqualFold(cast.ToString(c.Data["authenticator"]), "username_password_mfa") {
775+
setIfMissing("clientRequestMfaToken", "true")
776+
}
777+
if _, ok := c.Data["clientRequestMfaToken"]; ok {
778+
template = template + "&clientRequestMfaToken={clientRequestMfaToken}"
779+
}
770780
case dbio.TypeDbDatabricks:
771781
setIfMissing("token", c.Data["password"])
772782
setIfMissing("port", c.Type.DefPort())

core/dbio/database/database_snowflake.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ func (conn *SnowflakeConn) Init() error {
5555
)
5656
}
5757

58+
if strings.EqualFold(conn.GetProp("authenticator"), "programmatic_access_token") &&
59+
conn.GetProp("token") == "" {
60+
return g.Error(
61+
"did not provide property `token` with authenticator=programmatic_access_token. See https://docs.slingdata.io/connections/database-connections/snowflake",
62+
)
63+
}
64+
5865
if m := conn.GetProp("copy_method"); m != "" {
5966
conn.CopyMethod = conn.GetProp("copy_method")
6067
}

0 commit comments

Comments
 (0)