Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support s3 path style access #48

Merged
merged 6 commits into from
May 22, 2024
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
3 changes: 1 addition & 2 deletions .github/workflows/build-and-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
jobs:
build-and-publish:
name: Java Gradle
uses: bakdata/ci-templates/.github/workflows/java-gradle-library.yaml@1.40.6
uses: bakdata/ci-templates/.github/workflows/java-gradle-library.yaml@1.46.3
with:
java-version: 17
secrets:
Expand All @@ -19,5 +19,4 @@ jobs:
signing-password: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}
ossrh-username: ${{ secrets.SONATYPE_OSSRH_USERNAME }}
ossrh-password: ${{ secrets.SONATYPE_OSSRH_PASSWORD }}
github-username: ${{ secrets.GH_USERNAME }}
github-token: ${{ secrets.GH_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ on:
jobs:
java-gradle-release:
name: Java Gradle
uses: bakdata/ci-templates/.github/workflows/java-gradle-release.yaml@1.40.6
uses: bakdata/ci-templates/.github/workflows/java-gradle-release.yaml@1.46.3
with:
java-version: 17
release-type: "${{ inputs.release-type }}"
Expand Down
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ for backwards compatibility but leads to increased memory usage. It is recommend
* Default: ""
* Importance: low


``large.message.s3.role.external.id``
AWS STS role external ID used when retrieving session credentials under an assumed role. Leave empty if AWS Basic provider or AWS credential provider chain should be used.

Expand Down Expand Up @@ -151,6 +151,13 @@ Endpoint to use for connection to Amazon S3. Leave empty if default S3 endpoint
* Default: ""
* Importance: low

``large.message.s3.path.style.access``
Enable path-style access for S3 client.

* Type: boolean
* Default: false
* Importance: low

``large.message.abs.connection.string``
Azure connection string for connection to blob storage. Leave empty if Azure credential provider chain should be used.

Expand All @@ -161,7 +168,7 @@ Endpoint to use for connection to Amazon S3. Leave empty if default S3 endpoint
``large.message.gs.key.path``
Google service account key JSON path. Leave empty If the environment variable GOOGLE_APPLICATION_CREDENTIALS is set
or if you want to use the default service account provided by your computer engine. For more information about
authenticating as a service account please
authenticating as a service account please
refer to the [main documentation](https://cloud.google.com/docs/authentication/production).

* Type: string
Expand Down
20 changes: 3 additions & 17 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
plugins {
id("net.researchgate.release") version "3.0.2"
id("com.bakdata.sonar") version "1.1.17"
id("com.bakdata.sonatype") version "1.1.14"
id("org.hildan.github.changelog") version "2.2.0"
id("com.bakdata.release") version "1.4.0"
torbsto marked this conversation as resolved.
Show resolved Hide resolved
id("com.bakdata.sonar") version "1.4.0"
id("com.bakdata.sonatype") version "1.4.0"
id("io.freefair.lombok") version "8.4"
}

Expand Down Expand Up @@ -37,13 +36,6 @@ configure<com.bakdata.gradle.SonatypeSettings> {
}
}

configure<org.hildan.github.changelog.plugin.GitHubChangelogExtension> {
githubUser = "bakdata"
githubRepository = "kafka-large-message-serde"
futureVersionTag = findProperty("changelog.releaseVersion")?.toString()
sinceTag = findProperty("changelog.sinceTag")?.toString()
}

subprojects {
apply(plugin = "java-library")
apply(plugin = "java-test-fixtures")
Expand All @@ -55,9 +47,3 @@ subprojects {
}
}
}

release {
git {
requireBranch.set("master")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ public class AbstractLargeMessageConfig extends AbstractConfig {
public static final String S3_ENDPOINT_DOC =
"Endpoint to use for connection to Amazon S3. Leave empty if default S3 endpoint should be used.";
public static final String S3_ENDPOINT_DEFAULT = "";
public static final String S3_ENABLE_PATH_STYLE_ACCESS_CONFIG = S3_PREFIX + "path.style.access";
public static final String S3_ENABLE_PATH_STYLE_ACCESS_DOC = "Enable path-style access for S3 client.";
public static final boolean S3_ENABLE_PATH_STYLE_ACCESS_DEFAULT = false;
public static final String S3_REGION_DEFAULT = "";
public static final String S3_ACCESS_KEY_DOC = "AWS access key to use for connecting to S3. Leave empty if AWS"
+ " credential provider chain or STS Assume Role provider should be used.";
Expand Down Expand Up @@ -207,6 +210,8 @@ protected static ConfigDef baseConfigDef() {
COMPRESSION_TYPE_DOC)
// Amazon S3
.define(S3_ENDPOINT_CONFIG, Type.STRING, S3_ENDPOINT_DEFAULT, Importance.LOW, S3_ENDPOINT_DOC)
.define(S3_ENABLE_PATH_STYLE_ACCESS_CONFIG, Type.BOOLEAN, S3_ENABLE_PATH_STYLE_ACCESS_DEFAULT,
Importance.LOW, S3_ENABLE_PATH_STYLE_ACCESS_DOC)
.define(S3_REGION_CONFIG, Type.STRING, S3_REGION_DEFAULT, Importance.LOW, S3_REGION_DOC)
.define(S3_ACCESS_KEY_CONFIG, Type.PASSWORD, S3_ACCESS_KEY_DEFAULT, Importance.LOW, S3_ACCESS_KEY_DOC)
.define(S3_SECRET_KEY_CONFIG, Type.PASSWORD, S3_SECRET_KEY_DEFAULT, Importance.LOW, S3_SECRET_KEY_DOC)
Expand Down Expand Up @@ -296,6 +301,9 @@ private BlobStorageClient createAmazonS3Client() {
this.getAmazonEndpointOverride().ifPresent(clientBuilder::endpointOverride);
this.getAmazonRegion().ifPresent(clientBuilder::region);
this.getAmazonCredentialsProvider().ifPresent(clientBuilder::credentialsProvider);
if (this.enableAmazonS3PathStyleAccess()) {
clientBuilder.forcePathStyle(true);
}
return new AmazonS3Client(clientBuilder.build());
}

Expand All @@ -304,6 +312,10 @@ private Optional<URI> getAmazonEndpointOverride() {
return isEmpty(endpoint) ? Optional.empty() : Optional.of(URI.create(endpoint));
}

private boolean enableAmazonS3PathStyleAccess() {
return this.getBoolean(S3_ENABLE_PATH_STYLE_ACCESS_CONFIG);
}

private Optional<Region> getAmazonRegion() {
final String region = this.getString(S3_REGION_CONFIG);
return isEmpty(region) ? Optional.empty() : Optional.of(Region.of(region));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import io.confluent.common.config.ConfigDef;
import java.util.Map;
import java.util.stream.Stream;
import lombok.Builder;
import lombok.Value;
import org.apache.kafka.common.header.Header;
import org.apache.kafka.common.header.Headers;
import org.apache.kafka.common.header.internals.RecordHeaders;
Expand All @@ -52,18 +54,25 @@ private static byte[] serialize(final String s) {

private static Stream<Arguments> provideParameters() {
return Stream.of(true, false)
.flatMap(isKey -> Stream.of("none", "gzip", "snappy", "lz4", "zstd").map(c -> Arguments.of(isKey, c)));
.flatMap(isKey -> Stream.of(true, false)
.map(enabledPathAccess -> RoundtripArgument.builder()
.isKey(isKey)
.isPathStyleAccess(enabledPathAccess)))
.flatMap(builder -> Stream.of("none", "gzip", "snappy", "lz4", "zstd")
.map(c -> builder.compressionType(c).build())
.map(Arguments::of));
}

@ParameterizedTest
@MethodSource("provideParameters")
void shouldRoundtrip(final boolean isKey, final String compressionType) {
void shouldRoundtrip(final RoundtripArgument argument) {
final String bucket = "bucket";
final String basePath = "s3://" + bucket + "/base/";
final Map<String, Object> properties = ImmutableMap.<String, Object>builder()
.put(AbstractLargeMessageConfig.MAX_BYTE_SIZE_CONFIG, 0)
.put(AbstractLargeMessageConfig.BASE_PATH_CONFIG, basePath)
.put(AbstractLargeMessageConfig.COMPRESSION_TYPE_CONFIG, compressionType)
.put(AbstractLargeMessageConfig.S3_ENABLE_PATH_STYLE_ACCESS_CONFIG, argument.isPathStyleAccess())
.put(AbstractLargeMessageConfig.COMPRESSION_TYPE_CONFIG, argument.getCompressionType())
.build();
final S3Client s3 = this.getS3Client();
s3.createBucket(CreateBucketRequest.builder().bucket(bucket).build());
Expand All @@ -73,16 +82,16 @@ void shouldRoundtrip(final boolean isKey, final String compressionType) {

final Headers headers = new RecordHeaders();
final byte[] obj = serialize("big value");
final byte[] data = storer.storeBytes(TOPIC, obj, isKey, headers);
final byte[] data = storer.storeBytes(TOPIC, obj, argument.isKey(), headers);

final Iterable<Header> compressionHeaders = headers.headers(CompressionType.HEADER_NAME);
if ("none".equals(compressionType)) {
if ("none".equals(argument.getCompressionType())) {
assertThat(compressionHeaders).isEmpty();
} else {
assertThat(compressionHeaders).isNotEmpty();
}

final byte[] result = retriever.retrieveBytes(data, headers, isKey);
final byte[] result = retriever.retrieveBytes(data, headers, argument.isKey());
assertThat(result).isEqualTo(obj);
}

Expand All @@ -105,4 +114,12 @@ private LargeMessageRetrievingClient createRetriever() {
final AbstractLargeMessageConfig config = new AbstractLargeMessageConfig(configDef, properties);
return config.getRetriever();
}

@Builder
@Value
static class RoundtripArgument {
boolean isKey;
boolean isPathStyleAccess;
String compressionType;
}
}
Loading