/** * @throws IllegalStateException If the security group was in use */ @VisibleForTesting void deleteSecurityGroup(String region, String group) { checkNotNull(emptyToNull(region), "region must be defined"); checkNotNull(emptyToNull(group), "group must be defined"); String groupName = namingConvention.create().sharedNameForGroup(group); Multimap<String, String> securityGroupFilterByName = ImmutableMultimap.of("group-name", groupName); Set<SecurityGroup> securityGroupsToDelete = client.getSecurityGroupApi().get() .describeSecurityGroupsInRegionWithFilter(region, securityGroupFilterByName); if (securityGroupsToDelete.size() > 1) { logger.warn("When trying to delete security group %s found more than one matching the name. Will delete all - %s.", group, securityGroupsToDelete); } for (SecurityGroup securityGroup : securityGroupsToDelete) { logger.debug(">> deleting securityGroup(%s)", groupName); client.getSecurityGroupApi().get().deleteSecurityGroupInRegionById(region, securityGroup.getId()); securityGroupMap.invalidate(new RegionNameAndIngressRules(region, groupName, null, false, null)); logger.debug("<< deleted securityGroup(%s)", groupName); } }
/** * @throws IllegalStateException If the security group was in use */ @VisibleForTesting void deleteSecurityGroup(String region, String group) { checkNotNull(emptyToNull(region), "region must be defined"); checkNotNull(emptyToNull(group), "group must be defined"); String groupName = namingConvention.create().sharedNameForGroup(group); Multimap<String, String> securityGroupFilterByName = ImmutableMultimap.of("group-name", groupName); Set<SecurityGroup> securityGroupsToDelete = client.getSecurityGroupApi().get() .describeSecurityGroupsInRegionWithFilter(region, securityGroupFilterByName); if (securityGroupsToDelete.size() > 1) { logger.warn("When trying to delete security group %s found more than one matching the name. Will delete all - %s.", group, securityGroupsToDelete); } for (SecurityGroup securityGroup : securityGroupsToDelete) { logger.debug(">> deleting securityGroup(%s)", groupName); client.getSecurityGroupApi().get().deleteSecurityGroupInRegionById(region, securityGroup.getId()); securityGroupMap.invalidate(new RegionNameAndIngressRules(region, groupName, null, false, null)); logger.debug("<< deleted securityGroup(%s)", groupName); } }
public void testDeleteSecurityGroupByIdWhen404() { HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build(); EC2Api apiWhenNotExist = requestsSendResponses( describeRegionsRequest, describeRegionsResponse, deleteById, deleteResponse); apiWhenNotExist.getSecurityGroupApi().get().deleteSecurityGroupInRegionById("us-east-1", "sg-3c6ef654"); }
public void testDeleteSecurityGroupById() { HttpResponse deleteResponse = HttpResponse.builder().statusCode(200) .payload(payloadFromResourceWithContentType("/delete_securitygroup.xml", "text/xml")).build(); EC2Api apiWhenNotExist = requestsSendResponses( describeRegionsRequest, describeRegionsResponse, deleteById, deleteResponse); apiWhenNotExist.getSecurityGroupApi().get().deleteSecurityGroupInRegionById("us-east-1", "sg-3c6ef654"); }