This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch 23045 in repository https://gitbox.apache.org/repos/asf/camel.git
commit d30e4535ec6d60facceab22c1934d2410df4c358 Author: Andrea Cosentino <[email protected]> AuthorDate: Mon Mar 2 10:22:22 2026 +0100 CAMEL-23045 - Generalize Google services authentication with common module - Google Vertex AI Signed-off-by: Andrea Cosentino <[email protected]> --- components/camel-google/camel-google-vertexai/pom.xml | 4 ++++ .../google/vertexai/GoogleVertexAIConfiguration.java | 4 +++- .../vertexai/GoogleVertexAIConnectionFactory.java | 17 ++++++----------- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/components/camel-google/camel-google-vertexai/pom.xml b/components/camel-google/camel-google-vertexai/pom.xml index ce835b628832..18d8a58b37fa 100644 --- a/components/camel-google/camel-google-vertexai/pom.xml +++ b/components/camel-google/camel-google-vertexai/pom.xml @@ -37,6 +37,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-vertexai/src/main/java/org/apache/camel/component/google/vertexai/GoogleVertexAIConfiguration.java b/components/camel-google/camel-google-vertexai/src/main/java/org/apache/camel/component/google/vertexai/GoogleVertexAIConfiguration.java index 32c334fbc05a..6b82a119a633 100644 --- a/components/camel-google/camel-google-vertexai/src/main/java/org/apache/camel/component/google/vertexai/GoogleVertexAIConfiguration.java +++ b/components/camel-google/camel-google-vertexai/src/main/java/org/apache/camel/component/google/vertexai/GoogleVertexAIConfiguration.java @@ -19,13 +19,14 @@ package org.apache.camel.component.google.vertexai; import com.google.cloud.aiplatform.v1.PredictionServiceClient; import com.google.genai.Client; 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 GoogleVertexAIConfiguration implements Cloneable { +public class GoogleVertexAIConfiguration implements Cloneable, GoogleCommonConfiguration { @UriPath(label = "common", description = "Google Cloud Project ID") @Metadata(required = true) @@ -123,6 +124,7 @@ public class GoogleVertexAIConfiguration implements Cloneable { this.modelId = modelId; } + @Override public String getServiceAccountKey() { return serviceAccountKey; } diff --git a/components/camel-google/camel-google-vertexai/src/main/java/org/apache/camel/component/google/vertexai/GoogleVertexAIConnectionFactory.java b/components/camel-google/camel-google-vertexai/src/main/java/org/apache/camel/component/google/vertexai/GoogleVertexAIConnectionFactory.java index 29fe4d6a081b..54e85e273e12 100644 --- a/components/camel-google/camel-google-vertexai/src/main/java/org/apache/camel/component/google/vertexai/GoogleVertexAIConnectionFactory.java +++ b/components/camel-google/camel-google-vertexai/src/main/java/org/apache/camel/component/google/vertexai/GoogleVertexAIConnectionFactory.java @@ -16,15 +16,14 @@ */ package org.apache.camel.component.google.vertexai; -import java.io.InputStream; import java.util.Arrays; import java.util.List; +import com.google.auth.Credentials; import com.google.auth.oauth2.GoogleCredentials; -import com.google.common.base.Strings; import com.google.genai.Client; import org.apache.camel.CamelContext; -import org.apache.camel.support.ResourceHelper; +import org.apache.camel.component.google.common.GoogleCredentialsHelper; public final class GoogleVertexAIConnectionFactory { @@ -50,15 +49,11 @@ public final class GoogleVertexAIConnectionFactory { .project(configuration.getProjectId()) .location(configuration.getLocation()); - if (!Strings.isNullOrEmpty(configuration.getServiceAccountKey())) { - // Load credentials from the service account key file - InputStream credentialsStream - = ResourceHelper.resolveMandatoryResourceAsInputStream(context, configuration.getServiceAccountKey()); - GoogleCredentials credentials = GoogleCredentials.fromStream(credentialsStream) - .createScoped(VERTEX_AI_SCOPES); - clientBuilder.credentials(credentials); + Credentials credentials = GoogleCredentialsHelper.getCredentials(context, configuration, VERTEX_AI_SCOPES); + if (credentials instanceof GoogleCredentials) { + clientBuilder.credentials((GoogleCredentials) credentials); } - // If no service account key is provided, it will use Application Default Credentials + // If no credentials are returned (null), it will use Application Default Credentials // This requires the environment variable GOOGLE_APPLICATION_CREDENTIALS to be set // with the service account file path // More info at https://cloud.google.com/docs/authentication/production
