List of usage examples for com.amazonaws.services.ec2.model AuthorizeSecurityGroupEgressRequest AuthorizeSecurityGroupEgressRequest
AuthorizeSecurityGroupEgressRequest
From source file:com.urbancode.terraform.tasks.aws.helpers.AWSHelper.java
License:Apache License
/** * * @param groupId//from ww w . ja va 2 s. c o m * @param protocol * @param startPort * @param endPort * @param cidr * @param inbound * @param ec2Client */ public void createRuleForSecurityGroup(String groupId, String protocol, int startPort, int endPort, String cidr, boolean inbound, AmazonEC2 ec2Client) { try { // protocol should be lowercase protocol = protocol.toLowerCase(); // create container for request // we need to use IpPermission object here because the other (old) way // is deprecated and no longer works IpPermission perm = new IpPermission().withFromPort(startPort).withToPort(endPort) .withIpProtocol(protocol).withIpRanges(cidr); if (inbound) { // inbound rule AuthorizeSecurityGroupIngressRequest request = new AuthorizeSecurityGroupIngressRequest() .withGroupId(groupId).withIpPermissions(perm); ec2Client.authorizeSecurityGroupIngress(request); } else { // outbound rule AuthorizeSecurityGroupEgressRequest request = new AuthorizeSecurityGroupEgressRequest() .withGroupId(groupId).withIpPermissions(perm); ec2Client.authorizeSecurityGroupEgress(request); } } catch (AmazonServiceException e) { log.error("Failed to create Rule on Security Group " + groupId, e); if (!"InvalidGroup.NotFound".equalsIgnoreCase(e.getErrorCode())) { throw e; } } }
From source file:com.vmware.photon.controller.model.adapters.awsadapter.AWSFirewallService.java
License:Open Source License
public void updateEgressRules(AmazonEC2AsyncClient client, String groupId, List<IpPermission> rules) { AuthorizeSecurityGroupEgressRequest req = new AuthorizeSecurityGroupEgressRequest().withGroupId(groupId) .withIpPermissions(rules);/*ww w. j av a 2 s . c om*/ client.authorizeSecurityGroupEgress(req); }
From source file:jp.classmethod.aws.gradle.ec2.AmazonEC2AuthorizeSecurityGroupEgressTask.java
License:Apache License
@TaskAction public void authorizeEgress() { // to enable conventionMappings feature String groupId = getGroupId(); Object ipPermissions = getIpPermissions(); if (groupId == null) { throw new GradleException("groupId is not specified"); }/* w w w .j av a 2s .c o m*/ if (ipPermissions == null) { throw new GradleException("ipPermissions is not specified"); } AmazonEC2PluginExtension ext = getProject().getExtensions().getByType(AmazonEC2PluginExtension.class); AmazonEC2 ec2 = ext.getClient(); try { ec2.authorizeSecurityGroupEgress(new AuthorizeSecurityGroupEgressRequest().withGroupId(groupId) .withIpPermissions(parse(ipPermissions))); } catch (AmazonServiceException e) { if (e.getErrorCode().equals("InvalidPermission.Duplicate")) { getLogger().warn(e.getMessage()); } else { throw e; } } }
From source file:org.xmlsh.aws.gradle.ec2.AmazonEC2AuthorizeSecurityGroupEgressTask.java
License:BSD License
@TaskAction public void authorizeEgress() { // 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();/*from www . j av a 2 s. c o m*/ try { ec2.authorizeSecurityGroupEgress(new AuthorizeSecurityGroupEgressRequest().withGroupId(groupId) .withIpPermissions(parse(ipPermissions))); } catch (AmazonServiceException e) { if (e.getErrorCode().equals("InvalidPermission.Duplicate")) { getLogger().warn(e.getMessage()); } else { throw e; } } }