Skip to content

Commit 822efda

Browse files
committed
Add user agent interceptors to all remaining modules.
1 parent 18e8d66 commit 822efda

File tree

43 files changed

+901
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+901
-7
lines changed

powertools-batch/pom.xml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,23 @@
5050
<artifactId>powertools-serialization</artifactId>
5151
<version>${project.version}</version>
5252
</dependency>
53+
<dependency>
54+
<groupId>software.amazon.lambda</groupId>
55+
<artifactId>powertools-common</artifactId>
56+
<version>${project.version}</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>software.amazon.awssdk</groupId>
60+
<artifactId>sdk-core</artifactId>
61+
<scope>provided</scope>
62+
</dependency>
5363

5464
<!-- Test dependencies -->
5565
<dependency>
5666
<groupId>org.junit.jupiter</groupId>
5767
<artifactId>junit-jupiter-api</artifactId>
5868
<scope>test</scope>
5969
</dependency>
60-
<dependency>
61-
<groupId>org.slf4j</groupId>
62-
<artifactId>slf4j-simple</artifactId>
63-
<version>2.0.17</version>
64-
<scope>test</scope>
65-
</dependency>
6670
<dependency>
6771
<groupId>org.assertj</groupId>
6872
<artifactId>assertj-core</artifactId>
@@ -83,6 +87,11 @@
8387
<artifactId>slf4j-simple</artifactId>
8488
<scope>test</scope>
8589
</dependency>
90+
<dependency>
91+
<groupId>software.amazon.awssdk</groupId>
92+
<artifactId>s3</artifactId>
93+
<scope>test</scope>
94+
</dependency>
8695
</dependencies>
8796

