Skip to content

Commit

Permalink
SNOW-1515815 Remove the Requirement of SFUSER Parameter when using OA…
Browse files Browse the repository at this point in the history
…UTH (#568)

* remove the requirement of user parameter when using oauth

* fix parameter
  • Loading branch information
sfc-gh-bli authored Jul 8, 2024
1 parent 0468f3e commit 6ac2c8b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ object TestUtils {
// Obligatory properties
jdbcProperties.put("db", params.sfDatabase)
jdbcProperties.put("schema", params.sfSchema) // Has a default
jdbcProperties.put("user", params.sfUser)
if (params.sfUser != null) {
// user is optional when using Oauth token
jdbcProperties.put("user", params.sfUser)
}

params.privateKey match {
case Some(privateKey) =>
Expand Down
7 changes: 4 additions & 3 deletions src/main/scala/net/snowflake/spark/snowflake/Parameters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,12 @@ object Parameters {
"' parameter, e.g. 'accountname.snowflakecomputing.com:443'"
)
}
if (!userParameters.contains(PARAM_SF_USER)) {
val tokenVal = userParameters.get(PARAM_OAUTH_TOKEN)
if ((!userParameters.contains(PARAM_SF_USER)) && tokenVal.isEmpty) {
throw new IllegalArgumentException(
"A snowflake user must be provided with '" + PARAM_SF_USER + "' parameter, e.g. 'user1'"
)
}
val tokenVal = userParameters.get(PARAM_OAUTH_TOKEN)
if ((!userParameters.contains(PARAM_SF_PASSWORD)) &&
(!userParameters.contains(PARAM_PEM_PRIVATE_KEY)) &&
// if OAuth token not provided
Expand Down Expand Up @@ -621,7 +621,8 @@ object Parameters {
/**
* Snowflake user
*/
def sfUser: String = parameters(PARAM_SF_USER)
def sfUser: String = parameters.getOrElse(PARAM_SF_USER, null)


/**
* Snowflake password
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,10 @@ private[snowflake] object ServerConnection {
// Obligatory properties
jdbcProperties.put("db", params.sfDatabase)
jdbcProperties.put("schema", params.sfSchema) // Has a default
jdbcProperties.put("user", params.sfUser)

if (params.sfUser != null) {
// user is optional when using Oauth token
jdbcProperties.put("user", params.sfUser)
}
params.privateKey match {
case Some(privateKey) =>
jdbcProperties.put("privateKey", privateKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class ParametersSuite extends FunSuite with Matchers {
params += "sfauthenticator" -> "oauth"
params += "sftoken" -> "mytoken"
params.remove("sfpassword")
params.remove("sfuser")
val mergedParams = Parameters.mergeParameters(params.toMap)
mergedParams.sfAuthenticator shouldBe Some("oauth")
mergedParams.sfToken shouldBe Some("mytoken")
Expand Down

0 comments on commit 6ac2c8b

Please sign in to comment.