Skip to content

Commit

Permalink
Set s3Client as an external value
Browse files Browse the repository at this point in the history
  • Loading branch information
inigo-cobian committed Dec 10, 2024
1 parent f602164 commit 653eac8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ public HMStacCollection setCqlFilter( String cqlFilter ) throws CQLException {
return this;
}

public HMStacCollection setS3Client( S3AsyncClient s3Client ) {
this.s3Client = s3Client;
return this;
}

private SimpleFeatureCollection queryFeatureCollection() throws IOException {
try {
return stacClient.search(search, STACClient.SearchMode.POST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.hortonmachine.gears.utils.RegionMap;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.AwsCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3AsyncClient;
Expand Down Expand Up @@ -78,16 +79,17 @@ public void testReadRasterFromHTTP() throws Exception {
assertNotNull(grid);
}

private S3AsyncClient createDefaultS3Client() {
private S3AsyncClient createDefaultS3Client(Region region) {
AwsCredentials credentials = AwsBasicCredentials.create(
"accessKey",
"secretKey"
);
S3AsyncClient client = S3AsyncClient.builder()
// We use anonymized credentials for this example.
// For testing purposes, add your own credentials and uncomment the following line.
//.credentialsProvider(StaticCredentialsProvider.create(credentials))
.httpClient(NettyNioAsyncHttpClient.builder().build())
.region(Region.US_WEST_2)
.region(region)
.build();
return client;
}
Expand All @@ -98,8 +100,8 @@ public void testReadRasterFromS3() throws Exception {
String assetId = "rainfall";
HMStacAsset hmAsset = new HMStacAsset(assetId, node);
RegionMap regionMap = RegionMap.fromBoundsAndGrid(1640000.0, 1640200.0, 5140000.0, 5140160.0, 20, 16);
S3AsyncClient s3Client = createDefaultS3Client();

S3AsyncClient s3Client = createDefaultS3Client(Region.of("us-west-2"));
GridCoverage2D grid = hmAsset.readRaster(regionMap, s3Client);

assertNotNull(grid);
Expand Down

0 comments on commit 653eac8

Please sign in to comment.