Skip to content

Commit 3b35141

Browse files
authored
Fix GcsConnectorUtil auth for gcs-connector 3.x (#5984)
1 parent f346209 commit 3b35141

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

scio-parquet/src/main/scala/com/spotify/scio/parquet/GcsConnectorUtil.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,23 @@ private[parquet] object GcsConnectorUtil {
4848
case _ => None
4949
} match {
5050
case Success(Some(sa)) =>
51+
conf.set("fs.gs.auth.type", "SERVICE_ACCOUNT_JSON_KEYFILE")
5152
conf.set("fs.gs.auth.service.account.json.keyfile", sa)
5253
case Success(None) =>
54+
conf.set("fs.gs.auth.type", "ACCESS_TOKEN_PROVIDER")
5355
conf.set(
5456
"fs.gs.auth.access.token.provider.impl",
5557
"com.spotify.scio.parquet.ApplicationDefaultTokenProvider"
5658
)
5759
case _ =>
60+
conf.set("fs.gs.auth.type", "UNAUTHENTICATED")
5861
conf.setBoolean("fs.gs.auth.service.account.enable", false)
5962
conf.setBoolean("fs.gs.auth.null.enable", true)
6063
}
6164
}
6265

6366
def unsetCredentials(conf: Configuration): Unit = {
67+
conf.unset("fs.gs.auth.type")
6468
conf.unset("fs.gs.auth.service.account.json.keyfile")
6569
conf.unset("fs.gs.auth.access.token.provider.impl")
6670
conf.unset("fs.gs.auth.null.enable")

scio-parquet/src/test/scala/com/spotify/scio/parquet/GcsConnectorUtilTest.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ import org.scalatest.matchers.should.Matchers
2525

2626
class GcsConnectorUtilTest extends AnyFlatSpec with Matchers {
2727

28+
"setCredentials" should "set SERVICE_ACCOUNT_JSON_KEYFILE auth type for service account credentials" in {
29+
val conf = ParquetConfiguration.empty()
30+
sys.env.get("GOOGLE_APPLICATION_CREDENTIALS").foreach { _ =>
31+
GcsConnectorUtil.setCredentials(conf)
32+
val authType = conf.get("fs.gs.auth.type")
33+
authType should (
34+
equal("SERVICE_ACCOUNT_JSON_KEYFILE") or equal("ACCESS_TOKEN_PROVIDER")
35+
)
36+
}
37+
}
38+
39+
it should "set auth type and clear it on unset" in {
40+
val conf = ParquetConfiguration.empty()
41+
GcsConnectorUtil.setCredentials(conf)
42+
conf.get("fs.gs.auth.type") should not be null
43+
44+
GcsConnectorUtil.unsetCredentials(conf)
45+
conf.get("fs.gs.auth.type") shouldBe null
46+
}
47+
2848
private def getInputPaths(sc: ScioContext, path: String): Array[String] = {
2949
val conf = ParquetConfiguration.empty()
3050
GcsConnectorUtil.setInputPaths(sc, conf, path)

0 commit comments

Comments
 (0)