Search in sources :

Example 96 with Filter

use of com.amazonaws.services.s3.model.Filter in project boot by workoss.

the class AbstractS3Client method getBucket.

@Override
public StorageBucketInfo getBucket() {
    AmazonS3 amazonS3 = getClient("", "getBucket");
    try {
        ListBucketsRequest listBucketsRequest = new ListBucketsRequest();
        List<Bucket> buckets = amazonS3.listBuckets(listBucketsRequest);
        if (CollectionUtils.isEmpty(buckets)) {
            return null;
        }
        return buckets.stream().filter(bucket -> config.getBucketName().equals(bucket.getName())).map(bucket -> new StorageBucketInfo(bucket.getName(), bucket.getOwner() == null ? null : bucket.getOwner().getId(), bucket.getCreationDate())).findFirst().orElseGet(() -> null);
    } catch (AmazonS3Exception e) {
        throw new StorageException(e.getErrorCode(), e.getMessage());
    } catch (Exception e) {
        throw new StorageException("0002", ExceptionUtils.toShortString(e, 2));
    } finally {
        amazonS3.shutdown();
    }
}
Also used : AWSStaticCredentialsProvider(com.amazonaws.auth.AWSStaticCredentialsProvider) AmazonS3ClientBuilder(com.amazonaws.services.s3.AmazonS3ClientBuilder) StorageClientConfig(com.workoss.boot.storage.config.StorageClientConfig) URL(java.net.URL) Date(java.util.Date) AwsClientBuilder(com.amazonaws.client.builder.AwsClientBuilder) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Cache(com.github.benmanes.caffeine.cache.Cache) IOUtils(com.amazonaws.util.IOUtils) StorageClientNotFoundException(com.workoss.boot.storage.exception.StorageClientNotFoundException) BasicSessionCredentials(com.amazonaws.auth.BasicSessionCredentials) ProgressListener(com.amazonaws.event.ProgressListener) ByteArrayInputStream(java.io.ByteArrayInputStream) HttpUtil(com.workoss.boot.storage.util.HttpUtil) Map(java.util.Map) AmazonS3(com.amazonaws.services.s3.AmazonS3) AWSCredentials(com.amazonaws.auth.AWSCredentials) RemovalCause(com.github.benmanes.caffeine.cache.RemovalCause) ExceptionUtils(com.workoss.boot.util.exception.ExceptionUtils) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) Logger(org.slf4j.Logger) StorageException(com.workoss.boot.storage.exception.StorageException) com.amazonaws.services.s3.model(com.amazonaws.services.s3.model) StorageDownloadException(com.workoss.boot.storage.exception.StorageDownloadException) StringUtils(com.workoss.boot.util.StringUtils) CollectionUtils(com.workoss.boot.util.collection.CollectionUtils) Collectors(java.util.stream.Collectors) File(java.io.File) StorageUtil(com.workoss.boot.storage.util.StorageUtil) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) com.workoss.boot.storage.model(com.workoss.boot.storage.model) InputStream(java.io.InputStream) AmazonS3(com.amazonaws.services.s3.AmazonS3) StorageException(com.workoss.boot.storage.exception.StorageException) StorageClientNotFoundException(com.workoss.boot.storage.exception.StorageClientNotFoundException) StorageException(com.workoss.boot.storage.exception.StorageException) StorageDownloadException(com.workoss.boot.storage.exception.StorageDownloadException)

Example 97 with Filter

use of com.amazonaws.services.s3.model.Filter in project aws-sdk-android by aws-amplify.

the class BucketConfigurationXmlFactory method convertToXmlByteArray.

/**
 * Converts the specified
 * {@link com.amazonaws.services.s3.model.metrics.MetricsConfiguration}
 * object to an XML fragment that can be sent to Amazon S3.
 *
 * @param config The
 *            {@link com.amazonaws.services.s3.model.metrics.MetricsConfiguration}
 *            .
 */
/*
     * <MetricsConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
     * <Id>metrics-id</Id> <Filter> <!-- A filter should have only one of
     * Prefix, Tag or And--> <Prefix>prefix</Prefix> <Tag> <Key>Project</Key>
     * <Value>Foo</Value> </Tag> <And> <Prefix>documents/</Prefix> <Tag>
     * <Key>foo</Key> <Value>bar</Value> </Tag> </And> </Filter>
     * </MetricsConfiguration>
     */
public byte[] convertToXmlByteArray(MetricsConfiguration config) throws AmazonClientException {
    final XmlWriter xml = new XmlWriter();
    xml.start("MetricsConfiguration", "xmlns", Constants.XML_NAMESPACE);
    addParameterIfNotNull(xml, "Id", config.getId());
    writeMetricsFilter(xml, config.getFilter());
    xml.end();
    return xml.getBytes();
}
Also used : XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Example 98 with Filter

use of com.amazonaws.services.s3.model.Filter in project aws-sdk-android by aws-amplify.

the class BucketConfigurationXmlFactory method convertToXmlByteArray.

/**
 * Converts the specified
 * {@link com.amazonaws.services.s3.model.analytics.AnalyticsConfiguration}
 * object to an XML fragment that can be sent to Amazon S3.
 *
 * @param config The
 *            {@link com.amazonaws.services.s3.model.analytics.AnalyticsConfiguration}
 */
