Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion docs/src/main/sphinx/admin/fault-tolerant-execution.rst
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,13 @@ the property may be configured for:
- Any S3-compatible storage
* - ``exchange.gcs.json-key-file-path``
- Path to the JSON file that contains your Google Cloud Platform
service account key.
service account key. Not to be set together with
``exchange.gcs.json-key``
-
- GCS
* - ``exchange.gcs.json-key``
- Your Google Cloud Platform service account key in JSON format.
Not to be set together with ``exchange.gcs.json-key-file-path``
-
- GCS
* - ``exchange.azure.connection-string``
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class ExchangeS3Config
private int asyncClientMaxPendingConnectionAcquires = 10000;
private Duration connectionAcquisitionTimeout = new Duration(1, MINUTES);
private Optional<String> gcsJsonKeyFilePath = Optional.empty();
private Optional<String> gcsJsonKey = Optional.empty();

public String getS3AwsAccessKey()
{
Expand Down Expand Up @@ -228,9 +229,24 @@ public Optional<String> getGcsJsonKeyFilePath()
}

@Config("exchange.gcs.json-key-file-path")
@ConfigDescription("Path to the JSON file that contains your Google Cloud Platform service account key. Not to be set together with `exchange.gcs.json-key`")
public ExchangeS3Config setGcsJsonKeyFilePath(String gcsJsonKeyFilePath)
{
this.gcsJsonKeyFilePath = Optional.ofNullable(gcsJsonKeyFilePath);
return this;
}

public Optional<String> getGcsJsonKey()
{
return gcsJsonKey;
}

@Config("exchange.gcs.json-key")
@ConfigDescription("Your Google Cloud Platform service account key in JSON format. Not to be set together with `exchange.gcs.json-key-file-path`")
@ConfigSecuritySensitive
public ExchangeS3Config setGcsJsonKey(String gcsJsonKey)
{
this.gcsJsonKey = Optional.ofNullable(gcsJsonKey);
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@
import javax.crypto.SecretKey;
import javax.inject.Inject;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -169,8 +171,16 @@ public S3FileSystemExchangeStorage(S3FileSystemExchangeStorageStats stats, Excha
config.getConnectionAcquisitionTimeout());

if (compatibilityMode == GCP) {
if (config.getGcsJsonKeyFilePath().isPresent()) {
Credentials credentials = GoogleCredentials.fromStream(new FileInputStream(config.getGcsJsonKeyFilePath().get()));
Optional<String> gcsJsonKeyFilePath = config.getGcsJsonKeyFilePath();
Optional<String> gcsJsonKey = config.getGcsJsonKey();
verify(!(gcsJsonKeyFilePath.isPresent() && gcsJsonKey.isPresent()),
"gcsJsonKeyFilePath and gcsJsonKey shouldn't be set at the same time");
if (gcsJsonKeyFilePath.isPresent()) {
Credentials credentials = GoogleCredentials.fromStream(new FileInputStream(gcsJsonKeyFilePath.get()));
this.gcsClient = Optional.of(StorageOptions.newBuilder().setCredentials(credentials).build().getService());
}
else if (gcsJsonKey.isPresent()) {
Credentials credentials = GoogleCredentials.fromStream(new ByteArrayInputStream(gcsJsonKey.get().getBytes(StandardCharsets.UTF_8)));
this.gcsClient = Optional.of(StorageOptions.newBuilder().setCredentials(credentials).build().getService());
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public void testDefaults()
.setAsyncClientConcurrency(100)
.setAsyncClientMaxPendingConnectionAcquires(10000)
.setConnectionAcquisitionTimeout(new Duration(1, MINUTES))
.setGcsJsonKeyFilePath(null));
.setGcsJsonKeyFilePath(null)
.setGcsJsonKey(null));
}

@Test
Expand All @@ -68,6 +69,7 @@ public void testExplicitPropertyMappings()
.put("exchange.s3.async-client-max-pending-connection-acquires", "999")
.put("exchange.s3.async-client-connection-acquisition-timeout", "5m")
.put("exchange.gcs.json-key-file-path", "/path/to/gcs_keyfile.json")
.put("exchange.gcs.json-key", "{}")
.buildOrThrow();

ExchangeS3Config expected = new ExchangeS3Config()
Expand All @@ -84,7 +86,8 @@ public void testExplicitPropertyMappings()
.setAsyncClientConcurrency(202)
.setAsyncClientMaxPendingConnectionAcquires(999)
.setConnectionAcquisitionTimeout(new Duration(5, MINUTES))
.setGcsJsonKeyFilePath("/path/to/gcs_keyfile.json");
.setGcsJsonKeyFilePath("/path/to/gcs_keyfile.json")
.setGcsJsonKey("{}");

assertFullMapping(properties, expected);
}
Expand Down