List of usage examples for com.amazonaws.services.cloudfront.model Aliases Aliases
Aliases
From source file:ch.cyberduck.core.cloudfront.CloudFrontDistributionConfiguration.java
License:Open Source License
/** * Amazon CloudFront Extension to create a new distribution configuration * * @return Distribution configuration// w w w . j av a 2 s.c om */ protected StreamingDistribution createStreamingDistribution(final Path container, final Distribution distribution) throws BackgroundException { if (log.isDebugEnabled()) { log.debug(String.format("Create new %s distribution", distribution.getMethod().toString())); } final AmazonCloudFront client = 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 StreamingDistributionConfig config = new StreamingDistributionConfig( new AlphanumericRandomStringService().random(), new S3Origin(origin.getHost(), StringUtils.EMPTY), distribution.isEnabled()).withComment(originId) .withTrustedSigners(new TrustedSigners().withEnabled(false).withQuantity(0)) .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 StreamingLoggingConfig().withEnabled(distribution.isLogging()) .withBucket(loggingTarget).withPrefix(preferences.getProperty("cloudfront.logging.prefix"))); return client.createStreamingDistribution(new CreateStreamingDistributionRequest(config)) .getStreamingDistribution(); }
From source file:ch.cyberduck.core.cloudfront.CloudFrontDistributionConfiguration.java
License:Open Source License
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.getMethod().toString())); }/*ww w . ja v a2 s . com*/ final AmazonCloudFront client = 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(preferences.getProperty("cloudfront.logging.prefix"))); return client.createDistribution(new CreateDistributionRequest(config)).getDistribution(); }
From source file:ch.cyberduck.core.cloudfront.CloudFrontDistributionConfiguration.java
License:Open Source License
protected com.amazonaws.services.cloudfront.model.Distribution createCustomDistribution(final Path container, final Distribution distribution) throws BackgroundException { final AmazonCloudFront client = 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(); }/*from www . jav a2s. co m*/ 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(preferences.getProperty("cloudfront.logging.prefix"))); } return client.createDistribution(new CreateDistributionRequest(config)).getDistribution(); }
From source file:ch.cyberduck.core.cloudfront.CloudFrontDistributionConfiguration.java
License:Open Source License
/** * Amazon CloudFront Extension used to enable or disable a distribution configuration and its CNAMESs *///from w ww .ja v a2s . com protected UpdateDistributionResult updateDownloadDistribution(final Path container, final Distribution distribution) throws IOException, BackgroundException { final URI origin = this.getOrigin(container, distribution.getMethod()); if (log.isDebugEnabled()) { log.debug(String.format("Update %s distribution with origin %s", distribution.getMethod().toString(), origin)); } final AmazonCloudFront client = 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(preferences.getProperty("cloudfront.logging.prefix"))); } return client.updateDistribution( new UpdateDistributionRequest(config, distribution.getId(), response.getETag())); }
From source file:ch.cyberduck.core.cloudfront.CloudFrontDistributionConfiguration.java
License:Open Source License
protected UpdateStreamingDistributionResult updateStreamingDistribution(final Path container, final Distribution distribution) throws IOException, BackgroundException { final URI origin = this.getOrigin(container, distribution.getMethod()); if (log.isDebugEnabled()) { log.debug(String.format("Update %s distribution with origin %s", distribution.getMethod().toString(), origin));//from ww w. java 2 s.c om } final AmazonCloudFront client = client(container); final GetStreamingDistributionConfigResult response = client .getStreamingDistributionConfig(new GetStreamingDistributionConfigRequest(distribution.getId())); final StreamingDistributionConfig config = response.getStreamingDistributionConfig() .withEnabled(distribution.isEnabled()) .withS3Origin(new S3Origin(origin.getHost(), StringUtils.EMPTY)).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 StreamingLoggingConfig().withEnabled(distribution.isLogging()) .withBucket(loggingTarget).withPrefix(preferences.getProperty("cloudfront.logging.prefix"))); } return client.updateStreamingDistribution( new UpdateStreamingDistributionRequest(config, distribution.getId(), response.getETag())); }
From source file:ch.cyberduck.core.cloudfront.CloudFrontDistributionConfiguration.java
License:Open Source License
protected UpdateDistributionResult updateCustomDistribution(final Path container, final Distribution distribution) throws IOException, BackgroundException { final URI origin = this.getOrigin(container, distribution.getMethod()); if (log.isDebugEnabled()) { log.debug(String.format("Update %s distribution with origin %s", distribution.getMethod().toString(), origin));//from w w w . j a v a2 s . co m } final AmazonCloudFront client = 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(preferences.getProperty("cloudfront.logging.prefix"))); return client.updateDistribution( new UpdateDistributionRequest(config, distribution.getId(), response.getETag())); }
From source file:com.kpbird.aws.Main.java
public void createCloudFront() { try {/*from w w w .j a va 2s .c om*/ log.Info("Create CloudFront Distribution For Download"); AmazonCloudFrontClient cloudfront = new AmazonCloudFrontClient(credentials); cloudfront.setEndpoint(endPoint); cloudfront.setRegion(region); DistributionConfig dc = new DistributionConfig(); dc.withCallerReference(System.currentTimeMillis() + ""); dc.withAliases(new Aliases().withQuantity(0)); dc.withDefaultRootObject(""); dc.withOrigins(new Origins() .withItems(new Origin().withId(cloudFrontS3Origin) .withDomainName(cloudFrontS3Origin + ".s3.amazonaws.com") .withS3OriginConfig(new S3OriginConfig().withOriginAccessIdentity(""))) .withQuantity(1)); dc.withDefaultCacheBehavior(new DefaultCacheBehavior().withTargetOriginId(cloudFrontS3Origin) .withForwardedValues(new ForwardedValues().withQueryString(false) .withCookies(new CookiePreference().withForward("none"))) .withTrustedSigners(new TrustedSigners().withQuantity(0).withEnabled(false)) .withViewerProtocolPolicy(ViewerProtocolPolicy.AllowAll).withMinTTL(cloudFrontMinTTL)); dc.withCacheBehaviors(new CacheBehaviors().withQuantity(0)); dc.withComment(cloudFrontDesc); dc.withLogging( new LoggingConfig().withEnabled(false).withBucket("").withPrefix("").withIncludeCookies(false)); dc.withEnabled(true); dc.withPriceClass(PriceClass.PriceClass_All); CreateDistributionRequest cdr = new CreateDistributionRequest().withDistributionConfig(dc); CreateDistributionResult distribution = cloudfront.createDistribution(cdr); boolean isWait = true; while (isWait) { Thread.sleep(5000); GetDistributionResult gdr = cloudfront .getDistribution(new GetDistributionRequest(distribution.getDistribution().getId())); String status = gdr.getDistribution().getStatus(); log.Info("Status :" + status); if (status.equals("Deployed")) { isWait = false; log.Info("Domain Name :" + gdr.getDistribution().getDomainName()); } } } catch (Exception e) { e.printStackTrace(); System.exit(0); } }