/*
     * <AnalyticsConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
     * <Id>XXX</Id> <Filter> <And> <Prefix>documents/</Prefix> <Tag>
     * <Key>foo</Key> <Value>bar</Value> </Tag> </And> </Filter>
     * <StorageClassAnalysis> <DataExport>
     * <OutputSchemaVersion>1</OutputSchemaVersion> <Destination>
     * <S3BucketDestination> <Format>CSV</Format>
     * <BucketAccountId>123456789</BucketAccountId>
     * <Bucket>destination-bucket</Bucket> <Prefix>destination-prefix</Prefix>
     * </S3BucketDestination> </Destination> </DataExport>
     * </StorageClassAnalysis> </AnalyticsConfiguration>
     */
public byte[] convertToXmlByteArray(AnalyticsConfiguration config) throws AmazonClientException {
    final XmlWriter xml = new XmlWriter();
    xml.start("AnalyticsConfiguration", "xmlns", Constants.XML_NAMESPACE);
    addParameterIfNotNull(xml, "Id", config.getId());
    writeAnalyticsFilter(xml, config.getFilter());
    writeStorageClassAnalysis(xml, config.getStorageClassAnalysis());
    xml.end();
    return xml.getBytes();
}
Also used : XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Example 99 with Filter

use of com.amazonaws.services.s3.model.Filter in project aws-sdk-android by aws-amplify.

the class BucketConfigurationXmlFactory method addEventsAndFilterCriteria.

private void addEventsAndFilterCriteria(XmlWriter xml, NotificationConfiguration config) {
    for (final String event : config.getEvents()) {
        xml.start("Event").value(event).end();
    }
    final Filter filter = config.getFilter();
    if (filter != null) {
        validateFilter(filter);
        xml.start("Filter");
        if (filter.getS3KeyFilter() != null) {
            validateS3KeyFilter(filter.getS3KeyFilter());
            xml.start("S3Key");
            for (final FilterRule filterRule : filter.getS3KeyFilter().getFilterRules()) {
                xml.start("FilterRule");
                xml.start("Name").value(filterRule.getName()).end();
                xml.start("Value").value(filterRule.getValue()).end();
                xml.end();
            }
            xml.end();
        }
        xml.end();
    }
}
Also used : Filter(com.amazonaws.services.s3.model.Filter) AnalyticsFilter(com.amazonaws.services.s3.model.analytics.AnalyticsFilter) LifecycleFilter(com.amazonaws.services.s3.model.lifecycle.LifecycleFilter) InventoryFilter(com.amazonaws.services.s3.model.inventory.InventoryFilter) S3KeyFilter(com.amazonaws.services.s3.model.S3KeyFilter) MetricsFilter(com.amazonaws.services.s3.model.metrics.MetricsFilter) FilterRule(com.amazonaws.services.s3.model.FilterRule)

Example 100 with Filter

use of com.amazonaws.services.s3.model.Filter in project aws-sdk-android by aws-amplify.

the class FilterStaxUnmarshaller method unmarshall.

@Override
public Filter unmarshall(StaxUnmarshallerContext context) throws Exception {
    final int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;
    if (context.isStartOfDocument()) {
        targetDepth += 1;
    }
    final Filter filter = new Filter();
    while (true) {
        final int xmlEvent = context.nextEvent();
        if (xmlEvent == XmlPullParser.END_DOCUMENT) {
            break;
        } else if (xmlEvent == XmlPullParser.START_TAG) {
            if (context.testExpression("S3Key", targetDepth)) {
                filter.withS3KeyFilter(S3KeyFilterStaxUnmarshaller.getInstance().unmarshall(context));
            }
        } else if (xmlEvent == XmlPullParser.END_TAG) {
            if (context.getCurrentDepth() < originalDepth) {
                return filter;
            }
        }
    }
    return filter;
}
Also used : Filter(com.amazonaws.services.s3.model.Filter)

Aggregations

Filter (com.amazonaws.services.ec2.model.Filter)96 ArrayList (java.util.ArrayList)70 List (java.util.List)52 Collectors (java.util.stream.Collectors)46 IOException (java.io.IOException)41 HashMap (java.util.HashMap)38 Map (java.util.Map)35 AmazonS3 (com.amazonaws.services.s3.AmazonS3)34 Set (java.util.Set)31 DescribeInstancesRequest (com.amazonaws.services.ec2.model.DescribeInstancesRequest)30 S3ObjectSummary (com.amazonaws.services.s3.model.S3ObjectSummary)27 Instance (com.amazonaws.services.ec2.model.Instance)26 HashSet (java.util.HashSet)26 Reservation (com.amazonaws.services.ec2.model.Reservation)24 Collections (java.util.Collections)23 DescribeInstancesResult (com.amazonaws.services.ec2.model.DescribeInstancesResult)21 ObjectListing (com.amazonaws.services.s3.model.ObjectListing)21 DescribeSubnetsRequest (com.amazonaws.services.ec2.model.DescribeSubnetsRequest)20 Entry (java.util.Map.Entry)20 Tag (com.amazonaws.services.ec2.model.Tag)18