/**
* Authorize and Revoke Security Group Ingress have the same parameters.
*/
private EC2AuthorizeRevokeSecurityGroup toSecurityGroup( String groupName, IpPermissionType[] items ) {
EC2AuthorizeRevokeSecurityGroup request = new EC2AuthorizeRevokeSecurityGroup();
request.setName( groupName );
for (IpPermissionType ipPerm : items) {
EC2IpPermission perm = new EC2IpPermission();
perm.setProtocol( ipPerm.getIpProtocol());
if (ipPerm.getIpProtocol().equalsIgnoreCase("icmp")) {
perm.setIcmpType( Integer.toString(ipPerm.getFromPort()));
perm.setIcmpCode( Integer.toString(ipPerm.getToPort()));
} else {
perm.setFromPort( ipPerm.getFromPort());
perm.setToPort( ipPerm.getToPort());
}
UserIdGroupPairSetType groups = ipPerm.getGroups();
if (null != groups && groups.getItem() != null) {
UserIdGroupPairType[] groupItems = groups.getItem();
for (UserIdGroupPairType groupPair : groupItems) {
EC2SecurityGroup user = new EC2SecurityGroup();
user.setName( groupPair.getGroupName());
user.setAccount( groupPair.getUserId());
perm.addUser( user );
}
}
IpRangeSetType ranges = ipPerm.getIpRanges();
if (ranges != null && ranges.getItem() != null) {
IpRangeItemType[] rangeItems = ranges.getItem();
for (IpRangeItemType ipRange: rangeItems) {
perm.addIpRange( ipRange.getCidrIp() );
perm.setCIDR(ipRange.getCidrIp());
}
}
request.addIpPermission( perm );
}
return request;
}