Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FORCE_PATH_STYLE into the defaults of S3NioSpiConfiguration in order to allow it to be modified via environment variables #469

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public class S3NioSpiConfiguration extends HashMap<String, Object> {
* The name of the force path style property
*/
public static final String S3_SPI_FORCE_PATH_STYLE_PROPERTY = "s3.spi.force-path-style";
/**
* The default value of the force path style property
*/
public static final boolean S3_SPI_FORCE_PATH_STYLE_DEFAULT = false;
/**
* The default value of the credentials property
*/
Expand Down Expand Up @@ -98,6 +102,7 @@ public S3NioSpiConfiguration(Map<String, ?> overrides) {
put(S3_SPI_READ_MAX_FRAGMENT_NUMBER_PROPERTY, String.valueOf(S3_SPI_READ_MAX_FRAGMENT_NUMBER_DEFAULT));
put(S3_SPI_READ_MAX_FRAGMENT_SIZE_PROPERTY, String.valueOf(S3_SPI_READ_MAX_FRAGMENT_SIZE_DEFAULT));
put(S3_SPI_ENDPOINT_PROTOCOL_PROPERTY, S3_SPI_ENDPOINT_PROTOCOL_DEFAULT);
put(S3_SPI_FORCE_PATH_STYLE_PROPERTY, String.valueOf(S3_SPI_FORCE_PATH_STYLE_DEFAULT));

//
// With the below we pick existing environment variables and system
Expand Down Expand Up @@ -286,7 +291,7 @@ public S3NioSpiConfiguration withForcePathStyle(Boolean forcePathStyle) {
if (forcePathStyle == null) {
remove(S3_SPI_FORCE_PATH_STYLE_PROPERTY);
} else {
put(S3_SPI_FORCE_PATH_STYLE_PROPERTY, forcePathStyle);
put(S3_SPI_FORCE_PATH_STYLE_PROPERTY, String.valueOf(forcePathStyle));
}

return this;
Expand Down Expand Up @@ -387,7 +392,8 @@ public String getBucketName() {
}

public boolean getForcePathStyle() {
return (boolean) getOrDefault(S3_SPI_FORCE_PATH_STYLE_PROPERTY, false);
return Boolean.parseBoolean((String) getOrDefault(S3_SPI_FORCE_PATH_STYLE_PROPERTY,
String.valueOf(S3_SPI_FORCE_PATH_STYLE_DEFAULT)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,15 @@ public void withAndGetBucketName() {

@Test
public void withAndGetForcePathStyle() {
then(config).doesNotContainKey(S3_SPI_FORCE_PATH_STYLE_PROPERTY);
then(config).contains(entry(S3_SPI_FORCE_PATH_STYLE_PROPERTY, "false"));
then(config.withForcePathStyle(true)).isSameAs(config);
then(config).contains(entry(S3_SPI_FORCE_PATH_STYLE_PROPERTY, true));
then(config).contains(entry(S3_SPI_FORCE_PATH_STYLE_PROPERTY, "true"));
then(config.getForcePathStyle()).isTrue();
then(config.withForcePathStyle(false).getForcePathStyle()).isFalse();

Map<String, Object> map = new HashMap<>(); config = new S3NioSpiConfiguration(map);
then(config.getForcePathStyle()).isFalse();
map.put(S3_SPI_FORCE_PATH_STYLE_PROPERTY, true); config = new S3NioSpiConfiguration(map);
map.put(S3_SPI_FORCE_PATH_STYLE_PROPERTY, "true"); config = new S3NioSpiConfiguration(map);
then(config .getForcePathStyle()).isTrue();
map.remove(S3_SPI_FORCE_PATH_STYLE_PROPERTY); // same S3NioSpiConfiguration on purpose
then(config.getForcePathStyle()).isTrue();
Expand Down