Skip to content

Commit

Permalink
Adds fix for the getHost problem
Browse files Browse the repository at this point in the history
  • Loading branch information
ncordon committed Apr 20, 2022
1 parent 8ce346c commit 80e800d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions core/src/main/java/apoc/util/s3/S3ParamsExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ public static S3Params extract(String url) throws IllegalArgumentException {
}
}

// endpoint
String endpoint = uri.getHost();
// We have to use the getAuthority here instead of getHost, because addresses
// like us-east-1.127.0.0.1:55220 would return null for the later one.
// The downside is we have to clean the credentials preceding the @ if they are there,
// which .getHost would not return
String endpoint = uri.getAuthority();
int atIndex = endpoint.indexOf( "@" );
if (atIndex != -1)
endpoint = endpoint.substring( atIndex + 1 );

Integer slashIndex = uri.getPath().indexOf("/", 1);
String key;
Expand Down Expand Up @@ -94,8 +100,8 @@ public static S3Params extract(String url) throws IllegalArgumentException {
}
}

if (uri.getPort() != 80 && uri.getPort() != 443 && uri.getPort() > 0) {
endpoint += ":" + uri.getPort();
if (endpoint != null) {
endpoint = endpoint.replaceAll( ":443", "").replaceAll( ":80", "" );
}

if (Objects.nonNull(endpoint) && endpoint.isEmpty()) {
Expand Down

0 comments on commit 80e800d

Please sign in to comment.