diff --git a/src/main/java/org/vcell/vcellfiji/N5ImageHandler.java b/src/main/java/org/vcell/vcellfiji/N5ImageHandler.java index 1c62954..a8df0a5 100644 --- a/src/main/java/org/vcell/vcellfiji/N5ImageHandler.java +++ b/src/main/java/org/vcell/vcellfiji/N5ImageHandler.java @@ -174,17 +174,32 @@ public void loadN5Dataset(String selectedDataset) throws IOException { public void createS3Client(String url, HashMap credentials, HashMap endpoint){ AmazonS3ClientBuilder s3ClientBuilder = AmazonS3ClientBuilder.standard(); URI uri = URI.create(url); - String defaultRegion = "site2-low"; + + if(credentials != null){ + s3ClientBuilder.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(credentials.get("AccessKey"), credentials.get("SecretKey")))); + } // believe that it's a s3 URL try{ AmazonS3URI s3URI = new AmazonS3URI(uri); this.s3ObjectKey = s3URI.getKey(); this.bucketName = s3URI.getBucket(); - defaultRegion = s3URI.getRegion(); if(s3URI.isPathStyle()){ s3ClientBuilder.withPathStyleAccessEnabled(true); } + if(endpoint != null){ + s3ClientBuilder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint.get("Endpoint"), endpoint.get("Region"))); + this.s3Client = s3ClientBuilder.build(); + return; + } + // if nothing is given, default user and return so that code after if statement does not execute + if(endpoint == null && credentials == null){ + this.s3Client = AmazonS3ClientBuilder.standard().withRegion(s3URI.getRegion()).withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials())).build(); + return; + } + //creds not null, but region is + this.s3Client = s3ClientBuilder.withRegion(s3URI.getRegion()).build(); + return; } // otherwise assume it is one of our URLs // http://vcell:8000/bucket/object/object2 @@ -193,30 +208,10 @@ public void createS3Client(String url, HashMap credentials, Hash this.s3ObjectKey = pathSubStrings[2]; this.bucketName = pathSubStrings[1]; s3ClientBuilder.withPathStyleAccessEnabled(true); - s3ClientBuilder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(uri.getScheme() + "://" + uri.getAuthority(), defaultRegion)); - if(credentials != null){ - s3ClientBuilder.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(credentials.get("AccessKey"), credentials.get("SecretKey")))); - } - this.s3Client = s3ClientBuilder.build(); - return; - } - - if(credentials != null){ - s3ClientBuilder.withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(credentials.get("AccessKey"), credentials.get("SecretKey")))); - } - if(endpoint != null){ - s3ClientBuilder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint.get("Endpoint"), endpoint.get("Region"))); + s3ClientBuilder.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(uri.getScheme() + "://" + uri.getAuthority(), "site2-low")); this.s3Client = s3ClientBuilder.build(); return; } - // if nothing is given, default user and return so that code after if statement does not execute - if(endpoint == null && credentials == null){ - this.s3Client = AmazonS3ClientBuilder.standard().withRegion(defaultRegion).withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials())).build(); - return; - } - - //creds not null, but region is - this.s3Client = s3ClientBuilder.withRegion(defaultRegion).build(); } diff --git a/src/test/java/org/vcell/vcellfiji/N5ImageHandlerTest.java b/src/test/java/org/vcell/vcellfiji/N5ImageHandlerTest.java index 92f9a88..b7b08ab 100644 --- a/src/test/java/org/vcell/vcellfiji/N5ImageHandlerTest.java +++ b/src/test/java/org/vcell/vcellfiji/N5ImageHandlerTest.java @@ -65,22 +65,22 @@ public void testS3Client() throws IOException { credentials.put("AccessKey", "jj"); credentials.put("SecretKey", "jj"); - final String s3ProxyURL = "/" + this.n5FileName; + final String s3ProxyURI = "http://localhost:4000/" + this.n5FileName; N5ImageHandler n5ImageHandler = new N5ImageHandler(); // Environment variables are set in github actions VM -// n5ImageHandler.createS3Client(s3ProxyURL, null, null); -// this.remoteN5ImgPlusTests(n5ImageHandler); + n5ImageHandler.createS3Client(s3ProxyURI, null, null); + this.remoteN5ImgPlusTests(n5ImageHandler); - n5ImageHandler.createS3Client(s3ProxyURL, null, s3Endpoint); + n5ImageHandler.createS3Client(s3ProxyURI, null, s3Endpoint); this.remoteN5ImgPlusTests(n5ImageHandler); -// n5ImageHandler.createS3Client(s3ProxyURL, credentials, null); -// this.remoteN5ImgPlusTests(n5ImageHandler); + n5ImageHandler.createS3Client(s3ProxyURI, credentials, null); + this.remoteN5ImgPlusTests(n5ImageHandler); - n5ImageHandler.createS3Client(s3ProxyURL, credentials, s3Endpoint); + n5ImageHandler.createS3Client(s3ProxyURI, credentials, s3Endpoint); this.remoteN5ImgPlusTests(n5ImageHandler); }