use of com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult in project photon-model by vmware.
the class AWSSecurityGroupClient method getDefaultSecurityGroup.
public SecurityGroup getDefaultSecurityGroup(String vpcId) {
SecurityGroup cellGroup = null;
DescribeSecurityGroupsRequest req = new DescribeSecurityGroupsRequest().withFilters(new Filter("group-name", Collections.singletonList(DEFAULT_SECURITY_GROUP_NAME)));
if (vpcId != null) {
req.withFilters(new Filter("vpc-id", Collections.singletonList(vpcId)));
}
DescribeSecurityGroupsResult cellGroups = this.client.describeSecurityGroups(req);
if (cellGroups != null && !cellGroups.getSecurityGroups().isEmpty()) {
cellGroup = cellGroups.getSecurityGroups().get(0);
}
return cellGroup;
}
use of com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult in project photon-model by vmware.
the class AWSSecurityGroupClient method getSecurityGroup.
public SecurityGroup getSecurityGroup(String name, String vpcId) {
SecurityGroup cellGroup = null;
DescribeSecurityGroupsRequest req = new DescribeSecurityGroupsRequest().withFilters(new Filter("group-name", Collections.singletonList(name)));
if (vpcId != null) {
req.withFilters(new Filter("vpc-id", Collections.singletonList(vpcId)));
}
DescribeSecurityGroupsResult cellGroups = this.client.describeSecurityGroups(req);
if (cellGroups != null && !cellGroups.getSecurityGroups().isEmpty()) {
cellGroup = cellGroups.getSecurityGroups().get(0);
}
return cellGroup;
}
use of com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult in project photon-model by vmware.
the class TestAWSSetupUtils method createOrGetDefaultSecurityGroupForGivenVPC.
/**
* Returns an existing security group for a VPC if it exists otherwise creates a new security group.
*/
public static SecurityGroup createOrGetDefaultSecurityGroupForGivenVPC(AmazonEC2AsyncClient client, String vpcID) {
List<SecurityGroup> securityGroupsInVPC = client.describeSecurityGroups().getSecurityGroups().stream().filter(sg -> sg.getVpcId().equals(vpcID)).collect(Collectors.toList());
if (securityGroupsInVPC != null && !securityGroupsInVPC.isEmpty()) {
for (SecurityGroup sg : securityGroupsInVPC) {
// Do not use newly provisioned security groups as this could interfere with the cleanup logic of other tests.
if (!sg.getGroupName().startsWith(AWS_NEW_GROUP_PREFIX)) {
return sg;
}
}
}
String securityGroupId = new AWSSecurityGroupClient(client).createDefaultSecurityGroup(vpcID);
tagResources(client, Arrays.asList(securityGroupId), TAG_KEY_FOR_TEST_RESOURCES, TAG_VALUE_FOR_TEST_RESOURCES + TAG_SG);
DescribeSecurityGroupsResult result = client.describeSecurityGroups(new DescribeSecurityGroupsRequest().withGroupIds(Arrays.asList(securityGroupId)));
return result.getSecurityGroups().get(0);
}
use of com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult in project Gatekeeper by FINRAOS.
the class SGLookupService method loadSgsForAccountRegion.
private List<String> loadSgsForAccountRegion(AWSEnvironment environment) {
logger.info("Grabbing SGs for environment " + environment);
DescribeSecurityGroupsRequest describeSecurityGroupsRequest = new DescribeSecurityGroupsRequest();
Filter groupNameFilter = new Filter();
groupNameFilter.setName("group-name");
groupNameFilter.setValues(Collections.singletonList(securityGroupName));
AmazonEC2Client amazonEC2Client = awsSessionService.getEC2Session(environment);
DescribeSecurityGroupsResult result = amazonEC2Client.describeSecurityGroups(describeSecurityGroupsRequest.withFilters(groupNameFilter));
logger.info("found " + result.getSecurityGroups().size() + " Security Groups with name '" + securityGroupName + "'");
return result.getSecurityGroups().stream().map(SecurityGroup::getGroupId).collect(Collectors.toList());
}
use of com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult in project aws-doc-sdk-examples by awsdocs.
the class DescribeSecurityGroups method main.
public static void main(String[] args) {
final String USAGE = "To run this example, supply a group id\n" + "Ex: DescribeSecurityGroups <group-id>\n";
if (args.length != 1) {
System.out.println(USAGE);
System.exit(1);
}
String group_id = args[0];
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
DescribeSecurityGroupsRequest request = new DescribeSecurityGroupsRequest().withGroupIds(group_id);
DescribeSecurityGroupsResult response = ec2.describeSecurityGroups(request);
for (SecurityGroup group : response.getSecurityGroups()) {
System.out.printf("Found security group with id %s, " + "vpc id %s " + "and description %s", group.getGroupId(), group.getVpcId(), group.getDescription());
}
}
Aggregations