Skip to content

Commit

Permalink
Add FORCE_PATH_STYLE into the defaults of S3NioSpiConfiguration in …
Browse files Browse the repository at this point in the history
…order to allow it to be modified via environment variables (#469)

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

* Update S3NioSpiConfiguration.java

Shortens line to make checkstyle happy

---------

Co-authored-by: Mark Schreiber <[email protected]>
  • Loading branch information
oeph and markjschreiber committed May 28, 2024
1 parent d2ed92c commit cec9557
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
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

0 comments on commit cec9557

Please sign in to comment.