Skip to content

Commit

Permalink
LIBS-531 - Use sample credentials in AmazonS3Helper (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
hennes-maertins authored and Henrik Adamski committed Nov 14, 2019
1 parent bc48434 commit a5453ac
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: mvn surefire:test

- name: integration-tests
run: mvn jacoco:restore-instrumented-classes failsafe:integration-test failsafe:verify
run: mvn -DskipUTs -Dgpg.skip=true jacoco:restore-instrumented-classes verify

- name: sonar-analyse
env:
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/review.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name: review

on:
push:
branches:
- '*'
- '!master'
pull_request:
types: [opened, synchronize]

jobs:
build:
Expand Down Expand Up @@ -33,18 +31,20 @@ jobs:
run: mvn surefire:test

- name: integration-tests
run: mvn jacoco:restore-instrumented-classes failsafe:integration-test failsafe:verify
run: mvn -DskipUTs -Dgpg.skip=true jacoco:restore-instrumented-classes verify

- name: sonar-analyse
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
export GITHUB_PULL_REQUEST=$(cut -d / -f 3 <(echo ${GITHUB_REF}))
export SONAR_ORGANIZATION=$(echo ${GITHUB_REPOSITORY} | cut -d / -f 1)
mvn sonar:sonar \
-Dsonar.host.url=https://sonarcloud.io/ \
-Dsonar.login=${{ secrets.SONAR_TOKEN }} \
-Dsonar.organization=${SONAR_ORGANIZATION} \
-Dsonar.projectKey=${GITHUB_REPOSITORY//\//_} \
-Dsonar.pullrequest.key=${GITHUB_PULL_REQUEST} \
-Dsonar.java.binaries=./target/classes
- name: pom-analyse
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<dependency>
<groupId>com.avides.springboot.testcontainer</groupId>
<artifactId>springboot-testcontainer-awss3mock</artifactId>
<version>1.0.0-RC1</version>
<version>1.0.0-RC2</version>
<scope>test</scope>
</dependency>
```
Expand Down Expand Up @@ -60,3 +60,4 @@ Example:
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(s3HttpEndpoint, Regions.EU_CENTRAL_1.getName()))
.build();`

The `AmazonS3Helper` class can be used to build `AmazonS3` objects with sample credentials.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>com.avides.springboot.testcontainer</groupId>
<artifactId>springboot-testcontainer-awss3mock</artifactId>
<version>1.0.0-RC1</version>
<version>1.0.0-RC2</version>

<name>springboot-testcontainer-awss3mock</name>
<description>AwsS3Mock test-container</description>
Expand Down Expand Up @@ -98,7 +98,7 @@
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.671</version>
<version>1.11.674</version>
</dependency>

<!-- Testing -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,47 @@

import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;

import lombok.experimental.UtilityClass;

/**
* This class provides builder methods to construct {@link AmazonS3} clients for use with a mocked S3.
* <p>
* A Client built by one of those methods explicitly uses sample credentials to avoid bad performance of the AWS-SDK.
*/
@UtilityClass
public class AmazonS3Helper
{
/**
* Returns a new built {@link AmazonS3} client with sample credentials, region "us-east-1" and path-style access.
*
* @param endpoint of the mocked S3
* @param protocol used for communication with the mocked S3
* @return a new built {@link AmazonS3} client
*/
public static AmazonS3 buildAmazonS3(String endpoint, Protocol protocol)
{
return buildAmazonS3(endpoint, protocol, "us-east-1");
}

/**
* Returns a new built {@link AmazonS3} client with sample credentials and path-style access.
*
* @param endpoint of the mocked S3
* @param protocol used for communication with the mocked S3
* @param region used by the returned {@link AmazonS3}
* @return a new built {@link AmazonS3} client
*/
public static AmazonS3 buildAmazonS3(String endpoint, Protocol protocol, String region)
{
return AmazonS3ClientBuilder.standard()
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, "us-east-1"))
.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("acesskey", "secretkey")))
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, region))
.withPathStyleAccessEnabled(Boolean.TRUE)
.withClientConfiguration(new ClientConfiguration().withProtocol(protocol))
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public AwsS3MockContainer(String service, ConfigurableEnvironment environment, A
}

@Override
protected boolean isContainerReady(AwsS3MockProperties properties)
protected boolean isContainerReady(AwsS3MockProperties props)
{
AmazonS3 amazonS3 = AmazonS3Helper.buildAmazonS3(generateProtocolEndpoint(Protocol.HTTP), Protocol.HTTP);
amazonS3.createBucket("testbucket");
Expand Down

0 comments on commit a5453ac

Please sign in to comment.