com.amazonaws.services.cloudfront.AmazonCloudFrontClientBuilder Java Examples
The following examples show how to use
com.amazonaws.services.cloudfront.AmazonCloudFrontClientBuilder.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Sets the cloud front tags. * * @param temporaryCredentials the temporary credentials * @param cloudFrontList the cloud front list */ private static void setCloudFrontTags(BasicSessionCredentials temporaryCredentials,List<CloudFrontVH> cloudFrontList){ String[] regions = {"us-west-2","us-east-1"}; int index = 0; AmazonCloudFront amazonCloudFront = AmazonCloudFrontClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(regions[index]).build(); for(CloudFrontVH cfVH: cloudFrontList){ try{ cfVH.setTags(amazonCloudFront.listTagsForResource(new com.amazonaws.services.cloudfront.model.ListTagsForResourceRequest().withResource(cfVH.getDistSummary().getARN())).getTags().getItems()); }catch(Exception e){ index = index==0?1:0; amazonCloudFront = AmazonCloudFrontClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(regions[index]).build(); } } }
Example #2
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 6 votes |
/** * Sets the default root object. * * @param temporaryCredentials the temporary credentials * @param cloudFrontList the cloud front list */ private static void setConfigDetails(BasicSessionCredentials temporaryCredentials, List<CloudFrontVH> cloudFrontList){ String[] regions = {"us-east-2","us-west-1"}; int index = 0; AmazonCloudFront amazonCloudFront = AmazonCloudFrontClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(regions[index]).build(); for(CloudFrontVH cfVH: cloudFrontList){ try{ DistributionConfig distConfig = amazonCloudFront.getDistributionConfig(new GetDistributionConfigRequest().withId(cfVH.getDistSummary().getId())).getDistributionConfig(); cfVH.setDefaultRootObject(distConfig.getDefaultRootObject()); cfVH.setBucketName(distConfig.getLogging().getBucket()); cfVH.setAccessLogEnabled(distConfig.getLogging().getEnabled()); }catch(Exception e){ index = index==0?1:0; amazonCloudFront = AmazonCloudFrontClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(regions[index]).build(); } } }
Example #3
Source File: CFInvalidateStep.java From pipeline-aws-plugin with Apache License 2.0 | 6 votes |
@Override protected Void run() throws Exception { TaskListener listener = this.getContext().get(TaskListener.class); AmazonCloudFront client = AWSClientFactory.create(AmazonCloudFrontClientBuilder.standard(), this.getContext()); String distribution = this.step.getDistribution(); String[] paths = this.step.getPaths(); boolean waitForCompletion = this.step.getWaitForCompletion(); listener.getLogger().format("Invalidating paths %s in distribution %s%n", Arrays.toString(paths), distribution); Paths invalidationPaths = new Paths().withItems(paths).withQuantity(paths.length); InvalidationBatch batch = new InvalidationBatch(invalidationPaths, Long.toString(System.currentTimeMillis())); String invalidationId = client.createInvalidation(new CreateInvalidationRequest(distribution, batch)).getInvalidation().getId(); listener.getLogger().format("Invalidation %s enqueued%n", invalidationId); if (waitForCompletion) { listener.getLogger().format("Waiting for invalidation %s to be completed...%n", invalidationId); client.waiters().invalidationCompleted().run(new WaiterParameters<GetInvalidationRequest>(new GetInvalidationRequest(distribution, invalidationId))); listener.getLogger().format("Invalidation %s completed%n", invalidationId); } return null; }
Example #4
Source File: InventoryUtil.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch cloud front info. * * @param temporaryCredentials the temporary credentials * @param accountId the accountId * @param accountName the account name * @return the map */ public static Map<String,List<CloudFrontVH>> fetchCloudFrontInfo(BasicSessionCredentials temporaryCredentials,String accountId,String accountName) { Map<String,List<CloudFrontVH>> cloudFront = new LinkedHashMap<>(); List<DistributionSummary> distributionSummary = new ArrayList<>(); AmazonCloudFront amazonCloudFront; String bucketName = null; boolean accessLogEnabled = false; String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource \" ,\"type\": \"CloudFront\"" ; try{ amazonCloudFront = AmazonCloudFrontClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion("us-west-2").build(); String marker = null; List<CloudFrontVH> cloudFrontList = new ArrayList<>(); DistributionList distributionList ; do{ distributionList = amazonCloudFront.listDistributions(new ListDistributionsRequest().withMarker(marker)).getDistributionList(); distributionSummary = distributionList.getItems(); marker = distributionList.getNextMarker(); for(DistributionSummary ds : distributionSummary) { CloudFrontVH cf = new CloudFrontVH(); cf.setDistSummary(ds); cloudFrontList.add(cf); } }while(marker!=null); setCloudFrontTags(temporaryCredentials,cloudFrontList); setConfigDetails(temporaryCredentials,cloudFrontList); log.debug(InventoryConstants.ACCOUNT + accountId +" Type : CloudFront "+ " >> "+cloudFrontList.size()); cloudFront.put(accountId+delimiter+accountName,cloudFrontList); }catch(Exception e){ log.error(expPrefix+ InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,"","cloudfront",e.getMessage()); } return cloudFront; }
Example #5
Source File: InventoryUtilTest.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch cloud front info test. * * @throws Exception the exception */ @SuppressWarnings("static-access") @Test public void fetchCloudFrontInfoTest() throws Exception { mockStatic(AmazonCloudFrontClientBuilder.class); AmazonCloudFront amazonCloudFront = PowerMockito.mock(AmazonCloudFront.class); AmazonCloudFrontClientBuilder amazonCloudFrontClientBuilder = PowerMockito.mock(AmazonCloudFrontClientBuilder.class); AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class); PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider); when(amazonCloudFrontClientBuilder.standard()).thenReturn(amazonCloudFrontClientBuilder); when(amazonCloudFrontClientBuilder.withCredentials(anyObject())).thenReturn(amazonCloudFrontClientBuilder); when(amazonCloudFrontClientBuilder.withRegion(anyString())).thenReturn(amazonCloudFrontClientBuilder); when(amazonCloudFrontClientBuilder.build()).thenReturn(amazonCloudFront); ListDistributionsResult listDistributionsResult = new ListDistributionsResult(); List<DistributionSummary> distributionSummaries = new ArrayList<>(); DistributionSummary distributionSummary = new DistributionSummary(); distributionSummary.setARN("aRN"); distributionSummaries.add(distributionSummary); DistributionList distributionList = new DistributionList(); distributionList.setItems(distributionSummaries); listDistributionsResult.setDistributionList(distributionList); when(amazonCloudFront.listDistributions(anyObject())).thenReturn(listDistributionsResult); com.amazonaws.services.cloudfront.model.ListTagsForResourceResult listTagsForResourceResult = new com.amazonaws.services.cloudfront.model.ListTagsForResourceResult(); Tags tags = new Tags(); tags.setItems(new ArrayList<>()); listTagsForResourceResult.setTags(tags ); when(amazonCloudFront.listTagsForResource(anyObject())).thenReturn(listTagsForResourceResult ); assertThat(inventoryUtil.fetchCloudFrontInfo(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), "account","accountName").size(), is(1)); }
Example #6
Source File: CloudFrontDistributionConfiguration.java From cyberduck with GNU General Public License v3.0 | 5 votes |
private AmazonCloudFront client(final Path container) throws BackgroundException { final AmazonCloudFrontClientBuilder builder = AmazonCloudFrontClientBuilder.standard() .withCredentials(AWSCredentialsConfigurator.toAWSCredentialsProvider(bookmark.getCredentials())) .withClientConfiguration(configuration); final Location.Name region = this.getRegion(container); if(Location.unknown.equals(region)) { builder.withRegion(Regions.DEFAULT_REGION); } else { builder.withRegion(region.getIdentifier()); } return builder.build(); }
Example #7
Source File: TkInvalidate.java From jare with MIT License | 5 votes |
@Override public Response act(final Request req) throws IOException { final String url = new RqHref.Base(req).href() .param("url").iterator().next(); final String path = String.format( "/?u=%s", URLEncoder.encode( url, "UTF-8" ) ); final AmazonCloudFront aws = AmazonCloudFrontClientBuilder.standard() .withCredentials( new AWSStaticCredentialsProvider( new BasicAWSCredentials(this.key, this.secret) ) ) .build(); final CreateInvalidationResult result = aws.createInvalidation( new CreateInvalidationRequest( "E2QC66VZY6F0QA", new InvalidationBatch( new Paths().withItems(path).withQuantity(1), UUID.randomUUID().toString() ) ) ); return new RsForward( new RsFlash( String.format( "URL \"%s\" was invalidated (ID=\"%s\", Status=\"%s\")", url, result.getInvalidation().getId(), result.getInvalidation().getStatus() ) ), "/domains" ); }