desruisseaux commented on code in PR #40:
URL: https://github.com/apache/sis/pull/40#discussion_r2832356281
##########
endorsed/src/org.apache.sis.cloud.aws/main/org/apache/sis/cloud/aws/s3/FileService.java:
##########
@@ -237,66 +333,112 @@ final class Creator implements Function<String,
ClientFileSystem> {
* Removes the given file system from the cache.
* This method is invoked after the file system has been closed.
*/
- final void dispose(String identifier) {
+ final void dispose(ClientFileSystemKey identifier) {
if (identifier == null) {
- identifier = DEFAULT_ACCESS_KEY;
+ identifier = new ClientFileSystemKey(DEFAULT_ACCESS_KEY,
DEFAULT_HOST_KEY, DEFAULT_PORT_KEY, DEFAULT_IS_HTTPS);
}
fileSystems.remove(identifier);
}
/**
- * Returns the file system associated to the {@link #DEFAULT_ACCESS_KEY}.
+ * Returns the file system associated to the {@link #DEFAULT_ACCESS_KEY},
{@link #DEFAULT_HOST_KEY}, {@link #DEFAULT_PORT_KEY} and {@link
#DEFAULT_IS_HTTPS}.
*
* @throws SdkException if the file system cannot be created.
*/
private ClientFileSystem getDefaultFileSystem() {
- return fileSystems.computeIfAbsent(DEFAULT_ACCESS_KEY, (key) -> new
ClientFileSystem(this, S3Client.create()));
+ return fileSystems.computeIfAbsent(new
ClientFileSystemKey(DEFAULT_ACCESS_KEY, DEFAULT_HOST_KEY, DEFAULT_PORT_KEY,
DEFAULT_IS_HTTPS), (key) ->
+ new ClientFileSystem(this, S3Client.create(), null));
+ }
+
+ /**
+ * Returns the file system associated to the {@link #DEFAULT_HOST_KEY} and
{@link #DEFAULT_PORT_KEY}.
+ *
+ * @param accessKey the access key
+ * @throws SdkException if the file system cannot be created.
+ */
+ private ClientFileSystem getDefaultFileSystem(String accessKey) {
+ return fileSystems.computeIfAbsent(
+ new ClientFileSystemKey(accessKey, DEFAULT_HOST_KEY,
DEFAULT_PORT_KEY, DEFAULT_IS_HTTPS), (key) -> new ClientFileSystem(this,
S3Client.create(), key.accessKey));
+ }
+
+ /**
+ * Returns the file system associated to the {@link #DEFAULT_ACCESS_KEY}.
+ *
+ * @param host the host
+ * @param port the port
+ * @throws SdkException if the file system cannot be created.
+ */
+ private ClientFileSystem getDefaultFileSystem(String host, Integer port) {
+ return fileSystems.computeIfAbsent(
+ new ClientFileSystemKey(DEFAULT_ACCESS_KEY, host, port,
DEFAULT_IS_HTTPS), (key) ->
+ new ClientFileSystem(this, null, key.host, key.port,
key.isHttps, key.accessKey, null, null));
+ }
+
+ /**
+ * Returns the file system associated to the {@link #DEFAULT_ACCESS_KEY}.
+ *
+ * @param host the host
+ * @param port the port
+ * @param isHttps the protocol
+ * @throws SdkException if the file system cannot be created.
+ */
+ private ClientFileSystem getDefaultFileSystem(String host, Integer port,
boolean isHttps) {
+ return fileSystems.computeIfAbsent(
+ new ClientFileSystemKey(DEFAULT_ACCESS_KEY, host, port,
isHttps), (key) ->
+ new ClientFileSystem(this, null, key.host, key.port,
key.isHttps, key.accessKey, null, null));
}
/**
* Returns a reference to a file system that was created by the {@link
#newFileSystem(URI, Map)} method.
* If the file system has not been created or has been closed,
* then this method throws {@link FileSystemNotFoundException}.
*
- * @param uri a <abbr>URI</abbr> of the form {@code
"s3://accessKey@bucket/file"}.
+ * @param uri a <abbr>URI</abbr> of the form {@code
"s3://accessKey@bucket/file"} or {@code "s3://accessKey@host:port/bucket/key"}.
* @return the file system previously created by {@link
#newFileSystem(URI, Map)}.
* @throws IllegalArgumentException if the URI is not supported by this
provider.
* @throws FileSystemNotFoundException if the file system does not exist
or has been closed.
*/
@Override
public FileSystem getFileSystem(final URI uri) {
final String accessKey = getAccessKey(uri);
- if (accessKey == null) {
+ final String host = uri.getHost();
+ final int port = uri.getPort();
+
+ if (accessKey == null && port > -1) {
+ // No access key, but host and port are defined => Self Hosted
+ return getDefaultFileSystem(host, port);
+ } else if (accessKey == null && port < 0) {
+ // No access key, no host, no port => AWS S3
return getDefaultFileSystem();
+ } else if(accessKey != null && port < 0) {
Review Comment:
Space after `if`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]