protected static IpRule toIpRule( IpPermission permission ) { BasicIpRule rule = new BasicIpRule(); rule.setFromPort( permission.getFromPort() ); rule.setToPort( permission.getToPort() ); rule.setIpProtocol( permission.getIpProtocol() ); rule.setIpRanges( permission.getIpRanges() ); return rule; }
for (IpPermission perm : group.getIpPermissions()) if (perm.getFromPort() == from && perm.getToPort() == to) ipPermissions.addAll(perm.getIpRanges()); for (IpPermission perm : group.getIpPermissions()) if (perm.getFromPort() == from && perm.getToPort() == to) ipPermissions.addAll(perm.getIpRanges());
/** * One or more IP ranges. * <p> * Returns a reference to this object so that method calls can be chained together. * * @param ipRanges One or more IP ranges. * * @return A reference to this updated object so that method calls can be chained * together. */ public IpPermission withIpRanges(String... ipRanges) { if (getIpRanges() == null) setIpRanges(new java.util.ArrayList<String>(ipRanges.length)); for (String value : ipRanges) { getIpRanges().add(value); } return this; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getIpProtocol() == null) ? 0 : getIpProtocol().hashCode()); hashCode = prime * hashCode + ((getFromPort() == null) ? 0 : getFromPort().hashCode()); hashCode = prime * hashCode + ((getToPort() == null) ? 0 : getToPort().hashCode()); hashCode = prime * hashCode + ((getUserIdGroupPairs() == null) ? 0 : getUserIdGroupPairs().hashCode()); hashCode = prime * hashCode + ((getIpRanges() == null) ? 0 : getIpRanges().hashCode()); hashCode = prime * hashCode + ((getPrefixListIds() == null) ? 0 : getPrefixListIds().hashCode()); return hashCode; }
/** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getIpProtocol() != null) sb.append("IpProtocol: " + getIpProtocol() + ","); if (getFromPort() != null) sb.append("FromPort: " + getFromPort() + ","); if (getToPort() != null) sb.append("ToPort: " + getToPort() + ","); if (getUserIdGroupPairs() != null) sb.append("UserIdGroupPairs: " + getUserIdGroupPairs() + ","); if (getIpRanges() != null) sb.append("IpRanges: " + getIpRanges() + ","); if (getPrefixListIds() != null) sb.append("PrefixListIds: " + getPrefixListIds() ); sb.append("}"); return sb.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof IpPermission == false) return false; IpPermission other = (IpPermission)obj; if (other.getIpProtocol() == null ^ this.getIpProtocol() == null) return false; if (other.getIpProtocol() != null && other.getIpProtocol().equals(this.getIpProtocol()) == false) return false; if (other.getFromPort() == null ^ this.getFromPort() == null) return false; if (other.getFromPort() != null && other.getFromPort().equals(this.getFromPort()) == false) return false; if (other.getToPort() == null ^ this.getToPort() == null) return false; if (other.getToPort() != null && other.getToPort().equals(this.getToPort()) == false) return false; if (other.getUserIdGroupPairs() == null ^ this.getUserIdGroupPairs() == null) return false; if (other.getUserIdGroupPairs() != null && other.getUserIdGroupPairs().equals(this.getUserIdGroupPairs()) == false) return false; if (other.getIpRanges() == null ^ this.getIpRanges() == null) return false; if (other.getIpRanges() != null && other.getIpRanges().equals(this.getIpRanges()) == false) return false; if (other.getPrefixListIds() == null ^ this.getPrefixListIds() == null) return false; if (other.getPrefixListIds() != null && other.getPrefixListIds().equals(this.getPrefixListIds()) == false) return false; return true; }
ipPermission.getIpRanges().add(StringStaxUnmarshaller.getInstance().unmarshall(context)); continue;
results.setIngressUpdates(targetPermissions.stream().filter(p -> !p.getUserIdGroupPairs().isEmpty() || !p.getIpRanges().isEmpty()).collect(Collectors.toList()));
protected Permission getPermission(IpPermission perm) { checkArgument(CollectionUtils.isEmpty(perm.getUserIdGroupPairs()), "User id / group pairs are not supported"); String protocolName = perm.getIpProtocol(); Integer fromPort = perm.getFromPort(); Integer toPort = perm.getToPort(); List<String> ipRanges = perm.getIpRanges(); Assert.noNulls(fromPort, toPort, ipRanges); Assert.noBlanks(protocolName); Assert.isTrue(fromPort.equals(toPort), "port ranges are not supported"); Protocol protocol = Protocol.valueOf(protocolName.toUpperCase()); return Permission.builder(fromPort).withCidrNotations(ipRanges).withProtocol(protocol).build(); }
/** * List SG ACL's */ public List<String> listACL(int from, int to) { AmazonEC2 client = null; try { client = getEc2Client(); List<String> ipPermissions = new ArrayList<String>(); DescribeSecurityGroupsRequest req = new DescribeSecurityGroupsRequest().withGroupNames(Arrays.asList(config.getACLGroupName())); DescribeSecurityGroupsResult result = client.describeSecurityGroups(req); for (SecurityGroup group : result.getSecurityGroups()) { for (IpPermission perm : group.getIpPermissions()) { if (perm.getFromPort() == from && perm.getToPort() == to) { ipPermissions.addAll(perm.getIpRanges()); } } } return ipPermissions; } finally { if (client != null) client.shutdown(); } }
/** * List SG ACL's */ public List<String> listACL(int from, int to) { AmazonEC2 client = null; try { client = getEc2Client(); List<String> ipPermissions = new ArrayList<String>(); Filter nameFilter = new Filter().withName("group-name").withValues(envVariables.getDynomiteClusterName()); String vpcid = retriever.getVpcId(); if (vpcid == null || vpcid.isEmpty()) { throw new IllegalStateException("vpcid is null even though instance is running in vpc."); } Filter vpcFilter = new Filter().withName("vpc-id").withValues(vpcid); DescribeSecurityGroupsRequest req = new DescribeSecurityGroupsRequest().withFilters(nameFilter, vpcFilter); DescribeSecurityGroupsResult result = client.describeSecurityGroups(req); for (SecurityGroup group : result.getSecurityGroups()) for (IpPermission perm : group.getIpPermissions()) if (perm.getFromPort() == from && perm.getToPort() == to) ipPermissions.addAll(perm.getIpRanges()); logger.info("Fetch current permissions for vpc env of running instance"); return ipPermissions; } finally { if (client != null) client.shutdown(); } }
java.util.List<String> ipRangesList = ipPermissionMember.getIpRanges(); int ipRangesListIndex = 1;
java.util.List<String> ipRangesList = ipPermissionMember.getIpRanges(); int ipRangesListIndex = 1;
java.util.List<String> ipRangesList = ipPermissionMember.getIpRanges(); int ipRangesListIndex = 1;
java.util.List<String> ipRangesList = ipPermissionMember.getIpRanges(); int ipRangesListIndex = 1;