Search in sources :

Example 6 with AmazonCloudFront

use of com.amazonaws.services.cloudfront.AmazonCloudFront in project teamcity-s3-artifact-storage-plugin by JetBrains.

the class S3Util method withCloudFrontClient.

private static <T, E extends Throwable> T withCloudFrontClient(@NotNull final Map<String, String> params, @NotNull final WithCloudFront<T, E> withClient, boolean shutdownImmediately) throws E {
    return AWSCommonParams.withAWSClients(params, clients -> {
        clients.setS3SignerType(V4_SIGNER_TYPE);
        clients.setDisablePathStyleAccess(disablePathStyleAccess(params));
        patchAWSClientsSsl(clients, params);
        final AmazonCloudFront client = clients.createCloudFrontClient();
        try {
            return withClient.run(client);
        } finally {
            if (shutdownImmediately) {
                jetbrains.buildServer.util.amazon.S3Util.shutdownClient(client);
            }
        }
    });
}
Also used : AmazonCloudFront(com.amazonaws.services.cloudfront.AmazonCloudFront)

Example 7 with AmazonCloudFront

use of com.amazonaws.services.cloudfront.AmazonCloudFront in project deployer by craftercms.

the class CloudFrontInvalidationProcessor method doMainProcess.

/**
 * {@inheritDoc}
 */
@Override
@SuppressWarnings("unchecked")
protected ChangeSet doMainProcess(Deployment deployment, ProcessorExecution execution, ChangeSet filteredChangeSet, ChangeSet originalChangeSet) throws DeployerException {
    logger.info("Performing Cloudfront invalidation...");
    AmazonCloudFront client = buildClient();
    List<String> changedFiles = ListUtils.union(filteredChangeSet.getUpdatedFiles(), filteredChangeSet.getDeletedFiles());
    if (CollectionUtils.isNotEmpty(changedFiles)) {
        changedFiles = changedFiles.stream().map(f -> UriUtils.encodePath(f, StandardCharsets.UTF_8)).collect(Collectors.toList());
        Paths paths = new Paths().withItems(changedFiles).withQuantity(changedFiles.size());
        logger.info("Will invalidate {} files", changedFiles.size());
        for (String distribution : distributions) {
            try {
                String caller = UUID.randomUUID().toString();
                logger.info("Creating invalidation for distribution {} with reference {}", distribution, caller);
                InvalidationBatch batch = new InvalidationBatch().withPaths(paths).withCallerReference(caller);
                CreateInvalidationRequest request = new CreateInvalidationRequest(distribution, batch);
                CreateInvalidationResult result = client.createInvalidation(request);
                logger.info("Created invalidation {} for distribution {}", result.getInvalidation().getId(), distribution);
            } catch (Exception e) {
                throw new DeployerException("Error invalidating changed files for distribution " + distribution, e);
            }
        }
    } else {
        logger.info("No actual files that need to be invalidated");
    }
    return null;
}
Also used : InvalidationBatch(com.amazonaws.services.cloudfront.model.InvalidationBatch) CreateInvalidationResult(com.amazonaws.services.cloudfront.model.CreateInvalidationResult) DeployerException(org.craftercms.deployer.api.exceptions.DeployerException) AmazonCloudFront(com.amazonaws.services.cloudfront.AmazonCloudFront) Paths(com.amazonaws.services.cloudfront.model.Paths) CreateInvalidationRequest(com.amazonaws.services.cloudfront.model.CreateInvalidationRequest) DeployerException(org.craftercms.deployer.api.exceptions.DeployerException) ConfigurationException(org.craftercms.commons.config.ConfigurationException)

Example 8 with AmazonCloudFront

use of com.amazonaws.services.cloudfront.AmazonCloudFront in project cyberduck by iterate-ch.

the class CloudFrontDistributionConfiguration method updateCustomDistribution.

