use of com.amazonaws.services.cloudfront.AmazonCloudFront in project cyberduck by iterate-ch.
the class CloudFrontDistributionConfiguration method createCustomDistribution.
protected com.amazonaws.services.cloudfront.model.Distribution createCustomDistribution(final Path container, final Distribution distribution) throws BackgroundException {
final AmazonCloudFront client = this.client(container);
int httpPort = 80;
int httpsPort = 443;
final URI origin = this.getOrigin(container, distribution.getMethod());
if (origin.getPort() != -1) {
if (origin.getScheme().equals(Scheme.http.name())) {
httpPort = origin.getPort();
}
if (origin.getScheme().equals(Scheme.https.name())) {
httpsPort = origin.getPort();
}
}
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).withDomainName(origin.getHost()).withCustomOriginConfig(new CustomOriginConfig().withHTTPPort(httpPort).withHTTPSPort(httpsPort).withOriginSslProtocols(new OriginSslProtocols().withQuantity(2).withItems("TLSv1.1", "TLSv1.2")).withOriginProtocolPolicy(this.getPolicy(distribution.getMethod()))))).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));
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.createDistribution(new CreateDistributionRequest(config)).getDistribution();
}
use of com.amazonaws.services.cloudfront.AmazonCloudFront in project cyberduck by iterate-ch.
the class CloudFrontDistributionConfiguration method invalidate.
/**
* You can make any number of invalidation requests, but you can have only three invalidation requests in progress
* at one time. Each request can contain up to 1,000 objects to invalidate. If you exceed these limits, you get an
* error message.
* <p>
* It usually takes 10 to 15 minutes to complete your invalidation request, depending on the size of your request.
*/
@Override
public void invalidate(final Path container, final Distribution.Method method, final List<Path> files, final LoginCallback prompt) throws BackgroundException {
try {
final Distribution d = this.read(container, method, prompt);
if (d.isEnabled()) {
final List<String> keys = new ArrayList<>();
for (Path file : files) {
if (session.getFeature(PathContainerService.class).isContainer(file)) {
// To invalidate all of the objects in a distribution
keys.add(String.format("%s*", Path.DELIMITER));
} else {
if (file.isDirectory()) {
// The *, which replaces 0 or more characters, must be the last character in the invalidation path
keys.add(String.format("/%s*", session.getFeature(PathContainerService.class).getKey(file)));
} else {
keys.add(String.format("/%s", session.getFeature(PathContainerService.class).getKey(file)));
}
}
}
if (keys.isEmpty()) {
log.warn("No keys selected for invalidation");
} else {
final AmazonCloudFront client = this.client(container);
client.createInvalidation(new CreateInvalidationRequest(d.getId(), new InvalidationBatch(new Paths().withItems(keys).withQuantity(keys.size()), new AlphanumericRandomStringService().random())));
}
}
} catch (AmazonClientException e) {
throw new AmazonServiceExceptionMappingService().map("Cannot write CDN configuration", e);
}
}
use of com.amazonaws.services.cloudfront.AmazonCloudFront in project cyberduck by iterate-ch.
the class CloudFrontDistributionConfiguration method deleteStreamingDistribution.
protected void deleteStreamingDistribution(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);
client.deleteStreamingDistribution(new DeleteStreamingDistributionRequest(distribution.getId(), distribution.getEtag()));
}
Aggregations