Skip to content

Commit

Permalink
fix gcp credentials setup
Browse files Browse the repository at this point in the history
  • Loading branch information
smiklosovic committed Aug 10, 2022
1 parent df07ee4 commit 94c2e21
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 12 additions & 1 deletion src/main/java/com/instaclustr/esop/gcp/GCPModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 94c2e21

Please sign in to comment.