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 c8492097fe43 CAMEL-23044 - Generalize Google services authentication
with common module - Google Sheets (#21902)
c8492097fe43 is described below
commit c8492097fe4384d8030ffcbee2c7a6d9b9af6962
Author: Andrea Cosentino <[email protected]>
AuthorDate: Tue Mar 10 11:38:49 2026 +0100
CAMEL-23044 - Generalize Google services authentication with common module
- Google Sheets (#21902)
Signed-off-by: Andrea Cosentino <[email protected]>
---
.../camel/component/google/common/GoogleCredentialsHelper.java | 8 ++++++--
.../component/google/sheets/BatchGoogleSheetsClientFactory.java | 7 +++----
.../camel/component/google/sheets/GoogleSheetsComponent.java | 6 ++----
.../google/sheets/stream/GoogleSheetsStreamComponent.java | 6 ++----
4 files changed, 13 insertions(+), 14 deletions(-)
diff --git
a/components/camel-google/camel-google-common/src/main/java/org/apache/camel/component/google/common/GoogleCredentialsHelper.java
b/components/camel-google/camel-google-common/src/main/java/org/apache/camel/component/google/common/GoogleCredentialsHelper.java
index f0d06e31aff1..1449534d33b4 100644
---
a/components/camel-google/camel-google-common/src/main/java/org/apache/camel/component/google/common/GoogleCredentialsHelper.java
+++
b/components/camel-google/camel-google-common/src/main/java/org/apache/camel/component/google/common/GoogleCredentialsHelper.java
@@ -150,8 +150,12 @@ public final class GoogleCredentialsHelper {
context, serviceAccountKey, scopes, config.getDelegate(),
transport, factory);
}
- throw new IllegalArgumentException(
- "Either OAuth credentials (clientId + clientSecret) or
serviceAccountKey must be provided");
+ // Fall back to Application Default Credentials
+ GoogleCredential credential =
GoogleCredential.getApplicationDefault(transport, factory);
+ if (scopes != null && !scopes.isEmpty()) {
+ credential = credential.createScoped(scopes);
+ }
+ return credential;
}
/**
diff --git
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/BatchGoogleSheetsClientFactory.java
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/BatchGoogleSheetsClientFactory.java
index 777f2a228202..dd494763f137 100644
---
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/BatchGoogleSheetsClientFactory.java
+++
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/BatchGoogleSheetsClientFactory.java
@@ -91,13 +91,12 @@ public class BatchGoogleSheetsClientFactory implements
GoogleSheetsClientFactory
public Sheets makeClient(
CamelContext camelContext, String serviceAccountKey,
Collection<String> scopes, String applicationName,
String delegate) {
- if (serviceAccountKey == null) {
- throw new IllegalArgumentException("serviceAccountKey is required
to create Google Sheets client.");
- }
try {
// Create a temporary configuration to use GoogleCredentialsHelper
GoogleSheetsConfiguration tempConfig = new
GoogleSheetsConfiguration();
- tempConfig.setServiceAccountKey(serviceAccountKey);
+ if (serviceAccountKey != null) {
+ tempConfig.setServiceAccountKey(serviceAccountKey);
+ }
tempConfig.setDelegate(delegate);
Credential credential
diff --git
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsComponent.java
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsComponent.java
index 8e45c4bc5170..463946c21276 100644
---
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsComponent.java
+++
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/GoogleSheetsComponent.java
@@ -57,12 +57,10 @@ public class GoogleSheetsComponent
client = getClientFactory().makeClient(config.getClientId(),
config.getClientSecret(), config.getScopesAsList(),
config.getApplicationName(), config.getRefreshToken(),
config.getAccessToken());
- } else if (config.getServiceAccountKey() != null &&
!config.getServiceAccountKey().isBlank()) {
+ } else {
+ // Use service account key or fall back to Application Default
Credentials
client = getClientFactory().makeClient(getCamelContext(),
config.getServiceAccountKey(),
config.getScopesAsList(), config.getApplicationName(),
config.getDelegate());
- } else {
- throw new IllegalArgumentException(
- "(clientId and clientSecret) or serviceAccountKey are
required to create Google Sheets client");
}
}
return client;
diff --git
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/stream/GoogleSheetsStreamComponent.java
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/stream/GoogleSheetsStreamComponent.java
index 9b7e8b74e915..9a0dfbf74030 100644
---
a/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/stream/GoogleSheetsStreamComponent.java
+++
b/components/camel-google/camel-google-sheets/src/main/java/org/apache/camel/component/google/sheets/stream/GoogleSheetsStreamComponent.java
@@ -53,12 +53,10 @@ public class GoogleSheetsStreamComponent extends
HealthCheckComponent {
client = getClientFactory().makeClient(config.getClientId(),
config.getClientSecret(), config.getScopesAsList(),
config.getApplicationName(), config.getRefreshToken(),
config.getAccessToken());
- } else if (config.getServiceAccountKey() != null) {
+ } else {
+ // Use service account key or fall back to Application Default
Credentials
client = getClientFactory().makeClient(getCamelContext(),
config.getServiceAccountKey(),
config.getScopesAsList(), config.getApplicationName(),
config.getDelegate());
- } else {
- throw new IllegalArgumentException(
- "(clientId and clientSecret) or serviceAccountKey are
required to create Gmail client");
}
}
return client;