Skip to content

Commit 86a20c0

Browse files
committed
Addressed review comments
Signed-off-by: Kondaka <krishkdk@amazon.com>
1 parent c9d9c8f commit 86a20c0

26 files changed

+423
-91
lines changed

data-prepper-plugins/http-sink/build.gradle

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@ test {
3737
}
3838

3939
sourceSets {
40-
main {
41-
java {
42-
exclude '**/service/WebhookService.java'
43-
}
44-
}
45-
test {
46-
java {
47-
exclude '**/service/WebhookServiceTest.java'
48-
}
49-
}
5040
integrationTest {
5141
java {
5242
compileClasspath += main.output + test.output

data-prepper-plugins/http-sink/src/integrationTest/java/org/opensearch/dataprepper/plugins/sink/http/HttpSinkIT.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*
9+
*/
10+
111
package org.opensearch.dataprepper.plugins.sink.http;
212

313
import com.fasterxml.jackson.databind.ObjectMapper;

data-prepper-plugins/http-sink/src/integrationTest/java/org/opensearch/dataprepper/plugins/sink/http/HttpSinkServiceIT.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/*
22
* Copyright OpenSearch Contributors
33
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*
49
*/
10+
511
package org.opensearch.dataprepper.plugins.sink.http;
612

713
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -81,7 +87,7 @@ public class HttpSinkServiceIT {
8187
private Counter httpSinkRecordsSuccessCounter;
8288

8389
@Mock
84-
private HttpEndPointResponse httpEndPointResponse;
90+
private HttpEndpointResponse httpEndpointResponse;
8591

8692
@Mock
8793
NdjsonOutputConfig ndjsonOutputConfig;
@@ -92,9 +98,9 @@ void setUp() throws JsonProcessingException{
9298
final String configYaml = MessageFormat.format(config, (Object) urlString, "unauthenticated");
9399
this.httpSinkConfiguration = objectMapper.readValue(configYaml, HttpSinkConfiguration.class);
94100
this.httpSinkSender = mock(HttpSinkSender.class);
95-
httpEndPointResponse = mock(HttpEndPointResponse.class);
96-
when(httpEndPointResponse.getStatusCode()).thenReturn(200);
97-
when(httpSinkSender.send(any())).thenReturn(httpEndPointResponse);
101+
httpEndpointResponse = mock(HttpEndpointResponse.class);
102+
when(httpEndpointResponse.getStatusCode()).thenReturn(200);
103+
when(httpSinkSender.send(any())).thenReturn(httpEndpointResponse);
98104
sinkMetrics = mock(SinkMetrics.class);
99105
}
100106

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*
9+
*/
10+
11+
package org.opensearch.dataprepper.plugins.sink.http;
12+
13+
import software.amazon.awssdk.http.SdkHttpFullRequest;
14+
15+
public interface AuthenticationDecorator {
16+
SdkHttpFullRequest authenticate(SdkHttpFullRequest request);
17+
}

data-prepper-plugins/http-sink/src/main/java/org/opensearch/dataprepper/plugins/sink/http/HttpSinkSigV4Signer.java renamed to data-prepper-plugins/http-sink/src/main/java/org/opensearch/dataprepper/plugins/sink/http/AwsAuthenticationDecorator.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
/*
22
* Copyright OpenSearch Contributors
33
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*
49
*/
10+
511
package org.opensearch.dataprepper.plugins.sink.http;
612

713
import org.opensearch.dataprepper.aws.api.AwsCredentialsOptions;
814
import org.opensearch.dataprepper.aws.api.AwsCredentialsSupplier;
9-
import org.opensearch.dataprepper.plugins.sink.http.configuration.HttpSinkConfiguration;
1015
import org.opensearch.dataprepper.aws.api.AwsConfig;
1116
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
1217
import software.amazon.awssdk.auth.signer.Aws4Signer;
@@ -15,25 +20,23 @@
1520
import software.amazon.awssdk.regions.Region;
1621

1722
import javax.annotation.Nonnull;
18-
import java.net.URI;
1923

20-
class HttpSinkSigV4Signer {
24+
public class AwsAuthenticationDecorator implements AuthenticationDecorator {
2125
private static final String SERVICE_NAME = "execute-api";
26+
private static final String CONTENT_SHA256_HEADER = "x-amz-content-sha256";
27+
private static final String CONTENT_SHA256_VALUE = "required";
28+
2229
private final Aws4Signer signer = Aws4Signer.create();
2330
private final AwsCredentialsProvider credentialsProvider;
2431
private final Region region;
25-
private final URI endpointUri;
2632

27-
HttpSinkSigV4Signer(@Nonnull final AwsCredentialsSupplier awsCredentialsSupplier, @Nonnull final HttpSinkConfiguration config) {
28-
this.region = config.getAwsConfig().getAwsRegion();
29-
this.credentialsProvider = awsCredentialsSupplier.getProvider(convertToCredentialOptions(config.getAwsConfig()));
30-
this.endpointUri = URI.create(config.getUrl());
33+
public AwsAuthenticationDecorator(@Nonnull final AwsCredentialsSupplier awsCredentialsSupplier,
34+
@Nonnull final AwsConfig awsConfig) {
35+
this.region = awsConfig.getAwsRegion();
36+
this.credentialsProvider = awsCredentialsSupplier.getProvider(convertToCredentialOptions(awsConfig));
3137
}
3238

3339
private static AwsCredentialsOptions convertToCredentialOptions(final AwsConfig awsConfig) {
34-
if (awsConfig == null) {
35-
return AwsCredentialsOptions.builder().build();
36-
}
3740
return AwsCredentialsOptions.builder()
3841
.withRegion(awsConfig.getAwsRegion())
3942
.withStsRoleArn(awsConfig.getAwsStsRoleArn())
@@ -42,11 +45,13 @@ private static AwsCredentialsOptions convertToCredentialOptions(final AwsConfig
4245
.build();
4346
}
4447

45-
SdkHttpFullRequest signRequest(final SdkHttpFullRequest unsignedRequest) {
46-
if (credentialsProvider == null || credentialsProvider.resolveCredentials() == null) {
47-
return null;
48-
}
49-
return signer.sign(unsignedRequest, Aws4SignerParams.builder()
48+
@Override
49+
public SdkHttpFullRequest authenticate(final SdkHttpFullRequest request) {
50+
final SdkHttpFullRequest requestWithHeader = request.toBuilder()
51+
.putHeader(CONTENT_SHA256_HEADER, CONTENT_SHA256_VALUE)
52+
.build();
53+
54+
return signer.sign(requestWithHeader, Aws4SignerParams.builder()
5055
.signingRegion(region)
5156
.signingName(SERVICE_NAME)
5257
.awsCredentials(credentialsProvider.resolveCredentials())

data-prepper-plugins/http-sink/src/main/java/org/opensearch/dataprepper/plugins/sink/http/AwsRequestSigningApacheInterceptor.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
/*
2-
* Copyright OpenSearch Contributors. All Rights Reserved.
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
34
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
5-
* the License. A copy of the License is located at
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
68
*
7-
* http://aws.amazon.com/apache2.0
8-
*
9-
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10-
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
11-
* and limitations under the License.
129
*/
10+
1311
package org.opensearch.dataprepper.plugins.sink.http;
1412

1513
import org.apache.hc.core5.http.HttpRequest;
@@ -226,4 +224,4 @@ private static Header[] mapToHeaderArray(final Map<String, List<String>> mapHead
226224
}
227225
return headers;
228226
}
229-
}
227+
}

data-prepper-plugins/http-sink/src/main/java/org/opensearch/dataprepper/plugins/sink/http/FailedHttpResponseInterceptor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/*
22
* Copyright OpenSearch Contributors
33
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*
49
*/
10+
511
package org.opensearch.dataprepper.plugins.sink.http;
612

713
import org.apache.hc.core5.http.EntityDetails;

data-prepper-plugins/http-sink/src/main/java/org/opensearch/dataprepper/plugins/sink/http/HttpEndPointResponse.java renamed to data-prepper-plugins/http-sink/src/main/java/org/opensearch/dataprepper/plugins/sink/http/HttpEndpointResponse.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
/*
22
* Copyright OpenSearch Contributors
33
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*
49
*/
10+
511
package org.opensearch.dataprepper.plugins.sink.http;
612

7-
public class HttpEndPointResponse {
13+
public class HttpEndpointResponse {
814
private String url;
915
private int statusCode;
1016
private String errMessage;
1117

12-
public HttpEndPointResponse(final String url,
18+
public HttpEndpointResponse(final String url,
1319
final int statusCode,
1420
final String errMessage) {
1521
this.url = url;
1622
this.statusCode = statusCode;
1723
this.errMessage = errMessage;
1824
}
1925

20-
public HttpEndPointResponse(final String url,
26+
public HttpEndpointResponse(final String url,
2127
final int statusCode) {
2228
this.url = url;
2329
this.statusCode = statusCode;
@@ -43,4 +49,4 @@ public String toString() {
4349
", errMessage='" + errMessage + '\'' +
4450
'}';
4551
}
46-
}
52+
}

data-prepper-plugins/http-sink/src/main/java/org/opensearch/dataprepper/plugins/sink/http/HttpSink.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
/*
22
* Copyright OpenSearch Contributors
33
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* The OpenSearch Contributors require contributions made to
6+
* this file be licensed under the Apache-2.0 license or a
7+
* compatible open source license.
8+
*
49
*/
10+
511
package org.opensearch.dataprepper.plugins.sink.http;
612

713
import com.google.common.annotations.VisibleForTesting;
@@ -62,10 +68,11 @@ public HttpSink(final PluginSetting pluginSetting,
6268

6369
final SinkMetrics sinkMetrics = new DefaultSinkMetrics(pluginMetrics, "Event");
6470

65-
final HttpSinkSender httpSender = new HttpSinkSender(
66-
httpSinkConfiguration.getAwsConfig() != null ? awsCredentialsSupplier : null,
67-
httpSinkConfiguration,
68-
sinkMetrics);
71+
final AuthenticationDecorator authDecorator = httpSinkConfiguration.getAwsConfig() != null
72+
? new AwsAuthenticationDecorator(awsCredentialsSupplier, httpSinkConfiguration.getAwsConfig())
73+
: null;
74+
75+
final HttpSinkSender httpSender = new HttpSinkSender(authDecorator, httpSinkConfiguration, sinkMetrics);
6976

7077
this.httpSinkService = new HttpSinkService(
7178
httpSinkConfiguration,

0 commit comments

Comments
 (0)