com.amazonaws.services.rds.model.ListTagsForResourceRequest Java Examples

The following examples show how to use com.amazonaws.services.rds.model.ListTagsForResourceRequest. 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 vote down vote up
/**
 * 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 5 votes vote down vote up
/**
 * Fetch RDS cluster info.
 *
 * @param temporaryCredentials the temporary credentials
 * @param skipRegions the skip regions
 * @param accountId the accountId
 * @param accountName the account name
 * @return the map
 */
public static Map<String,List<DBClusterVH>> fetchRDSClusterInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){
	Map<String,List<DBClusterVH>> rdsMap =  new LinkedHashMap<>();
	AmazonRDS rdsClient ;
	String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"RDS Cluster\" , \"region\":\"" ;
	for(Region region : RegionUtils.getRegions()){
		try{
			if(!skipRegions.contains(region.getName())){
				rdsClient = AmazonRDSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build();
				DescribeDBClustersResult rslt ;
				String nextMarker = null;
				List<DBClusterVH> rdsList = new ArrayList<>();
				do{
					rslt = rdsClient.describeDBClusters( new DescribeDBClustersRequest().withMarker(nextMarker));
					List<DBCluster> rdsListTemp = rslt.getDBClusters();
					for(DBCluster cluster : rdsListTemp){
						DBClusterVH vh = new DBClusterVH(cluster,rdsClient.listTagsForResource(new ListTagsForResourceRequest().
								withResourceName(cluster.getDBClusterArn())).
								getTagList());
						rdsList.add(vh);
					}
					nextMarker = rslt.getMarker();
				}while(nextMarker!=null);

				if( !rdsList.isEmpty() ){
					log.debug(InventoryConstants.ACCOUNT + accountId +" Type : RDS Cluster "+region.getName() + " >> "+rdsList.size());
					rdsMap.put(accountId+delimiter+accountName+delimiter+region.getName(), rdsList);
				}
			}
		}catch(Exception e){
			if(region.isServiceSupported(AmazonRDS.ENDPOINT_PREFIX)){
				log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}");
				ErrorManageUtil.uploadError(accountId,region.getName(),"rdscluster",e.getMessage());
			}
		}
	}
	return rdsMap;
}
 
Example #3
Source File: AmazonRdsDataSourceUserTagsFactoryBean.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Override
protected Map<String, String> createInstance() throws Exception {
	LinkedHashMap<String, String> userTags = new LinkedHashMap<>();
	ListTagsForResourceResult tagsForResource = this.amazonRds
			.listTagsForResource(new ListTagsForResourceRequest()
					.withResourceName(getDbInstanceResourceName()));
	for (Tag tag : tagsForResource.getTagList()) {
		userTags.put(tag.getKey(), tag.getValue());
	}
	return userTags;
}
 
Example #4
Source File: AmazonRdsDataSourceUserTagsFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void getObject_instanceWithTagsConfiguredWithCustomResourceResolverAndCustomRegion_mapWithTagsReturned()
		throws Exception {
	// Arrange
	AmazonRDS amazonRds = mock(AmazonRDS.class);
	ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
	AmazonIdentityManagement amazonIdentityManagement = mock(
			AmazonIdentityManagement.class);
	AmazonRdsDataSourceUserTagsFactoryBean factoryBean = new AmazonRdsDataSourceUserTagsFactoryBean(
			amazonRds, "test", amazonIdentityManagement);
	factoryBean.setResourceIdResolver(resourceIdResolver);
	factoryBean.setRegion(Region.getRegion(Regions.EU_WEST_1));

	when(resourceIdResolver.resolveToPhysicalResourceId("test"))
			.thenReturn("stack-test");
	when(amazonIdentityManagement.getUser()).thenReturn(
			new GetUserResult().withUser(new User("/", "aemruli", "123456789012",
					"arn:aws:iam::1234567890:user/aemruli", new Date())));
	when(amazonRds.listTagsForResource(new ListTagsForResourceRequest()
			.withResourceName("arn:aws:rds:eu-west-1:1234567890:db:stack-test")))
					.thenReturn(new ListTagsForResourceResult().withTagList(
							new Tag().withKey("key1").withValue("value1"),
							new Tag().withKey("key2").withValue("value2")));

	// Act
	factoryBean.afterPropertiesSet();
	Map<String, String> userTagMap = factoryBean.getObject();

	// Assert
	assertThat(userTagMap.get("key1")).isEqualTo("value1");
	assertThat(userTagMap.get("key2")).isEqualTo("value2");
}
 
