You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pekko.apache.org by md...@apache.org on 2024/01/27 21:59:01 UTC

(incubator-pekko-connectors) branch main updated: Remove duplicate scopes value in reference.conf

This is an automated email from the ASF dual-hosted git repository.

mdedetrich pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-pekko-connectors.git


The following commit(s) were added to refs/heads/main by this push:
     new 26fa17428 Remove duplicate scopes value in reference.conf
26fa17428 is described below

commit 26fa1742887489828c5e0d46f1ed10f7ac056fc9
Author: Matthew de Detrich <ma...@aiven.io>
AuthorDate: Sun Jan 14 19:14:24 2024 +1100

    Remove duplicate scopes value in reference.conf
---
 .../apache/pekko/stream/connectors/googlecloud/pubsub/model.scala | 4 ++--
 .../connectors/googlecloud/storage/impl/GCStorageStream.scala     | 2 +-
 google-common/src/main/resources/reference.conf                   | 3 ---
 .../apache/pekko/stream/connectors/google/auth/Credentials.scala  | 7 +++++--
 .../apache/pekko/stream/connectors/google/auth/GoogleOAuth2.scala | 4 ++--
 .../stream/connectors/google/auth/ServiceAccountCredentials.scala | 8 +++-----
 .../pekko/stream/connectors/google/auth/GoogleOAuth2Spec.scala    | 2 +-
 .../stream/connectors/google/firebase/fcm/impl/FcmFlows.scala     | 2 +-
 8 files changed, 15 insertions(+), 17 deletions(-)

