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 78874a371443f62dd431659b9fb705d5e1984e75 Author: Andrea Cosentino <[email protected]> AuthorDate: Mon Mar 1 09:25:11 2021 +0100 CAMEL-16274 - Camel-google-storage: serviceAccountKey should be supported as file, classpath, remote etc. --- .../google/storage/GoogleCloudStorageConnectionFactory.java | 9 +++++++-- .../component/google/storage/GoogleCloudStorageEndpoint.java | 2 +- 2 files changed, 8 insertions(+), 3 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 627f4d5..fb7ba56 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 @@ -17,12 +17,16 @@ 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; + public final class GoogleCloudStorageConnectionFactory { /** @@ -31,11 +35,12 @@ public final class GoogleCloudStorageConnectionFactory { private GoogleCloudStorageConnectionFactory() { } - public static Storage create(GoogleCloudStorageConfiguration configuration) throws Exception { + public static Storage create(CamelContext context, GoogleCloudStorageConfiguration configuration) throws Exception { if (!Strings.isNullOrEmpty(configuration.getServiceAccountKey())) { + InputStream resolveMandatoryResourceAsInputStream = ResourceHelper.resolveMandatoryResourceAsInputStream(context, configuration.getServiceAccountKey()); Storage storage = StorageOptions.newBuilder() .setCredentials( - ServiceAccountCredentials.fromStream(new FileInputStream(configuration.getServiceAccountKey()))) + ServiceAccountCredentials.fromStream(resolveMandatoryResourceAsInputStream)) .build().getService(); return storage; } else { diff --git a/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpoint.java b/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpoint.java index 79da387..38d7cfe 100644 --- a/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpoint.java +++ b/components/camel-google-storage/src/main/java/org/apache/camel/component/google/storage/GoogleCloudStorageEndpoint.java @@ -72,7 +72,7 @@ public class GoogleCloudStorageEndpoint extends ScheduledPollEndpoint { this.storageClient = configuration.getStorageClient(); if (this.storageClient == null) { - this.storageClient = GoogleCloudStorageConnectionFactory.create(configuration); + this.storageClient = GoogleCloudStorageConnectionFactory.create(this.getCamelContext(), configuration); } if (configuration.isAutoCreateBucket()) {