Example #5
Source File: AmazonRdsDataSourceUserTagsFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void getObject_instanceWithOutTags_emptyMapReturned() throws Exception {
	// Arrange
	AmazonRDS amazonRds = mock(AmazonRDS.class);
	ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
	AmazonIdentityManagement amazonIdentityManagement = mock(
			AmazonIdentityManagement.class);
	AmazonRdsDataSourceUserTagsFactoryBean factoryBean = new AmazonRdsDataSourceUserTagsFactoryBean(
			amazonRds, "test", amazonIdentityManagement);
	factoryBean.setResourceIdResolver(resourceIdResolver);
	factoryBean.setResourceIdResolver(resourceIdResolver);
	factoryBean.setRegion(Region.getRegion(Regions.EU_WEST_1));

	when(resourceIdResolver.resolveToPhysicalResourceId("test"))
			.thenReturn("stack-test");
	when(amazonIdentityManagement.getUser()).thenReturn(
			new GetUserResult().withUser(new User("/", "aemruli", "123456789012",
					"arn:aws:iam::1234567890:user/aemruli", new Date())));
	when(amazonRds.listTagsForResource(new ListTagsForResourceRequest()
			.withResourceName("arn:aws:rds:eu-west-1:1234567890:db:stack-test")))
					.thenReturn(new ListTagsForResourceResult());

	// Act
	factoryBean.afterPropertiesSet();
	Map<String, String> userTagMap = factoryBean.getObject();

	// Assert
	assertThat(userTagMap.isEmpty()).isTrue();
}
 
Example #6
Source File: AmazonRdsDataSourceUserTagsFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void getObject_instanceWithTagsAndNoResourceIdResolverAndDefaultRegion_mapWithTagsReturned()
		throws Exception {
	// Arrange
	AmazonRDS amazonRds = mock(AmazonRDS.class);
	AmazonIdentityManagement amazonIdentityManagement = mock(
			AmazonIdentityManagement.class);

	AmazonRdsDataSourceUserTagsFactoryBean factoryBean = new AmazonRdsDataSourceUserTagsFactoryBean(
			amazonRds, "test", amazonIdentityManagement);

	when(amazonIdentityManagement.getUser()).thenReturn(
			new GetUserResult().withUser(new User("/", "aemruli", "123456789012",
					"arn:aws:iam::1234567890:user/aemruli", new Date())));
	when(amazonRds.listTagsForResource(new ListTagsForResourceRequest()
			.withResourceName("arn:aws:rds:us-west-2:1234567890:db:test")))
					.thenReturn(new ListTagsForResourceResult().withTagList(
							new Tag().withKey("key1").withValue("value1"),
							new Tag().withKey("key2").withValue("value2")));

	// Act
	factoryBean.afterPropertiesSet();
	Map<String, String> userTagMap = factoryBean.getObject();

	// Assert
	assertThat(userTagMap.get("key1")).isEqualTo("value1");
	assertThat(userTagMap.get("key2")).isEqualTo("value2");
}
 
Example #7
Source File: InventoryUtil.java    From pacbot with Apache License 2.0 4 votes vote down vote up
/**
 * Fetch RDS instance info.
 *
 * @param temporaryCredentials the temporary credentials
 * @param skipRegions the skip regions
 * @param accountId the accountId
 * @param accountName the account name
 * @return the map
 */
public static Map<String,List<DBInstanceVH>> fetchRDSInstanceInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName){
	Map<String,List<DBInstanceVH>> dbInstMap =  new LinkedHashMap<>();
	AmazonRDS rdsClient ;
	String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource in specific region\" ,\"type\": \"RDS Instance\" , \"region\":\"" ;
	for(Region region : RegionUtils.getRegions()){
		try{
			if(!skipRegions.contains(region.getName())){
				rdsClient = AmazonRDSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build();
				String nextMarker = null;
				DescribeDBInstancesResult rslt;
				List<DBInstanceVH> dbInstList = new ArrayList<>();
				do{
					rslt = rdsClient.describeDBInstances(new DescribeDBInstancesRequest().withMarker(nextMarker));
					List<DBInstance> dbInstListTemp = rslt.getDBInstances();
					for(DBInstance db : dbInstListTemp){
						DBInstanceVH vh = new DBInstanceVH(db, rdsClient.listTagsForResource(new ListTagsForResourceRequest().
													withResourceName(db.getDBInstanceArn())).
														getTagList(),
														db.getDBSubnetGroup().getSubnets().stream().map(subnet -> subnet.getSubnetIdentifier()).collect(Collectors.joining(",")),
														db.getVpcSecurityGroups().stream().map(group->group.getVpcSecurityGroupId()+":"+group.getStatus()).collect(Collectors.joining(","))
										);
						dbInstList.add(vh);
					}
					nextMarker = rslt.getMarker();
				}while(nextMarker!=null);

				if(! dbInstList.isEmpty() ){
					log.debug(InventoryConstants.ACCOUNT + accountId +" Type : RDS Instance" +region.getName() + " >> "+dbInstList.size());
					dbInstMap.put(accountId+delimiter+accountName+delimiter+region.getName(),  dbInstList);
				}
			}
		}catch(Exception e){
			if(region.isServiceSupported(AmazonRDS.ENDPOINT_PREFIX)){
				log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}");
				ErrorManageUtil.uploadError(accountId,region.getName(),"rdsdb",e.getMessage());
			}
		}
	}
	return dbInstMap;
}