diff --git a/google-cloud-pub-sub/src/main/scala/org/apache/pekko/stream/connectors/googlecloud/pubsub/model.scala b/google-cloud-pub-sub/src/main/scala/org/apache/pekko/stream/connectors/googlecloud/pubsub/model.scala
index 802bb8442..0bed06463 100644
--- a/google-cloud-pub-sub/src/main/scala/org/apache/pekko/stream/connectors/googlecloud/pubsub/model.scala
+++ b/google-cloud-pub-sub/src/main/scala/org/apache/pekko/stream/connectors/googlecloud/pubsub/model.scala
@@ -71,7 +71,7 @@ object PubSubConfig {
           projectId = projectId,
           credentials =
             ServiceAccountCredentials(projectId, clientEmail, privateKey,
-              Seq("https://www.googleapis.com/auth/pubsub")))))
+              Set("https://www.googleapis.com/auth/pubsub")))))
 
   /**
    * @deprecated Use [[pekko.stream.connectors.google.GoogleSettings]] to manage credentials
@@ -93,7 +93,7 @@ object PubSubConfig {
           projectId = projectId,
           credentials =
             ServiceAccountCredentials(projectId, clientEmail, privateKey,
-              Seq("https://www.googleapis.com/auth/pubsub")))))
+              Set("https://www.googleapis.com/auth/pubsub")))))
 
   /**
    * Java API
diff --git a/google-cloud-storage/src/main/scala/org/apache/pekko/stream/connectors/googlecloud/storage/impl/GCStorageStream.scala b/google-cloud-storage/src/main/scala/org/apache/pekko/stream/connectors/googlecloud/storage/impl/GCStorageStream.scala
index 63d55bd4b..150305568 100644
--- a/google-cloud-storage/src/main/scala/org/apache/pekko/stream/connectors/googlecloud/storage/impl/GCStorageStream.scala
+++ b/google-cloud-storage/src/main/scala/org/apache/pekko/stream/connectors/googlecloud/storage/impl/GCStorageStream.scala
@@ -312,7 +312,7 @@ import scala.concurrent.{ ExecutionContext, Future }
         && (legacySettings.tokenUrl.contains("googleapis.com") || legacySettings.tokenUrl == "unsupported"),
         "Non-default base-url/base-path/token-url no longer supported, use config path pekko.connectors.google.forward-proxy")
 
-      val legacyScopes = legacySettings.tokenScope.split(" ").toList
+      val legacyScopes = legacySettings.tokenScope.split(" ").toSet
       val credentials = Credentials.cache(
         (
           legacySettings.projectId,
diff --git a/google-common/src/main/resources/reference.conf b/google-common/src/main/resources/reference.conf
index c5fe112f6..48a33ca28 100644
--- a/google-common/src/main/resources/reference.conf
+++ b/google-common/src/main/resources/reference.conf
@@ -27,9 +27,6 @@ pekko.connectors.google {
       path = ${?CLOUDSDK_CONFIG}
       path = ${pekko.connectors.google.credentials.service-account.path}/application_default_credentials.json
       path = ${?GOOGLE_APPLICATION_CREDENTIALS}
-
-      # Always required regardless of where credentials are read from
-      scopes = ${pekko.connectors.google.credentials.scopes}
     }
 
     # Timeout for blocking call during settings initialization to compute engine metadata server
diff --git a/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/Credentials.scala b/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/Credentials.scala
index 72c0e0226..c94f34fbc 100644
--- a/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/Credentials.scala
+++ b/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/Credentials.scala
@@ -20,6 +20,7 @@ import pekko.event.Logging
 import pekko.http.scaladsl.model.headers.HttpCredentials
 import pekko.stream.connectors.google.RequestSettings
 import pekko.util.JavaDurationConverters._
+import pekko.util.ccompat.JavaConverters._
 import com.google.auth.{ Credentials => GoogleCredentials }
 import com.typesafe.config.Config
 
@@ -69,8 +70,10 @@ object Credentials {
     case "none"            => parseNone(c)
   }
 
-  private def parseServiceAccount(c: Config)(implicit system: ClassicActorSystemProvider) =
-    ServiceAccountCredentials(c.getConfig("service-account"))
+  private def parseServiceAccount(c: Config)(implicit system: ClassicActorSystemProvider) = {
+    val scopes = c.getStringList("scopes").asScala.toSet
+    ServiceAccountCredentials(c.getConfig("service-account"), scopes)
+  }
 
   private def parseComputeEngine(c: Config)(implicit system: ClassicActorSystemProvider) =
     Await.result(ComputeEngineCredentials(), c.getDuration("compute-engine.timeout").asScala)
diff --git a/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/GoogleOAuth2.scala b/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/GoogleOAuth2.scala
index 0e41b30c2..6eab497ba 100644
--- a/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/GoogleOAuth2.scala
+++ b/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/GoogleOAuth2.scala
@@ -37,7 +37,7 @@ private[auth] object GoogleOAuth2 {
 
   private val oAuthTokenUrl = "https://oauth2.googleapis.com/token"
 
-  def getAccessToken(clientEmail: String, privateKey: String, scopes: Seq[String])(
+  def getAccessToken(clientEmail: String, privateKey: String, scopes: Set[String])(
       implicit mat: Materializer,
       settings: RequestSettings,
       clock: Clock): Future[AccessToken] = {
@@ -58,7 +58,7 @@ private[auth] object GoogleOAuth2 {
     }
   }
 
-  private def generateJwt(clientEmail: String, privateKey: String, scopes: Seq[String])(
+  private def generateJwt(clientEmail: String, privateKey: String, scopes: Set[String])(
       implicit clock: Clock): String = {
     import spray.json._
 
diff --git a/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/ServiceAccountCredentials.scala b/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/ServiceAccountCredentials.scala
index 369365415..7e69fb4e6 100644
--- a/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/ServiceAccountCredentials.scala
+++ b/google-common/src/main/scala/org/apache/pekko/stream/connectors/google/auth/ServiceAccountCredentials.scala
@@ -18,7 +18,6 @@ import pekko.actor.ClassicActorSystemProvider
 import pekko.annotation.InternalApi
 import pekko.stream.Materializer
 import pekko.stream.connectors.google.RequestSettings
-import pekko.util.ccompat.JavaConverters._
 import com.typesafe.config.Config
 import spray.json.DefaultJsonProtocol._
 import spray.json.{ JsonParser, RootJsonFormat }
@@ -30,11 +29,11 @@ import scala.io.Source
 @InternalApi
 private[connectors] object ServiceAccountCredentials {
 
-  def apply(projectId: String, clientEmail: String, privateKey: String, scopes: Seq[String])(
+  def apply(projectId: String, clientEmail: String, privateKey: String, scopes: Set[String])(
       implicit system: ClassicActorSystemProvider): Credentials =
     new ServiceAccountCredentials(projectId, clientEmail, privateKey, scopes)
 
-  def apply(c: Config)(implicit system: ClassicActorSystemProvider): Credentials = {
+  def apply(c: Config, scopes: Set[String])(implicit system: ClassicActorSystemProvider): Credentials = {
     val (projectId, clientEmail, privateKey) = {
       if (c.getString("private-key").nonEmpty) {
         (
@@ -48,7 +47,6 @@ private[connectors] object ServiceAccountCredentials {
         (credentials.project_id, credentials.client_email, credentials.private_key)
       }
     }
-    val scopes = c.getStringList("scopes").asScala.toSeq
     require(
       projectId.nonEmpty && clientEmail.nonEmpty && privateKey.nonEmpty && scopes.nonEmpty && scopes.forall(_.nonEmpty),
       "Service account requires that project-id, client-email, private-key, and at least one scope are specified.")
@@ -64,7 +62,7 @@ private[connectors] object ServiceAccountCredentials {
 private final class ServiceAccountCredentials(projectId: String,
     clientEmail: String,
     privateKey: String,
-    scopes: Seq[String])(implicit mat: Materializer)
+    scopes: Set[String])(implicit mat: Materializer)
     extends OAuth2Credentials(projectId) {
 
   override protected def getAccessToken()(implicit mat: Materializer,
diff --git a/google-common/src/test/scala/org/apache/pekko/stream/connectors/google/auth/GoogleOAuth2Spec.scala b/google-common/src/test/scala/org/apache/pekko/stream/connectors/google/auth/GoogleOAuth2Spec.scala
index 753e3004a..753f70ea6 100644
--- a/google-common/src/test/scala/org/apache/pekko/stream/connectors/google/auth/GoogleOAuth2Spec.scala
+++ b/google-common/src/test/scala/org/apache/pekko/stream/connectors/google/auth/GoogleOAuth2Spec.scala
@@ -58,7 +58,7 @@ class GoogleOAuth2Spec
     Source.fromInputStream(inputStream).getLines().mkString("\n").stripMargin
   }
 
-  val scopes = Seq("https://www.googleapis.com/auth/service")
+  val scopes = Set("https://www.googleapis.com/auth/service")
 
   "GoogleTokenApi" should {
 
diff --git a/google-fcm/src/main/scala/org/apache/pekko/stream/connectors/google/firebase/fcm/impl/FcmFlows.scala b/google-fcm/src/main/scala/org/apache/pekko/stream/connectors/google/firebase/fcm/impl/FcmFlows.scala
index 61070294c..e6c04873f 100644
--- a/google-fcm/src/main/scala/org/apache/pekko/stream/connectors/google/firebase/fcm/impl/FcmFlows.scala
+++ b/google-fcm/src/main/scala/org/apache/pekko/stream/connectors/google/firebase/fcm/impl/FcmFlows.scala
@@ -66,7 +66,7 @@ private[fcm] object FcmFlows {
   @Deprecated
   private def resolveSettings(conf: FcmSettings)(mat: Materializer, attr: Attributes): GoogleSettings = {
     val settings = GoogleAttributes.resolveSettings(mat, attr)
-    val scopes = List("https://www.googleapis.com/auth/firebase.messaging")
+    val scopes = Set("https://www.googleapis.com/auth/firebase.messaging")
     val credentials =
       if (conf.privateKey == "deprecated")
         settings.credentials


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pekko.apache.org
For additional commands, e-mail: commits-help@pekko.apache.org