File tree Expand file tree Collapse file tree
main/scala/com/spotify/scio/parquet
test/scala/com/spotify/scio/parquet Expand file tree Collapse file tree Original file line number Diff line number Diff 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" )
Original file line number Diff line number Diff line change @@ -25,6 +25,26 @@ import org.scalatest.matchers.should.Matchers
2525
2626class 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)
You can’t perform that action at this time.
0 commit comments