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);
}
}
});
}
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;
}
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()));
}
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()));
}
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();
}
Aggregations