use of org.jclouds.s3.S3Client in project flyway by flyway.
the class AwsS3Scanner method scanForResources.
/**
* Scans S3 for the resources. In AWS SDK v2, only the region that the client is configured with can be used.
* The format of the path is expected to be {@code s3:{bucketName}/{optional prefix}}.
*
* @param location The location in S3 to start searching. Subdirectories are also searched.
* @return The resources that were found.
*/
@Override
public Collection<LoadableResource> scanForResources(final Location location) {
String bucketName = getBucketName(location);
String prefix = getPrefix(bucketName, location.getPath());
S3Client s3Client = S3ClientFactory.getClient();
try {
ListObjectsV2Request.Builder builder = ListObjectsV2Request.builder().bucket(bucketName).prefix(prefix);
ListObjectsV2Request request = builder.build();
ListObjectsV2Response listObjectResult = s3Client.listObjectsV2(request);
return getLoadableResources(bucketName, listObjectResult);
} catch (SdkClientException e) {
if (throwOnMissingLocations) {
throw new FlywayException("Could not access s3 location:" + bucketName + prefix + " due to error: " + e.getMessage());
}
LOG.error("Skipping s3 location:" + bucketName + prefix + " due to error: " + e.getMessage());
return Collections.emptyList();
}
}
Aggregations