Search in sources :

Example 31 with SecurityGroup

use of software.amazon.awssdk.services.ec2.model.SecurityGroup in project photon-model by vmware.

the class TestAWSSecurityGroupService method testUpdateIngressRules.

/*
     * Test updating ingress rules with the Security Group Service Allow
     * object
     */
@Test
public void testUpdateIngressRules() throws Throwable {
    String groupID = this.client.createDefaultSecurityGroup(null);
    ArrayList<Rule> rules = TestUtils.getAllowIngressRules();
    this.client.addIngressRules(groupID, this.client.buildRules(rules));
    SecurityGroup awsSG = this.client.getSecurityGroupById(groupID);
    List<IpPermission> ingress = awsSG.getIpPermissions();
    for (IpPermission rule : ingress) {
        assertDefaultRules(rule);
    }
    this.client.deleteSecurityGroup(groupID);
}
Also used : Rule(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState.Rule) IpPermission(com.amazonaws.services.ec2.model.IpPermission) SecurityGroup(com.amazonaws.services.ec2.model.SecurityGroup) Test(org.junit.Test)

Example 32 with SecurityGroup

use of software.amazon.awssdk.services.ec2.model.SecurityGroup in project aws-doc-sdk-examples by awsdocs.

the class DescribeSecurityGroups method describeEC2SecurityGroups.

// snippet-start:[ec2.java2.describe_security_groups.main]
public static void describeEC2SecurityGroups(Ec2Client ec2, String groupId) {
    try {
        DescribeSecurityGroupsRequest request = DescribeSecurityGroupsRequest.builder().groupIds(groupId).build();
        DescribeSecurityGroupsResponse response = ec2.describeSecurityGroups(request);
        for (SecurityGroup group : response.securityGroups()) {
            System.out.printf("Found Security Group with id %s, " + "vpc id %s " + "and description %s", group.groupId(), group.vpcId(), group.description());
        }
    } catch (Ec2Exception e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : DescribeSecurityGroupsRequest(software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsRequest) DescribeSecurityGroupsResponse(software.amazon.awssdk.services.ec2.model.DescribeSecurityGroupsResponse) Ec2Exception(software.amazon.awssdk.services.ec2.model.Ec2Exception) SecurityGroup(software.amazon.awssdk.services.ec2.model.SecurityGroup)

Aggregations

SecurityGroup (com.amazonaws.services.ec2.model.SecurityGroup)31 DescribeSecurityGroupsResult (com.amazonaws.services.ec2.model.DescribeSecurityGroupsResult)12 DescribeSecurityGroupsRequest (com.amazonaws.services.ec2.model.DescribeSecurityGroupsRequest)11 Test (org.junit.Test)10 IpPermission (com.amazonaws.services.ec2.model.IpPermission)9 ArrayList (java.util.ArrayList)8 Instance (com.amazonaws.services.ec2.model.Instance)7 HashMap (java.util.HashMap)7 AmazonEC2AsyncClient (com.amazonaws.services.ec2.AmazonEC2AsyncClient)6 SecurityGroupState (com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState)6 Operation (com.vmware.xenon.common.Operation)6 Utils (com.vmware.xenon.common.Utils)6 Map (java.util.Map)6 Filter (com.amazonaws.services.ec2.model.Filter)5 Collections (java.util.Collections)5 List (java.util.List)5 TimeUnit (java.util.concurrent.TimeUnit)5 Level (java.util.logging.Level)5 Collectors (java.util.stream.Collectors)5 Before (org.junit.Before)5