Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into upstream-main#115
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanofornari committed Sep 19, 2023
2 parents 32682e9 + 0f2a215 commit fd2fc49
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ follow this URI pattern:
```
s3x://[key:secret@]endpoint[:port]/bucket/objectkey
```
Note that in this case the TCP port of the target service must be specified.

If no credentials are given the default AWS configuration mechanism will be used as per
the section above.

Expand All @@ -102,7 +102,7 @@ The same can also be provided when creating a file system:
```
Map<String, String> env = ...;
env.put("s3.spi.endpoint-protocol", "http");
FileSystem fs = FileSystems.newFileSystem("s3://myendpoint.com:1000/mybucket", env);
FileSystem fs = FileSystems.newFileSystem("s3x://myendpoint.com:1000/mybucket", env);
```

## Reading Files
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ dependencies {
testImplementation 'org.mockito:mockito-junit-jupiter:5.5.0'
testImplementation 'com.github.stefanbirkner:system-lambda:1.2.1'

implementation platform('software.amazon.awssdk:bom:2.20.141')
implementation platform('software.amazon.awssdk:bom:2.20.150')

implementation 'software.amazon.awssdk:s3'
implementation 'software.amazon.awssdk:s3-transfer-manager'
implementation 'software.amazon.awssdk.crt:aws-crt:0.25.0'
implementation 'org.slf4j:slf4j-api:2.0.7'
implementation 'software.amazon.awssdk.crt:aws-crt:0.27.1'
implementation 'org.slf4j:slf4j-api:2.0.9'
implementation 'ch.qos.logback:logback-classic:1.4.11'
implementation 'ch.qos.logback:logback-core:1.4.11'
// cannot use caffeine v3 because that requires java 11
Expand Down
46 changes: 46 additions & 0 deletions src/test/java/software/amazon/nio/spi/s3x/S3PathTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package software.amazon.nio.spi.s3x;

import java.lang.reflect.Field;
import java.net.URI;
import java.nio.file.Paths;
import java.util.Map;
import static org.assertj.core.api.BDDAssertions.then;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import software.amazon.nio.spi.s3.S3FileSystem;
import software.amazon.nio.spi.s3.S3FileSystemProvider;
import software.amazon.nio.spi.s3.S3Path;

/**
*
*/
public class S3PathTest {
@BeforeEach
public void before() throws Exception {
Field f = S3FileSystemProvider.class.getDeclaredField("cache");
f.setAccessible(true);
Map cache = (Map)f.get(null);
cache.clear();
}

@Test
public void stripCredentialsAndEndpointNIO() {
then(Paths.get(URI.create("s3x://somewhere.com:1010/bucket/afile.txt")).toString()).isEqualTo("/afile.txt");
then(Paths.get(URI.create("s3x://key:[email protected]:1010/bucket/afile.txt")).toString()).isEqualTo("/afile.txt");
}

@Test
public void stripCredentialsAndEndpoint() throws Exception {
S3XFileSystemProvider provider = new S3XFileSystemProvider();

S3FileSystem fs = provider.newFileSystem(URI.create("s3x://key:[email protected]:1010/bucket"));
then(S3Path.getPath(fs, "s3x://somewhere.com:1010/bucket/afile.txt").toString()).isEqualTo("/afile.txt");
then(S3Path.getPath(fs, "s3x://key:[email protected]:1010/bucket/afile.txt").toString()).isEqualTo("/afile.txt");
provider.closeFileSystem(fs);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2023 ste.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package software.amazon.nio.spi.s3x.util;

import java.net.URI;
import static org.assertj.core.api.BDDAssertions.then;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

/**
*
* @author ste
*/
public class S3XFileSystemInfoTest {

@Test
public void construction() {
S3XFileSystemInfo info = new S3XFileSystemInfo(URI.create("s3://myendpoint/mybucket/something"));
then(info.key()).isEqualTo("myendpoint/mybucket");
then(info.bucket()).isEqualTo("mybucket");
then(info.endpoint()).isEqualTo("myendpoint");
then(info.accessKey()).isNull();
then(info.accessSecret()).isNull();

info = new S3XFileSystemInfo(URI.create("s3://yourendpoint/yourbucket/somethingelse"));
then(info.key()).isEqualTo("yourendpoint/yourbucket");
then(info.bucket()).isEqualTo("yourbucket");
then(info.endpoint()).isEqualTo("yourendpoint");
then(info.accessKey()).isNull();
then(info.accessSecret()).isNull();

try {
new S3XFileSystemInfo(URI.create("s2://myendpoint/Wrong$bucket;name"));
fail("missing sanity check");
} catch (IllegalArgumentException x) {
then(x).hasMessage("Bucket name should not contain uppercase characters");
}

try {
new S3XFileSystemInfo(null);
fail("missing sanity check");
} catch (IllegalArgumentException x) {
then(x).hasMessage("uri can not be null");
}
}

@Test
public void user_info() {
S3XFileSystemInfo info = new S3XFileSystemInfo(URI.create("s3://[email protected]:1111/mybucket"));
then(info.key()).isEqualTo("[email protected]:1111/mybucket");
then(info.bucket()).isEqualTo("mybucket");
then(info.endpoint()).isEqualTo("my.service.com:1111");
then(info.accessKey()).isEqualTo("key");
then(info.accessSecret()).isNull();

info = new S3XFileSystemInfo(URI.create("s3://key:[email protected]/mybucket"));
then(info.key()).isEqualTo("[email protected]/mybucket");
then(info.bucket()).isEqualTo("mybucket");
then(info.endpoint()).isEqualTo("my.service.com");
then(info.accessKey()).isEqualTo("key");
then(info.accessSecret()).isEqualTo("secret");
}
}

0 comments on commit fd2fc49

Please sign in to comment.