Skip to content

Commit

Permalink
Merge pull request #9 from levigo/bugfix/JF-1186_path_style_config
Browse files Browse the repository at this point in the history
fix(JF-1186): add property pathStyleAccessEnabled
  • Loading branch information
welschsn authored Nov 14, 2024
2 parents 658f441 + c4f5da4 commit 3720d7c
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 28 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@
.idea
**/*.iml
**/vcs.xml
/src/test/resources/application-test.yml
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<!-- dependencies -->
<aws-java-sdk-s3.version>1.12.750</aws-java-sdk-s3.version>
<slf4j.version>1.7.36</slf4j.version>
<aws-java-sdk-s3.version>1.12.778</aws-java-sdk-s3.version>
<slf4j.version>2.0.16</slf4j.version>
<jaxb.version>2.3.1</jaxb.version>
<junit.version>5.10.2</junit.version>
<snakeyml.version>2.2</snakeyml.version>
<junit.version>5.11.3</junit.version>
<snakeyml.version>2.3</snakeyml.version>
<!-- plugins -->
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-assembly-plugin.version>3.7.1</maven-assembly-plugin.version>
<maven-surefire-plugin.version>3.3.0</maven-surefire-plugin.version>
<maven-surefire-plugin.version>3.5.2</maven-surefire-plugin.version>
<!-- sonarcloud -->
<sonar.organization>levigo</sonar.organization>
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
Expand Down
55 changes: 40 additions & 15 deletions src/main/java/com/jadice/flow/client/s3/ConfigProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.net.URI;
import java.util.Objects;

import com.amazonaws.services.s3.model.Region;

