@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getSecurityGroups() == null) ? 0 : getSecurityGroups().hashCode()); hashCode = prime * hashCode + ((getNextToken() == null) ? 0 : getNextToken().hashCode()); return hashCode; }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. * * @return A string representation of this object. * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getSecurityGroups() != null) sb.append("SecurityGroups: ").append(getSecurityGroups()).append(","); if (getNextToken() != null) sb.append("NextToken: ").append(getNextToken()); sb.append("}"); return sb.toString(); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof DescribeSecurityGroupsResult == false) return false; DescribeSecurityGroupsResult other = (DescribeSecurityGroupsResult) obj; if (other.getSecurityGroups() == null ^ this.getSecurityGroups() == null) return false; if (other.getSecurityGroups() != null && other.getSecurityGroups().equals(this.getSecurityGroups()) == false) return false; if (other.getNextToken() == null ^ this.getNextToken() == null) return false; if (other.getNextToken() != null && other.getNextToken().equals(this.getNextToken()) == false) return false; return true; }
@Override public Collection<String> listRuleSets() { DescribeSecurityGroupsRequest request = new DescribeSecurityGroupsRequest(); DescribeSecurityGroupsResult result = null; try { result = client.describeSecurityGroups( request ); } catch ( Exception e ) { LOG.warn( "Error while getting security groups", e ); return new LinkedList<String>(); } Collection<String> groups = new ArrayList<String>(); for( SecurityGroup group : result.getSecurityGroups() ) { groups.add( group.getGroupName() ); } return groups; }
@Override public Collection<IpRule> getRules( final String name, final boolean inbound ) { DescribeSecurityGroupsRequest request = new DescribeSecurityGroupsRequest().withGroupNames( name ); DescribeSecurityGroupsResult result = client.describeSecurityGroups( request ); if( result.getSecurityGroups().size() != 1 ) { return null; } Collection<IpRule> ipRules = new ArrayList<IpRule>(); List<IpPermission> permissions; if( inbound ) { permissions = result.getSecurityGroups().get( 0 ).getIpPermissions(); } else { permissions = result.getSecurityGroups().get( 0 ).getIpPermissionsEgress(); } for( IpPermission permission : permissions ) { ipRules.add( toIpRule( permission ) ); } return ipRules; }
ec2.describeSecurityGroups(request); for(SecurityGroup group : response.getSecurityGroups()) { System.out.printf( "Found security group with id %s, " +
Collections.singletonList(config.getACLGroupName())); DescribeSecurityGroupsResult result = client.describeSecurityGroups(req); for (SecurityGroup group : result.getSecurityGroups()) for (IpPermission perm : group.getIpPermissions()) if (perm.getFromPort() == from && perm.getToPort() == to) 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)
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof DescribeSecurityGroupsResult == false) return false; DescribeSecurityGroupsResult other = (DescribeSecurityGroupsResult)obj; if (other.getSecurityGroups() == null ^ this.getSecurityGroups() == null) return false; if (other.getSecurityGroups() != null && other.getSecurityGroups().equals(this.getSecurityGroups()) == false) return false; return true; }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getSecurityGroups() == null) ? 0 : getSecurityGroups().hashCode()); return hashCode; }
protected String getVpcGoupId() { AmazonEC2 client = null; try { client = getEc2Client(); Filter nameFilter = new Filter().withName("group-name").withValues(config.getACLGroupName()); // SG Filter vpcFilter = new Filter().withName("vpc-id").withValues(instanceInfo.getVpcId()); DescribeSecurityGroupsRequest req = new DescribeSecurityGroupsRequest().withFilters(nameFilter, vpcFilter); DescribeSecurityGroupsResult result = client.describeSecurityGroups(req); for (SecurityGroup group : result.getSecurityGroups()) { logger.debug( "got group-id:{} for group-name:{},vpc-id:{}", group.getGroupId(), config.getACLGroupName(), instanceInfo.getVpcId()); return group.getGroupId(); } logger.error( "unable to get group-id for group-name={} vpc-id={}", config.getACLGroupName(), instanceInfo.getVpcId()); return ""; } finally { if (client != null) client.shutdown(); } }
/** * 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 (getSecurityGroups() != null) sb.append("SecurityGroups: " + getSecurityGroups() ); sb.append("}"); return sb.toString(); }
/** * Information about one or more security groups. * <p> * Returns a reference to this object so that method calls can be chained together. * * @param securityGroups Information about one or more security groups. * * @return A reference to this updated object so that method calls can be chained * together. */ public DescribeSecurityGroupsResult withSecurityGroups(SecurityGroup... securityGroups) { if (getSecurityGroups() == null) setSecurityGroups(new java.util.ArrayList<SecurityGroup>(securityGroups.length)); for (SecurityGroup value : securityGroups) { getSecurityGroups().add(value); } return this; }
public DescribeSecurityGroupsResult unmarshall(StaxUnmarshallerContext context) throws Exception { DescribeSecurityGroupsResult describeSecurityGroupsResult = new DescribeSecurityGroupsResult(); int originalDepth = context.getCurrentDepth(); int targetDepth = originalDepth + 1; if (context.isStartOfDocument()) targetDepth += 1; while (true) { int xmlEvent = context.nextEvent(); if (xmlEvent == XmlPullParser.END_DOCUMENT) return describeSecurityGroupsResult; if (xmlEvent == XmlPullParser.START_TAG) { if (context.testExpression("securityGroupInfo/item", targetDepth)) { describeSecurityGroupsResult.getSecurityGroups().add(SecurityGroupStaxUnmarshaller.getInstance().unmarshall(context)); continue; } } else if (xmlEvent == XmlPullParser.END_TAG) { if (context.getCurrentDepth() < originalDepth) { return describeSecurityGroupsResult; } } } }
@Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getSecurityGroups() == null) ? 0 : getSecurityGroups().hashCode()); hashCode = prime * hashCode + ((getNextToken() == null) ? 0 : getNextToken().hashCode()); return hashCode; }
public List<SecurityGroup> findAllSecurityGroups() { DescribeSecurityGroupsRequest securityRequest = new DescribeSecurityGroupsRequest(); DescribeSecurityGroupsResult securityDescription = ec2.describeSecurityGroups(securityRequest); return securityDescription.getSecurityGroups(); }
@Override public List<String> getSecurityGroupNames() { DescribeSecurityGroupsResult result = client.describeSecurityGroups(); List<String> names = newArrayList(); for (SecurityGroup group : result.getSecurityGroups()) { names.add(group.getGroupName()); } Collections.sort(names); return ImmutableList.copyOf(names); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof DescribeSecurityGroupsResult == false) return false; DescribeSecurityGroupsResult other = (DescribeSecurityGroupsResult) obj; if (other.getSecurityGroups() == null ^ this.getSecurityGroups() == null) return false; if (other.getSecurityGroups() != null && other.getSecurityGroups().equals(this.getSecurityGroups()) == false) return false; if (other.getNextToken() == null ^ this.getNextToken() == null) return false; if (other.getNextToken() != null && other.getNextToken().equals(this.getNextToken()) == false) return false; return true; }
public SecurityGroup findOneSecurityGroupByName(String securityGroupName) { DescribeSecurityGroupsRequest securityRequest = new DescribeSecurityGroupsRequest(); securityRequest.setGroupNames(Arrays.asList(securityGroupName)); DescribeSecurityGroupsResult securityDescription = ec2.describeSecurityGroups(securityRequest); return securityDescription.getSecurityGroups().get(0); }
@Override public Optional<SecurityGroup> getSecurityGroup(String name) { checkNotBlank(name, "name"); List<String> names = getSecurityGroupNames(); if (names.contains(name)) { DescribeSecurityGroupsRequest request = new DescribeSecurityGroupsRequest(); request.setGroupNames(Collections.singletonList(name)); DescribeSecurityGroupsResult result = client.describeSecurityGroups(request); List<SecurityGroup> groups = result.getSecurityGroups(); checkState(groups.size() == 1, "Expected exactly 1 security group but there were %s instead", groups.size()); SecurityGroup group = groups.get(0); return Optional.of(group); } else { return Optional.<SecurityGroup> absent(); } }
/** * * @param groupIds * @param ec2Client * @return */ public List<SecurityGroup> getSecurityGroups(List<String> groupIds, AmazonEC2 ec2Client) { DescribeSecurityGroupsRequest request = new DescribeSecurityGroupsRequest(); if (groupIds != null && !groupIds.isEmpty()) { request = request.withGroupIds(groupIds); } DescribeSecurityGroupsResult result = ec2Client.describeSecurityGroups(request); return result.getSecurityGroups(); }