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
35 changes: 35 additions & 0 deletions data-prepper-plugins/s3-common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

dependencies {
compileOnly 'org.projectlombok:lombok:1.18.30'
annotationProcessor 'org.projectlombok:lombok:1.18.30'
implementation project(path: ':data-prepper-plugins:common')
implementation 'software.amazon.awssdk:sts'
implementation 'software.amazon.awssdk:s3'
implementation 'com.fasterxml.jackson.core:jackson-databind'
implementation 'org.apache.httpcomponents:httpcore:4.4.16'
implementation 'dev.failsafe:failsafe:3.3.2'
implementation 'io.micrometer:micrometer-core'
testImplementation libs.commons.lang3
implementation libs.parquet.common
testImplementation testLibs.bundles.junit
}

jacocoTestCoverageVerification {
dependsOn jacocoTestReport
violationRules {
rule { //in addition to core projects rule
limit {
minimum = 0.90
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

package org.opensearch.dataprepper.plugins.source.s3.configuration;
package org.opensearch.dataprepper.plugins.s3.common.config;

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.constraints.Size;
import software.amazon.awssdk.arns.Arn;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.arns.Arn;

import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -68,4 +73,3 @@ public Map<String, String> getAwsStsHeaderOverrides() {
return awsStsHeaderOverrides;
}
}

Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

package org.opensearch.dataprepper.plugins.source.s3.ownership;
package org.opensearch.dataprepper.plugins.s3.common.ownership;

import java.util.Optional;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
package org.opensearch.dataprepper.plugins.source.s3.ownership;
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

package org.opensearch.dataprepper.plugins.s3.common.ownership;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

/**
* Implements {@link BucketOwnerProvider} using a mapping of bucket
* names to account Ids for the bucket owners. Uses a delegate
* {@link BucketOwnerProvider} as a fallback when the bucket is not
* found in the map.
*/
class MappedBucketOwnerProvider implements BucketOwnerProvider {
public class MappedBucketOwnerProvider implements BucketOwnerProvider {
private final Map<String, String> bucketOwnershipMap;
private final BucketOwnerProvider fallbackProvider;

MappedBucketOwnerProvider(Map<String, String> bucketOwnershipMap, BucketOwnerProvider fallbackProvider) {
public MappedBucketOwnerProvider(Map<String, String> bucketOwnershipMap, BucketOwnerProvider fallbackProvider) {
this.bucketOwnershipMap = new HashMap<>(Objects.requireNonNull(bucketOwnershipMap));
this.fallbackProvider = Objects.requireNonNull(fallbackProvider);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

package org.opensearch.dataprepper.plugins.source.s3.ownership;
package org.opensearch.dataprepper.plugins.s3.common.ownership;

import java.util.Optional;

/**
* An implementation of {@link BucketOwnerProvider} which does not provide
* a bucket owner, effectively skipping owner validation.
*/
class NoOwnershipBucketOwnerProvider implements BucketOwnerProvider {
public class NoOwnershipBucketOwnerProvider implements BucketOwnerProvider{
@Override
public Optional<String> getBucketOwner(final String bucket) {
return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

package org.opensearch.dataprepper.plugins.source.s3.ownership;
package org.opensearch.dataprepper.plugins.s3.common.ownership;

import java.util.Objects;
import java.util.Optional;

/**
* An implementation of {@link BucketOwnerProvider} which provides the
* same owner for all buckets.
*/
class StaticBucketOwnerProvider implements BucketOwnerProvider {
public class StaticBucketOwnerProvider implements BucketOwnerProvider {
private final String accountId;

public StaticBucketOwnerProvider(final String accountId) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package org.opensearch.dataprepper.plugins.source.s3;
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

package org.opensearch.dataprepper.plugins.s3.common.source;

import org.apache.parquet.io.SeekableInputStream;
import org.opensearch.dataprepper.model.io.InputFile;
import org.opensearch.dataprepper.plugins.source.s3.ownership.BucketOwnerProvider;
import org.opensearch.dataprepper.plugins.s3.common.ownership.BucketOwnerProvider;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.HeadObjectRequest;
import software.amazon.awssdk.services.s3.model.HeadObjectResponse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
package org.opensearch.dataprepper.plugins.source.s3;
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

package org.opensearch.dataprepper.plugins.s3.common.source;

import com.google.common.base.Preconditions;
import com.google.common.io.ByteStreams;
Expand All @@ -8,7 +18,7 @@
import dev.failsafe.function.CheckedSupplier;
import org.apache.http.ConnectionClosedException;
import org.apache.parquet.io.SeekableInputStream;
import org.opensearch.dataprepper.plugins.source.s3.ownership.BucketOwnerProvider;
import org.opensearch.dataprepper.plugins.s3.common.ownership.BucketOwnerProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.core.sync.ResponseTransformer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/
package org.opensearch.dataprepper.plugins.source.s3;

package org.opensearch.dataprepper.plugins.s3.common.source;

import io.micrometer.core.instrument.Counter;
import io.micrometer.core.instrument.DistributionSummary;
Expand Down Expand Up @@ -94,4 +100,4 @@ public Counter getS3ObjectsThrottledCounter() {
public Counter getS3ObjectsDeleteFailed() { return s3ObjectsDeleteFailed; }

public Counter getS3ObjectReadFailedCounter() { return s3ObjectReadFailedCounter; }
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

package org.opensearch.dataprepper.plugins.source.s3;
package org.opensearch.dataprepper.plugins.s3.common.source;

import lombok.Getter;

import java.util.Objects;
import java.util.Optional;

/**
* Reference to an S3 object.
*/
class S3ObjectReference {
public class S3ObjectReference {
@Getter
private final String bucketName;
@Getter
private final String key;
private final String owner;

Expand All @@ -22,20 +31,12 @@ private S3ObjectReference(final String bucketName, final String key, final Strin
this.owner = owner;
}

static Builder bucketAndKey(final String bucketName, final String key) {
public static Builder bucketAndKey(final String bucketName, final String key) {
Objects.requireNonNull(bucketName, "bucketName must be non null");
Objects.requireNonNull(key, "key must be non null");
return new Builder(bucketName, key);
}

String getBucketName() {
return bucketName;
}

String getKey() {
return key;
}

Optional<String> getBucketOwner() {
return Optional.ofNullable(owner);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
package org.opensearch.dataprepper.plugins.source.s3;
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

package org.opensearch.dataprepper.plugins.s3.common.source;

import software.amazon.awssdk.arns.Arn;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

package org.opensearch.dataprepper.plugins.source.s3.configuration;
package org.opensearch.dataprepper.plugins.s3.common.config;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -69,4 +74,4 @@ private void reflectivelySetField(final AwsAuthenticationOptions awsAuthenticati
field.setAccessible(false);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
package org.opensearch.dataprepper.plugins.source.s3.ownership;
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

package org.opensearch.dataprepper.plugins.s3.common.ownership;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
Expand Down Expand Up @@ -117,4 +127,4 @@ void getBucketOwner_returns_empty_when_not_in_map_nor_in_fallback() {
assertThat(optionalOwner.isPresent(), equalTo(false));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

package org.opensearch.dataprepper.plugins.source.s3.ownership;
package org.opensearch.dataprepper.plugins.s3.common.ownership;

import org.junit.jupiter.api.Test;

Expand All @@ -26,4 +31,4 @@ void getBucketOwner_returns_empty() {
assertThat(optionalOwner, notNullValue());
assertThat(optionalOwner.isPresent(), equalTo(false));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*
*/

package org.opensearch.dataprepper.plugins.source.s3.ownership;
package org.opensearch.dataprepper.plugins.s3.common.ownership;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -42,4 +47,4 @@ void getBucketOwner_returns_the_predefined_accountId() {
assertThat(optionalOwner.isPresent(), equalTo(true));
assertThat(optionalOwner.get(), equalTo(accountId));
}
}
}
Loading
Loading