This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new e8111c0f77fc CAMEL-23039 - Generalize Google services authentication
with common module - Google Cloud Functions (#21593)
e8111c0f77fc is described below
commit e8111c0f77fcc6493eab93cf935d409b9d2a1d11
Author: Andrea Cosentino <[email protected]>
AuthorDate: Tue Feb 24 18:51:13 2026 +0100
CAMEL-23039 - Generalize Google services authentication with common module
- Google Cloud Functions (#21593)
Signed-off-by: Andrea Cosentino <[email protected]>
---
.../camel-google/camel-google-functions/pom.xml | 4 ++++
.../GoogleCloudFunctionsClientFactory.java | 23 ++++++++--------------
.../GoogleCloudFunctionsConfiguration.java | 4 +++-
3 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/components/camel-google/camel-google-functions/pom.xml
b/components/camel-google/camel-google-functions/pom.xml
index fe8c23644ed3..89b38625bd61 100644
--- a/components/camel-google/camel-google-functions/pom.xml
+++ b/components/camel-google/camel-google-functions/pom.xml
@@ -38,6 +38,10 @@
</properties>
<dependencies>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-google-common</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-support</artifactId>
diff --git
a/components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsClientFactory.java
b/components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsClientFactory.java
index 02b7796676f5..34fec21430c6 100644
---
a/components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsClientFactory.java
+++
b/components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsClientFactory.java
@@ -16,16 +16,12 @@
*/
package org.apache.camel.component.google.functions;
-import java.io.InputStream;
-
import com.google.api.gax.core.FixedCredentialsProvider;
import com.google.auth.Credentials;
-import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.functions.v1.CloudFunctionsServiceClient;
import com.google.cloud.functions.v1.CloudFunctionsServiceSettings;
-import com.google.common.base.Strings;
import org.apache.camel.CamelContext;
-import org.apache.camel.support.ResourceHelper;
+import org.apache.camel.component.google.common.GoogleCredentialsHelper;
public final class GoogleCloudFunctionsClientFactory {
/**
@@ -38,22 +34,19 @@ public final class GoogleCloudFunctionsClientFactory {
CamelContext context,
GoogleCloudFunctionsConfiguration configuration)
throws Exception {
- CloudFunctionsServiceClient cloudFunctionsClient = null;
- if (!Strings.isNullOrEmpty(configuration.getServiceAccountKey())) {
- InputStream resolveMandatoryResourceAsInputStream
- =
ResourceHelper.resolveMandatoryResourceAsInputStream(context,
configuration.getServiceAccountKey());
- Credentials myCredentials = ServiceAccountCredentials
- .fromStream(resolveMandatoryResourceAsInputStream);
+
+ Credentials credentials =
GoogleCredentialsHelper.getCredentials(context, configuration);
+
+ if (credentials != null) {
CloudFunctionsServiceSettings settings =
CloudFunctionsServiceSettings.newBuilder()
-
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)).build();
- cloudFunctionsClient =
CloudFunctionsServiceClient.create(settings);
+
.setCredentialsProvider(FixedCredentialsProvider.create(credentials)).build();
+ return CloudFunctionsServiceClient.create(settings);
} else {
// it needs to define the environment variable
GOOGLE_APPLICATION_CREDENTIALS
// with the service account file
// more info at
https://cloud.google.com/docs/authentication/production
CloudFunctionsServiceSettings settings =
CloudFunctionsServiceSettings.newBuilder().build();
- cloudFunctionsClient =
CloudFunctionsServiceClient.create(settings);
+ return CloudFunctionsServiceClient.create(settings);
}
- return cloudFunctionsClient;
}
}
diff --git
a/components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsConfiguration.java
b/components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsConfiguration.java
index 199ed1d2f662..4481994b7ed0 100644
---
a/components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsConfiguration.java
+++
b/components/camel-google/camel-google-functions/src/main/java/org/apache/camel/component/google/functions/GoogleCloudFunctionsConfiguration.java
@@ -18,13 +18,14 @@ package org.apache.camel.component.google.functions;
import com.google.cloud.functions.v1.CloudFunctionsServiceClient;
import org.apache.camel.RuntimeCamelException;
+import org.apache.camel.component.google.common.GoogleCommonConfiguration;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriParams;
import org.apache.camel.spi.UriPath;
@UriParams
-public class GoogleCloudFunctionsConfiguration implements Cloneable {
+public class GoogleCloudFunctionsConfiguration implements Cloneable,
GoogleCommonConfiguration {
@UriPath(label = "common", description = "The user-defined name of the
function")
@Metadata(required = true)
@@ -63,6 +64,7 @@ public class GoogleCloudFunctionsConfiguration implements
Cloneable {
this.functionName = functionName;
}
+ @Override
public String getServiceAccountKey() {
return serviceAccountKey;
}