protected UpdateDistributionResult updateCustomDistribution(final Path container, final Distribution distribution) throws BackgroundException {
    final URI origin = this.getOrigin(container, distribution.getMethod());
    if (log.isDebugEnabled()) {
        log.debug(String.format("Update %s distribution with origin %s", distribution, origin));
    }
    final AmazonCloudFront client = this.client(container);
    final GetDistributionConfigResult response = client.getDistributionConfig(new GetDistributionConfigRequest(distribution.getId()));
    final DistributionConfig config = response.getDistributionConfig().withEnabled(distribution.isEnabled()).withDefaultRootObject(distribution.getIndexDocument() != null ? distribution.getIndexDocument() : StringUtils.EMPTY).withAliases(new Aliases().withItems(distribution.getCNAMEs()).withQuantity(distribution.getCNAMEs().length));
    // Make bucket name fully qualified
    final String loggingTarget = ServiceUtils.generateS3HostnameForBucket(distribution.getLoggingContainer(), false, new S3Protocol().getDefaultHostname());
    if (log.isDebugEnabled()) {
        log.debug(String.format("Set logging target for %s to %s", distribution, loggingTarget));
    }
    config.setLogging(new LoggingConfig().withEnabled(distribution.isLogging()).withIncludeCookies(true).withBucket(loggingTarget).withPrefix(new HostPreferences(session.getHost()).getProperty("cloudfront.logging.prefix")));
    return client.updateDistribution(new UpdateDistributionRequest(config, distribution.getId(), response.getETag()));
}
Also used : AmazonCloudFront(com.amazonaws.services.cloudfront.AmazonCloudFront) URI(java.net.URI) S3Protocol(ch.cyberduck.core.s3.S3Protocol) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Example 9 with AmazonCloudFront

use of com.amazonaws.services.cloudfront.AmazonCloudFront in project cyberduck by iterate-ch.

the class CloudFrontDistributionConfiguration method updateDownloadDistribution.

/**
 * Amazon CloudFront Extension used to enable or disable a distribution configuration and its CNAMESs
 */
protected UpdateDistributionResult updateDownloadDistribution(final Path container, final Distribution distribution) throws BackgroundException {
    final URI origin = this.getOrigin(container, distribution.getMethod());
    if (log.isDebugEnabled()) {
        log.debug(String.format("Update %s distribution with origin %s", distribution, origin));
    }
    final AmazonCloudFront client = this.client(container);
    final GetDistributionConfigResult response = client.getDistributionConfig(new GetDistributionConfigRequest(distribution.getId()));
    final DistributionConfig config = response.getDistributionConfig().withEnabled(distribution.isEnabled()).withDefaultRootObject(distribution.getIndexDocument()).withAliases(new Aliases().withItems(distribution.getCNAMEs()).withQuantity(distribution.getCNAMEs().length));
    if (distribution.isLogging()) {
        // Make bucket name fully qualified
        final String loggingTarget = ServiceUtils.generateS3HostnameForBucket(distribution.getLoggingContainer(), false, new S3Protocol().getDefaultHostname());
        if (log.isDebugEnabled()) {
            log.debug(String.format("Set logging target for %s to %s", distribution, loggingTarget));
        }
        config.setLogging(new LoggingConfig().withEnabled(distribution.isLogging()).withIncludeCookies(true).withBucket(loggingTarget).withPrefix(new HostPreferences(session.getHost()).getProperty("cloudfront.logging.prefix")));
    }
    return client.updateDistribution(new UpdateDistributionRequest(config, distribution.getId(), response.getETag()));
}
Also used : AmazonCloudFront(com.amazonaws.services.cloudfront.AmazonCloudFront) URI(java.net.URI) S3Protocol(ch.cyberduck.core.s3.S3Protocol) HostPreferences(ch.cyberduck.core.preferences.HostPreferences)

Example 10 with AmazonCloudFront

use of com.amazonaws.services.cloudfront.AmazonCloudFront in project cyberduck by iterate-ch.

the class CloudFrontDistributionConfiguration method createDownloadDistribution.