/**
* Configuration object that contains all the necessary connection information for accessing the s3 storage.
*/
Expand All @@ -21,6 +19,8 @@ public class ConfigProperties {
String protocol;
boolean trustSelfSigned = false;
boolean trustAll = false;
// prefer the path style access, as minio uses that mode
boolean pathStyleAccessEnabled = true;

public ConfigProperties() {}

Expand All @@ -30,18 +30,33 @@ public ConfigProperties( //
final String region, //
final String accessKey, //
final String secretKey, //
final String protocol ,//
final String protocol, //
final boolean trustSelfSigned, //
final boolean trustAll //
) {
this.endpoint = endpoint;
this.bucket = bucket;
this.region = region;
this.accessKey = accessKey;
this.secretKey = secretKey;
this.protocol = protocol;
this.trustSelfSigned = trustSelfSigned;
this.trustAll = trustAll;
this(endpoint, bucket, region, accessKey, secretKey, protocol, trustSelfSigned, trustAll, true);
}

public ConfigProperties( //
final URI endpoint, //
final String bucket, //
final String region, //
final String accessKey, //
final String secretKey, //
final String protocol, //
final boolean trustSelfSigned, //
final boolean trustAll, //
final boolean pathStyleAccessEnabled //
) {
this.endpoint = endpoint;
this.bucket = bucket;
this.region = region;
this.accessKey = accessKey;
this.secretKey = secretKey;
this.protocol = protocol;
this.trustSelfSigned = trustSelfSigned;
this.trustAll = trustAll;
this.pathStyleAccessEnabled = pathStyleAccessEnabled;
}

public String getAccessKey() {
Expand Down Expand Up @@ -108,20 +123,30 @@ public void setTrustAll(boolean trustAll) {
this.trustAll = trustAll;
}

public boolean isPathStyleAccessEnabled() {
return pathStyleAccessEnabled;
}

public void setPathStyleAccessEnabled(boolean pathStyleAccessEnabled) {
this.pathStyleAccessEnabled = pathStyleAccessEnabled;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ConfigProperties that = (ConfigProperties) o;
return trustSelfSigned == that.trustSelfSigned && trustAll == that.trustAll && Objects.equals(endpoint,
that.endpoint) && Objects.equals(bucket, that.bucket) && region == that.region && Objects.equals(accessKey,
that.accessKey) && Objects.equals(secretKey, that.secretKey) && Objects.equals(protocol, that.protocol);
return trustSelfSigned == that.trustSelfSigned && trustAll == that.trustAll && pathStyleAccessEnabled == that.pathStyleAccessEnabled && Objects.equals(
endpoint, that.endpoint) && Objects.equals(bucket, that.bucket) && Objects.equals(region,
that.region) && Objects.equals(accessKey, that.accessKey) && Objects.equals(secretKey,
that.secretKey) && Objects.equals(protocol, that.protocol);
}

@Override
public int hashCode() {
return Objects.hash(endpoint, bucket, region, accessKey, secretKey, protocol, trustSelfSigned, trustAll);
return Objects.hash(endpoint, bucket, region, accessKey, secretKey, protocol, trustSelfSigned, trustAll,
pathStyleAccessEnabled);
}
}
5 changes: 2 additions & 3 deletions src/main/java/com/jadice/flow/client/s3/S3ClientBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public AmazonS3 build(final ConfigProperties configProperties) {
new AwsClientBuilder.EndpointConfiguration(configProperties.getEndpoint().toString(),
region)).withCredentials(new AWSStaticCredentialsProvider(
new BasicAWSCredentials(configProperties.getAccessKey(), configProperties.getSecretKey())));
// prefer the path style access, as minio uses that mode
builder.setPathStyleAccessEnabled(true);
builder.setPathStyleAccessEnabled(configProperties.isPathStyleAccessEnabled());

final ClientConfiguration clientConfiguration = new ClientConfiguration();

Expand All @@ -40,7 +39,7 @@ public AmazonS3 build(final ConfigProperties configProperties) {
builder.withClientConfiguration(clientConfiguration.withProtocol(Protocol.HTTP));
} else if (configProperties.isTrustSelfSigned() || configProperties.isTrustAll()) {
// trust self-signed certificates
SSLContext sslContext = null;
SSLContext sslContext;
try {
sslContext = new SSLContextBuilder().loadTrustMaterial(getTrustStrategy(configProperties)).build();
} catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
Expand Down
11 changes: 7 additions & 4 deletions src/test/java/com/jadice/flow/client/s3/S3ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.amazonaws.services.s3.model.S3Object;
import com.amazonaws.services.s3.model.S3ObjectInputStream;

@Disabled
public class S3ClientTest {
private static S3Client s3Client;

Expand All @@ -35,11 +34,12 @@ public static void setupClass() throws IOException {
final Map s3 = (Map) publisher.get("s3");
final String bucket = (String) s3.get("bucket");
final String endpoint = (String) s3.get("endpoint");
final String accessKey = (String) s3.get("access-key");
final String secretKey = (String) s3.get("secret-key");
final String accessKey = (String) s3.get("accessKey");
final String secretKey = (String) s3.get("secretKey");
final String protocol = (String) s3.get("protocol");
final boolean trustSelfSigned = (boolean) s3.get("trustSelfSigned");
final boolean trustAll = (boolean) s3.get("trustAll");
final boolean pathStyleAccessEnabled = (boolean) s3.get("pathStyleAccessEnabled");
final ConfigProperties configProperties = new ConfigProperties( //
URI.create(endpoint), //
bucket, //
Expand All @@ -48,7 +48,8 @@ public static void setupClass() throws IOException {
secretKey, //
protocol, //
trustSelfSigned, //
trustAll //
trustAll, //
pathStyleAccessEnabled
);
s3Client = new S3Client(configProperties, Duration.ofHours(1));
}
Expand All @@ -67,6 +68,7 @@ void test_getIdentifier(String filename, String expected) {
assertTrue(identifier.endsWith(expected));
}

@Disabled
@Test
void test() throws IOException {
try (final InputStream resourceAsStream = this.getClass().getResourceAsStream("/test.txt")) {
Expand All @@ -79,6 +81,7 @@ void test() throws IOException {
}
}

@Disabled
@Test
void test2() throws IOException {
try (final InputStream resourceAsStream = this.getClass().getResourceAsStream("/test.txt")) {
Expand Down
11 changes: 11 additions & 0 deletions src/test/resources/application-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
publisher:
s3:
endpoint: "https://s3.us-east-404.amazonaws.com"
bucket: "s3-java-example"
region: "us-east-404"
accessKey: "1234567890"
secretKey: "abcdefghijklmnopqrstuvwxyz"
protocol: "https"
trustSelfSigned: false
trustAll: false
pathStyleAccessEnabled: true

0 comments on commit 3720d7c

Please sign in to comment.