You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2021/03/01 10:22:57 UTC
[camel] 02/07: CAMEL-16274 - Camel-google-storage:
serviceAccountKey should be supported as file, classpath, remote etc.
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 623f5a826704b4e1912bdc58f870cbc8dd1cb368
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Mar 1 09:28:16 2021 +0100
CAMEL-16274 - Camel-google-storage: serviceAccountKey should be supported as file, classpath, remote etc.
---
.../google/storage/GoogleCloudStorageConnectionFactory.java | 5 ++---
.../unit/GoogleCloudStorageComponentConfigurationTest.java | 8 ++++----
2 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConnectionFactory.java b/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConnectionFactory.java
index fb7ba56..8965b85 100644
--- a/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConnectionFactory.java
+++ b/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageConnectionFactory.java
@@ -16,14 +16,12 @@
*/
package org.apache.camel.component.google.storage;
-import java.io.FileInputStream;
import java.io.InputStream;
import com.google.api.client.util.Strings;
import com.google.auth.oauth2.ServiceAccountCredentials;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
-
import org.apache.camel.CamelContext;
import org.apache.camel.support.ResourceHelper;
@@ -37,7 +35,8 @@ public final class GoogleCloudStorageConnectionFactory {
public static Storage create(CamelContext context, GoogleCloudStorageConfiguration configuration) throws Exception {
if (!Strings.isNullOrEmpty(configuration.getServiceAccountKey())) {
- InputStream resolveMandatoryResourceAsInputStream = ResourceHelper.resolveMandatoryResourceAsInputStream(context, configuration.getServiceAccountKey());
+ InputStream resolveMandatoryResourceAsInputStream
+ = ResourceHelper.resolveMandatoryResourceAsInputStream(context, configuration.getServiceAccountKey());
Storage storage = StorageOptions.newBuilder()
.setCredentials(
ServiceAccountCredentials.fromStream(resolveMandatoryResourceAsInputStream))
diff --git a/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/GoogleCloudStorageComponentConfigurationTest.java b/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/GoogleCloudStorageComponentConfigurationTest.java
index 8fe7c1e..bf02279 100644
--- a/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/GoogleCloudStorageComponentConfigurationTest.java
+++ b/components/camel-google-storage/src/test/java/org/apache/camel/component/google/storage/unit/GoogleCloudStorageComponentConfigurationTest.java
@@ -33,10 +33,10 @@ public class GoogleCloudStorageComponentConfigurationTest extends CamelTestSuppo
GoogleCloudStorageComponent component = context.getComponent("google-storage", GoogleCloudStorageComponent.class);
GoogleCloudStorageEndpoint endpoint = (GoogleCloudStorageEndpoint) component.createEndpoint(
- String.format("google-storage://%s?serviceAccountKey=%s", bucketName, serviceAccountKeyFile));
+ String.format("google-storage://%s?serviceAccountKey=file:%s", bucketName, serviceAccountKeyFile));
assertEquals(endpoint.getConfiguration().getBucketName(), bucketName);
- assertEquals(endpoint.getConfiguration().getServiceAccountKey(), serviceAccountKeyFile);
+ assertEquals(endpoint.getConfiguration().getServiceAccountKey(), "file:" + serviceAccountKeyFile);
}
public void createEndpointForComplexConsumer() throws Exception {
@@ -52,13 +52,13 @@ public class GoogleCloudStorageComponentConfigurationTest extends CamelTestSuppo
GoogleCloudStorageComponent component = context.getComponent("google-storage", GoogleCloudStorageComponent.class);
GoogleCloudStorageEndpoint endpoint = (GoogleCloudStorageEndpoint) component.createEndpoint(
String.format(
- "google-storage://%s?serviceAccountKey=%s&moveAfterRead=%s&destinationBucket=%s&autoCreateBucket=%s&deleteAfterRead=%s&includeBody=%s",
+ "google-storage://%s?serviceAccountKey=file:%s&moveAfterRead=%s&destinationBucket=%s&autoCreateBucket=%s&deleteAfterRead=%s&includeBody=%s",
bucketName, serviceAccountKeyFile, moveAfterRead, destinationBucket, autoCreateBucket,
deleteAfterRead, includeBody));
GoogleCloudStorageConfiguration configuration = endpoint.getConfiguration();
assertEquals(configuration.getBucketName(), bucketName);
- assertEquals(configuration.getServiceAccountKey(), serviceAccountKeyFile);
+ assertEquals(configuration.getServiceAccountKey(), "file:" + serviceAccountKeyFile);
assertEquals(configuration.isMoveAfterRead(), moveAfterRead);
assertEquals(configuration.getDestinationBucket(), destinationBucket);
assertEquals(configuration.isAutoCreateBucket(), autoCreateBucket);