use of com.amazonaws.services.s3.model.Filter in project cloudbreak by hortonworks.
the class AwsPlatformResources method readRegionCoordinates.
private Map<Region, Coordinate> readRegionCoordinates(String displayNames) {
Map<Region, Coordinate> regionCoordinates = new HashMap<>();
try {
RegionCoordinateSpecifications regionCoordinateSpecifications = JsonUtil.readValue(displayNames, RegionCoordinateSpecifications.class);
for (RegionCoordinateSpecification regionCoordinateSpecification : regionCoordinateSpecifications.getItems()) {
Region region = region(regionCoordinateSpecification.getName());
if (!enabledRegions.contains(region)) {
continue;
}
Optional<Entry<Region, DisplayName>> regionEntry = regionDisplayNames.entrySet().stream().filter(e -> e.getKey().getRegionName().equalsIgnoreCase(regionCoordinateSpecification.getName())).findFirst();
regionCoordinates.put(region, coordinate(regionCoordinateSpecification.getLongitude(), regionCoordinateSpecification.getLatitude(), regionCoordinateSpecification.getDisplayName(), regionEntry.isPresent() ? regionEntry.get().getKey().value() : regionCoordinateSpecification.getDisplayName(), regionCoordinateSpecification.isK8sSupported(), regionCoordinateSpecification.getEntitlements()));
}
} catch (IOException ignored) {
return regionCoordinates;
}
return regionCoordinates;
}
use of com.amazonaws.services.s3.model.Filter in project nexus-public by sonatype.
the class AmazonS3Factory method create.
public AmazonS3 create(final BlobStoreConfiguration blobStoreConfiguration) {
NexusS3ClientBuilder builder = NexusS3ClientBuilder.standard();
NestedAttributesMap s3Configuration = blobStoreConfiguration.attributes(CONFIG_KEY);
String accessKeyId = s3Configuration.get(ACCESS_KEY_ID_KEY, String.class);
String secretAccessKey = s3Configuration.get(SECRET_ACCESS_KEY_KEY, String.class);
String region = s3Configuration.get(REGION_KEY, String.class);
String signerType = s3Configuration.get(SIGNERTYPE_KEY, String.class);
String forcePathStyle = s3Configuration.get(FORCE_PATH_STYLE_KEY, String.class);
int maximumConnectionPoolSize = Optional.ofNullable(s3Configuration.get(MAX_CONNECTION_POOL_KEY, String.class)).filter(Predicates.not(Strings2::isBlank)).map(Integer::valueOf).orElse(-1);
AWSCredentialsProvider credentialsProvider = null;
if (!isNullOrEmpty(accessKeyId) && !isNullOrEmpty(secretAccessKey)) {
String sessionToken = s3Configuration.get(SESSION_TOKEN_KEY, String.class);
AWSCredentials credentials = buildCredentials(accessKeyId, secretAccessKey, sessionToken);
String assumeRole = s3Configuration.get(ASSUME_ROLE_KEY, String.class);
credentialsProvider = buildCredentialsProvider(credentials, region, assumeRole);
builder = builder.withCredentials(credentialsProvider);
}
if (!isNullOrEmptyOrDefault(region)) {
String endpoint = s3Configuration.get(ENDPOINT_KEY, String.class);
if (!isNullOrEmpty(endpoint)) {
builder = builder.withEndpointConfiguration(new AmazonS3ClientBuilder.EndpointConfiguration(endpoint, region));
} else {
builder = builder.withRegion(region);
}
}
ClientConfiguration clientConfiguration = PredefinedClientConfigurations.defaultConfig();
if (defaultConnectionPoolSize > 0 || maximumConnectionPoolSize > 0) {
clientConfiguration.setMaxConnections(maximumConnectionPoolSize > 0 ? maximumConnectionPoolSize : defaultConnectionPoolSize);
}
if (!isNullOrEmptyOrDefault(signerType)) {
clientConfiguration.setSignerOverride(signerType);
}
if (connectionTtl != null) {
clientConfiguration.setConnectionTTL(connectionTtl.toMillis());
}
builder = builder.withClientConfiguration(clientConfiguration);
builder = builder.withPathStyleAccessEnabled(Boolean.parseBoolean(forcePathStyle));
builder.withBlobStoreConfig(blobStoreConfiguration);
if (cloudWatchMetricsEnabled) {
if (credentialsProvider != null) {
AwsSdkMetrics.setCredentialProvider(credentialsProvider);
}
AwsSdkMetrics.setMetricNameSpace(cloudWatchMetricsNamespace);
if (!isNullOrEmptyOrDefault(region)) {
AwsSdkMetrics.setRegion(region);
}
AwsSdkMetrics.enableDefaultMetrics();
log.info("CloudWatch metrics enabled using namespace {}", cloudWatchMetricsNamespace);
}
return builder.build();
}
use of com.amazonaws.services.s3.model.Filter in project nexus-public by sonatype.
the class S3BlobStore method getBlobIdUpdatedSinceStream.
@Override
public Stream<BlobId> getBlobIdUpdatedSinceStream(final int sinceDays) {
if (sinceDays < 0) {
throw new IllegalArgumentException("sinceDays must >= 0");
} else {
Iterable<S3ObjectSummary> summaries = S3Objects.withPrefix(s3, getConfiguredBucket(), getContentPrefix());
OffsetDateTime offsetDateTime = Instant.now().minus(sinceDays, ChronoUnit.DAYS).atOffset(ZoneOffset.UTC);
return blobIdStream(stream(summaries.spliterator(), false).filter(s3objectSummary -> s3objectSummary.getLastModified().toInstant().atOffset(ZoneOffset.UTC).isAfter(offsetDateTime)));
}
}
use of com.amazonaws.services.s3.model.Filter in project bff-marvel-api by thomasdacosta.
the class S3UtilTest method testCreateFile.
@Test
@Order(1)
@DisplayName("1 - Criando arquivos em um Bucket S3")
public void testCreateFile() {
String[] listFiles = new String[4];
listFiles[0] = "file1.txt";
listFiles[1] = "file2.txt";
listFiles[2] = "file3.txt";
listFiles[3] = "file4.txt";
S3Util.setEndpointConfiguration(LocalStackUtil.getLocalstack().getEndpointConfiguration(LocalStackContainer.Service.S3));
AmazonS3 amazonS3 = S3Util.getS3(S3Util.Env.LOCALSTACK);
Objects.requireNonNull(amazonS3).createBucket(Constants.BUCKET);
amazonS3.putObject(Constants.BUCKET, listFiles[0], "file1");
amazonS3.putObject(Constants.BUCKET, listFiles[1], "file2");
amazonS3.putObject(Constants.BUCKET, listFiles[2], "file3");
amazonS3.putObject(Constants.BUCKET, listFiles[3], "file4");
ObjectListing files = amazonS3.listObjects(Constants.BUCKET);
assertEquals(1, files.getObjectSummaries().stream().filter(p -> p.getKey().equals(listFiles[0])).count());
assertEquals(1, files.getObjectSummaries().stream().filter(p -> p.getKey().equals(listFiles[1])).count());
assertEquals(1, files.getObjectSummaries().stream().filter(p -> p.getKey().equals(listFiles[2])).count());
assertEquals(1, files.getObjectSummaries().stream().filter(p -> p.getKey().equals(listFiles[3])).count());
S3Util.setAmazonS3(null);
assertNotNull(S3Util.getS3(S3Util.Env.AWS));
assertNotNull(S3Util.getS3(S3Util.Env.AWS));
S3Util.setAmazonS3(null);
Assertions.assertNull(S3Util.getS3(null));
S3Util.setAmazonS3(null);
S3Util.setEndpointConfiguration(null);
assertNotNull(S3Util.getS3(S3Util.Env.LOCALSTACK));
assertNotNull(S3Util.getS3(S3Util.Env.LOCALSTACK));
}
use of com.amazonaws.services.s3.model.Filter in project bff-marvel-api by thomasdacosta.
the class ImageUtilTest method testCreateImage.
@Test
@Order(1)
@DisplayName("1 - Criando as imagens em um Bucket S3")
public void testCreateImage() throws URISyntaxException, IOException {
S3Util.setAmazonS3(null);
S3Util.setEndpointConfiguration(null);
WireMockUtils.serverImage();
S3Util.setEndpointConfiguration(LocalStackUtil.getLocalstack().getEndpointConfiguration(LocalStackContainer.Service.S3));
AmazonS3 amazonS3 = S3Util.getS3(S3Util.Env.LOCALSTACK);
Objects.requireNonNull(amazonS3).createBucket(Constants.BUCKET);
ThumbnailCharacter thumbnailCharacter = new ThumbnailCharacter();
thumbnailCharacter.setUrl("http://localhost:8082/imageMarvel");
thumbnailCharacter.setExtension("jpg");
MarvelCharacter marvelCharacter = new MarvelCharacter();
marvelCharacter.setId(new BigDecimal(1011355));
marvelCharacter.setName("Captain Midlands");
ImageUtil.saveImage(thumbnailCharacter, marvelCharacter);
ObjectListing files = amazonS3.listObjects(Constants.BUCKET);
assertEquals(1, files.getObjectSummaries().stream().filter(p -> p.getKey().equals("captain_midlands_1011355_portrait_uncanny.jpg")).count());
}
Aggregations