Example usage for com.amazonaws.services.ec2.model RevokeSecurityGroupEgressRequest RevokeSecurityGroupEgressRequest

List of usage examples for com.amazonaws.services.ec2.model RevokeSecurityGroupEgressRequest RevokeSecurityGroupEgressRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.ec2.model RevokeSecurityGroupEgressRequest RevokeSecurityGroupEgressRequest.

Prototype

RevokeSecurityGroupEgressRequest

Source Link

Usage

From source file:com.urbancode.terraform.tasks.aws.helpers.AWSHelper.java

License:Apache License

/**
 *
 * @param groupId/*from  w  w  w  .j  a  va2s  .co  m*/
 * @param protocol
 * @param startPort
 * @param endPort
 * @param cidr
 * @param inbound
 * @param ec2Client
 */
public void deleteRuleForSecurityGroup(String groupId, String protocol, int startPort, int endPort, String cidr,
        boolean inbound, AmazonEC2 ec2Client) {

    IpPermission perm = new IpPermission().withFromPort(startPort).withToPort(endPort).withIpProtocol(protocol)
            .withIpRanges(cidr);
    try {
        if (inbound) {
            RevokeSecurityGroupIngressRequest request = new RevokeSecurityGroupIngressRequest()
                    .withGroupId(groupId).withIpPermissions(perm);
            ec2Client.revokeSecurityGroupIngress(request);
        } else {
            RevokeSecurityGroupEgressRequest request = new RevokeSecurityGroupEgressRequest()
                    .withGroupId(groupId).withIpPermissions(perm);
            ec2Client.revokeSecurityGroupEgress(request);
        }
    } catch (AmazonServiceException e) {
        log.error("Failed to delete Rule on Security Group " + groupId);
        if (!"InvalidGroup.NotFound".equals(e.getErrorCode())) {
            throw e;
        }
    }
}

From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2RevokeSecurityGroupEgressTask.java

License:Apache License

@TaskAction
public void revokeEgress() {
    // to enable conventionMappings feature
    String groupId = getGroupId();
    Object ipPermissions = getIpPermissions();

    if (groupId == null) {
        throw new GradleException("groupId is not specified");
    }//from ww  w .  ja v  a 2 s.  c om
    if (ipPermissions == null) {
        throw new GradleException("ipPermissions is not specified");
    }

    AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class);
    AmazonEC2 ec2 = ext.getClient();

    try {
        ec2.revokeSecurityGroupEgress(new RevokeSecurityGroupEgressRequest().withGroupId(groupId)
                .withIpPermissions(parse(ipPermissions)));
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidPermission.NotFound")) {
            getLogger().warn(e.getMessage());
        } else {
            throw e;
        }
    }
}

From source file:org.xmlsh.aws.gradle.ec2.AmazonEC2RevokeSecurityGroupEgressTask.java

License:BSD License

@TaskAction
public void revokeEgress() {
    // to enable conventionMappings feature
    String groupId = getGroupId();
    Object ipPermissions = getIpPermissions();

    if (groupId == null)
        throw new GradleException("groupId is not specified");
    if (ipPermissions == null)
        throw new GradleException("ipPermissions is not specified");

    AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class);
    AmazonEC2 ec2 = ext.getClient();// ww w . j  av a2  s .  com

    try {
        ec2.revokeSecurityGroupEgress(new RevokeSecurityGroupEgressRequest().withGroupId(groupId)
                .withIpPermissions(parse(ipPermissions)));
    } catch (AmazonServiceException e) {
        if (e.getErrorCode().equals("InvalidPermission.NotFound")) {
            getLogger().warn(e.getMessage());
        } else {
            throw e;
        }
    }
}