Skip to content

Commit

Permalink
S3 Connect
Browse files Browse the repository at this point in the history
- Made its region dynamic
- Fixed no endpoint and credentials branch
- Remove unneeded key in hash map
  • Loading branch information
AvocadoMoon committed Oct 3, 2023
1 parent d851d18 commit 97ee3b0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
13 changes: 4 additions & 9 deletions src/main/java/org/vcell/vcellfiji/N5ImageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,14 @@ public void loadN5Dataset(String selectedDataset) throws IOException {
public void createS3Client(String url, HashMap<String, String> credentials, HashMap<String, String> endpoint){
AmazonS3ClientBuilder s3ClientBuilder = AmazonS3ClientBuilder.standard();
URI uri = URI.create(url);
String defaultRegion = "site2-low";

// believe that it's a s3 URL
try{
AmazonS3URI s3URI = new AmazonS3URI(uri);
this.s3ObjectKey = s3URI.getKey();
this.bucketName = s3URI.getBucket();
defaultRegion = s3URI.getRegion();
}
// otherwise assume it is one of our URLs
catch (IllegalArgumentException e){
Expand All @@ -215,18 +217,11 @@ public void createS3Client(String url, HashMap<String, String> credentials, Hash
}
// if nothing is given, default user and return so that code after if statement does not execute
if(endpoint == null && credentials == null){
s3ClientBuilder
.withRegion("site-low")
.withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials()))
.withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration("", ""))
.build();

this.s3Client = AmazonS3ClientBuilder.standard().withRegion("site-low").withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials())).build();
this.s3Client = AmazonS3ClientBuilder.standard().withRegion(defaultRegion).withCredentials(new AWSStaticCredentialsProvider(new AnonymousAWSCredentials())).build();
return;
}

// TODO: hard coding a region is not a solution
this.s3Client = s3ClientBuilder.withRegion("site2-low").build();
this.s3Client = s3ClientBuilder.withRegion(defaultRegion).build();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public HashMap<String, String> returnEndpoint(){
}
hashMap.put("Endpoint", this.s3EndpointTextField.getText());
hashMap.put("Region", this.s3RegionTextField.getText());
hashMap.put("Bucket", null);
return hashMap;
}

Expand Down

0 comments on commit 97ee3b0

Please sign in to comment.