protected com.amazonaws.services.cloudfront.model.Distribution createDownloadDistribution(final Path container, final Distribution distribution) throws BackgroundException {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Create new %s distribution", distribution));
    }
    final AmazonCloudFront client = this.client(container);
    final URI origin = this.getOrigin(container, distribution.getMethod());
    final String originId = String.format("%s-%s", preferences.getProperty("application.name"), new AlphanumericRandomStringService().random());
    final DistributionConfig config = new DistributionConfig(new AlphanumericRandomStringService().random(), distribution.isEnabled()).withComment(originId).withOrigins(new Origins().withQuantity(1).withItems(new Origin().withId(originId).withCustomHeaders(new CustomHeaders().withQuantity(0)).withOriginPath(StringUtils.EMPTY).withDomainName(origin.getHost()).withS3OriginConfig(new S3OriginConfig().withOriginAccessIdentity(StringUtils.EMPTY)))).withPriceClass(PriceClass.PriceClass_All).withDefaultCacheBehavior(new DefaultCacheBehavior().withTargetOriginId(originId).withForwardedValues(new ForwardedValues().withQueryString(true).withCookies(new CookiePreference().withForward(ItemSelection.All))).withViewerProtocolPolicy(ViewerProtocolPolicy.AllowAll).withMinTTL(0L).withTrustedSigners(new TrustedSigners().withEnabled(false).withQuantity(0))).withDefaultRootObject(distribution.getIndexDocument()).withAliases(new Aliases().withItems(distribution.getCNAMEs()).withQuantity(distribution.getCNAMEs().length));
    // Make bucket name fully qualified
    final String loggingTarget = ServiceUtils.generateS3HostnameForBucket(distribution.getLoggingContainer(), false, new S3Protocol().getDefaultHostname());
    if (log.isDebugEnabled()) {
        log.debug(String.format("Set logging target for %s to %s", distribution, loggingTarget));
    }
    config.setLogging(new LoggingConfig().withEnabled(distribution.isLogging()).withIncludeCookies(true).withBucket(loggingTarget).withPrefix(new HostPreferences(session.getHost()).getProperty("cloudfront.logging.prefix")));
    return client.createDistribution(new CreateDistributionRequest(config)).getDistribution();
}
Also used : URI(java.net.URI) S3Protocol(ch.cyberduck.core.s3.S3Protocol) HostPreferences(ch.cyberduck.core.preferences.HostPreferences) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) AmazonCloudFront(com.amazonaws.services.cloudfront.AmazonCloudFront)

Aggregations

AmazonCloudFront (com.amazonaws.services.cloudfront.AmazonCloudFront)13 URI (java.net.URI)9 HostPreferences (ch.cyberduck.core.preferences.HostPreferences)6 S3Protocol (ch.cyberduck.core.s3.S3Protocol)6 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)4 Path (ch.cyberduck.core.Path)2 PathContainerService (ch.cyberduck.core.PathContainerService)2 AmazonServiceExceptionMappingService (ch.cyberduck.core.aws.AmazonServiceExceptionMappingService)2 Distribution (ch.cyberduck.core.cdn.Distribution)2 AmazonClientException (com.amazonaws.AmazonClientException)2 SdkClientException (com.amazonaws.SdkClientException)1 Policy (com.amazonaws.auth.policy.Policy)1 Principal (com.amazonaws.auth.policy.Principal)1 Statement (com.amazonaws.auth.policy.Statement)1 S3Actions (com.amazonaws.auth.policy.actions.S3Actions)1 S3ObjectResource (com.amazonaws.auth.policy.resources.S3ObjectResource)1 com.amazonaws.services.cloudfront.model (com.amazonaws.services.cloudfront.model)1 CreateInvalidationRequest (com.amazonaws.services.cloudfront.model.CreateInvalidationRequest)1 CreateInvalidationResult (com.amazonaws.services.cloudfront.model.CreateInvalidationResult)1 InvalidationBatch (com.amazonaws.services.cloudfront.model.InvalidationBatch)1