88-
</project>
97+
</project>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates.
3+
* Licensed under the Apache License, Version 2.0 (the
4+
* "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*
13+
*/
14+
package software.amazon.lambda.powertools.batch.internal;
15+
16+
import software.amazon.awssdk.core.SdkRequest;
17+
import software.amazon.awssdk.core.interceptor.Context;
18+
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
19+
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
20+
import software.amazon.lambda.powertools.common.internal.UserAgentConfigurator;
21+
22+
/**
23+
* Global interceptor that configures the User-Agent for all AWS SDK clients
24+
* when the powertools-batch module is on the classpath.
25+
*/
26+
public final class BatchUserAgentInterceptor implements ExecutionInterceptor {
27+
static {
28+
UserAgentConfigurator.configureUserAgent("batch");
29+
}
30+
31+
@Override
32+
public SdkRequest modifyRequest(Context.ModifyRequest context, ExecutionAttributes executionAttributes) {
33+
// This is a no-op interceptor. We use this class to configure the PT User-Agent in the static block. It is
34+
// loaded by AWS SDK Global Interceptors.
35+
return context.request();
36+
}
37+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
software.amazon.lambda.powertools.batch.internal.BatchUserAgentInterceptor
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates.
3+
* Licensed under the Apache License, Version 2.0 (the
4+
* "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*
13+
*/
14+
package software.amazon.lambda.powertools.batch.internal;
15+
16+
import org.junit.jupiter.api.Test;
17+
import software.amazon.awssdk.regions.Region;
18+
import software.amazon.awssdk.services.s3.S3Client;
19+
20+
import static org.assertj.core.api.Assertions.assertThat;
21+
22+
class BatchUserAgentInterceptorTest {
23+
24+
@Test
25+
void shouldConfigureUserAgentWhenCreatingAwsSdkClient() {
26+
// WHEN creating an AWS SDK client, the interceptor should be loaded
27+
// We use S3 client but it can be any arbitrary AWS SDK client
28+
S3Client.builder().region(Region.US_EAST_1).build();
29+
30+
// THEN the user agent system property should be set
31+
String userAgent = System.getProperty("sdk.ua.appId");
32+
assertThat(userAgent).contains("PT/BATCH/");
33+
}
34+
}

powertools-cloudformation/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
<groupId>software.amazon.awssdk</groupId>
4343
<artifactId>url-connection-client</artifactId>
4444
</dependency>
45+
<dependency>
46+
<groupId>software.amazon.awssdk</groupId>
47+
<artifactId>sdk-core</artifactId>
48+
</dependency>
4549
<dependency>
4650
<groupId>com.amazonaws</groupId>
4751
<artifactId>aws-lambda-java-core</artifactId>
@@ -58,6 +62,11 @@
5862
<groupId>org.aspectj</groupId>
5963
<artifactId>aspectjrt</artifactId>
6064
</dependency>
65+
<dependency>
66+
<groupId>software.amazon.lambda</groupId>
67+
<artifactId>powertools-common</artifactId>
68+
<version>${project.version}</version>
69+
</dependency>
6170

6271
<!-- Test dependencies -->
6372
<dependency>
@@ -102,6 +111,11 @@
102111
<type>test-jar</type>
103112
<scope>test</scope>
104113
</dependency>
114+
<dependency>
115+
<groupId>software.amazon.awssdk</groupId>
116+
<artifactId>s3</artifactId>
117+
<scope>test</scope>
118+
</dependency>
105119
</dependencies>
106120

107121
<profiles>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates.
3+
* Licensed under the Apache License, Version 2.0 (the
4+
* "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*
13+
*/
14+
package software.amazon.lambda.powertools.cloudformation.internal;
15+
16+
import software.amazon.awssdk.core.SdkRequest;
17+
import software.amazon.awssdk.core.interceptor.Context;
18+
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
19+
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
20+
import software.amazon.lambda.powertools.common.internal.UserAgentConfigurator;
21+
22+
/**
23+
* Global interceptor that configures the User-Agent for all AWS SDK clients
24+
* when the powertools-cloudformation module is on the classpath.
25+
*/
26+
public final class CloudformationUserAgentInterceptor implements ExecutionInterceptor {
27+
static {
28+
UserAgentConfigurator.configureUserAgent("cloudformation");
29+
}
30+
31+
@Override
32+
public SdkRequest modifyRequest(Context.ModifyRequest context, ExecutionAttributes executionAttributes) {
33+
// This is a no-op interceptor. We use this class to configure the PT User-Agent in the static block. It is
34+
// loaded by AWS SDK Global Interceptors.
35+
return context.request();
36+
}
37+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
software.amazon.lambda.powertools.cloudformation.internal.CloudformationUserAgentInterceptor
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates.
3+
* Licensed under the Apache License, Version 2.0 (the
4+
* "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*
13+
*/
14+
package software.amazon.lambda.powertools.cloudformation.internal;
15+
16+
import org.junit.jupiter.api.Test;
17+
import software.amazon.awssdk.regions.Region;
18+
import software.amazon.awssdk.services.s3.S3Client;
19+
20+
import static org.assertj.core.api.Assertions.assertThat;
21+
22+
class CloudformationUserAgentInterceptorTest {
23+
24+
@Test
25+
void shouldConfigureUserAgentWhenCreatingAwsSdkClient() {
26+
// WHEN creating an AWS SDK client, the interceptor should be loaded
27+
// We use S3 client but it can be any arbitrary AWS SDK client
28+
S3Client.builder().region(Region.US_EAST_1).build();
29+
30+
// THEN the user agent system property should be set
31+
String userAgent = System.getProperty("sdk.ua.appId");
32+
assertThat(userAgent).contains("PT/CLOUDFORMATION/");
33+
}
34+
}

powertools-idempotency/powertools-idempotency-dynamodb/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
</exclusion>
5858
</exclusions>
5959
</dependency>
60+
<dependency>
61+
<groupId>software.amazon.awssdk</groupId>
62+
<artifactId>sdk-core</artifactId>
63+
</dependency>
6064
<dependency>
6165
<groupId>org.crac</groupId>
6266
<artifactId>crac</artifactId>
@@ -94,6 +98,11 @@
9498
<version>2.2.0</version>
9599
<scope>test</scope>
96100
</dependency>
101+
<dependency>
102+
<groupId>software.amazon.awssdk</groupId>
103+
<artifactId>s3</artifactId>
104+
<scope>test</scope>
105+
</dependency>
97106
</dependencies>
98107

99108
<profiles>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2023 Amazon.com, Inc. or its affiliates.
3+
* Licensed under the Apache License, Version 2.0 (the
4+
* "License"); you may not use this file except in compliance
5+
* with the License. You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
* limitations under the License.
12+
*
13+
*/
14+
package software.amazon.lambda.powertools.idempotency.dynamodb.internal;
15+
16+
import software.amazon.awssdk.core.SdkRequest;
17+
import software.amazon.awssdk.core.interceptor.Context;
18+
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
19+
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
20+
import software.amazon.lambda.powertools.common.internal.UserAgentConfigurator;
21+
22+
/**
23+
* Global interceptor that configures the User-Agent for all AWS SDK clients
24+
* when the powertools-idempotency-dynamodb module is on the classpath.
25+
*/
26+
public final class IdempotencyDynamodbUserAgentInterceptor implements ExecutionInterceptor {
27+
static {
28+
UserAgentConfigurator.configureUserAgent("idempotency-dynamodb");
29+
}
30+
31+
@Override
32+
public SdkRequest modifyRequest(Context.ModifyRequest context, ExecutionAttributes executionAttributes) {
33+
// This is a no-op interceptor. We use this class to configure the PT User-Agent in the static block. It is
34+
// loaded by AWS SDK Global Interceptors.
35+
return context.request();
36+
}
37+
}

0 commit comments

Comments
 (0)