From 94c2e21a384893ebd3d776eb691f004bbdd55afd Mon Sep 17 00:00:00 2001 From: Stefan Miklosovic Date: Wed, 10 Aug 2022 17:52:20 +0200 Subject: [PATCH] fix gcp credentials setup --- .../java/com/instaclustr/esop/gcp/GCPModule.java | 13 ++++++++++++- .../gcp/GoogleStorageBackupRestoreTest.java | 2 -- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/instaclustr/esop/gcp/GCPModule.java b/src/main/java/com/instaclustr/esop/gcp/GCPModule.java index a0a187d4..a1a13ccc 100644 --- a/src/main/java/com/instaclustr/esop/gcp/GCPModule.java +++ b/src/main/java/com/instaclustr/esop/gcp/GCPModule.java @@ -5,6 +5,8 @@ import static java.lang.String.format; import java.io.ByteArrayInputStream; +import java.io.FileInputStream; +import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Optional; @@ -86,7 +88,16 @@ private Storage resolveStorageFromEnvProperties() { throw new GCPModuleException(format("GCP credentials file %s does not exist!", googleAppCredentialsPath)); } - return StorageOptions.getDefaultInstance().getService(); + GoogleCredentials credentials = resolveGoogleCredentialsFromFile(googleAppCredentialsPath); + return StorageOptions.newBuilder().setCredentials(credentials).build().getService(); + } + + private GoogleCredentials resolveGoogleCredentialsFromFile(String googleAppCredentialsPath) { + try (InputStream is = new FileInputStream(googleAppCredentialsPath)) { + return GoogleCredentials.fromStream(is); + } catch (Exception ex) { + throw new RuntimeException("Unable to read credentials from " + googleAppCredentialsPath); + } } private GoogleCredentials resolveGoogleCredentials(final AbstractOperationRequest operationRequest) { diff --git a/src/test/java/com/instaclustr/esop/backup/embedded/gcp/GoogleStorageBackupRestoreTest.java b/src/test/java/com/instaclustr/esop/backup/embedded/gcp/GoogleStorageBackupRestoreTest.java index 68579402..5dff385c 100644 --- a/src/test/java/com/instaclustr/esop/backup/embedded/gcp/GoogleStorageBackupRestoreTest.java +++ b/src/test/java/com/instaclustr/esop/backup/embedded/gcp/GoogleStorageBackupRestoreTest.java @@ -20,14 +20,12 @@ import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Ignore; import org.testng.annotations.Test; @Test(groups = { "googleTest", "cloudTest", }) -@Ignore public class GoogleStorageBackupRestoreTest extends BaseGoogleStorageBackupRestoreTest { @Inject