use of com.amazonaws.services.ec2.model.RevokeSecurityGroupIngressRequest in project photon-model by vmware.
the class AWSSecurityGroupClient method removeIngressRules.
public DeferredResult<Void> removeIngressRules(String groupId, List<IpPermission> rules) {
if (CollectionUtils.isNotEmpty(rules)) {
RevokeSecurityGroupIngressRequest req = new RevokeSecurityGroupIngressRequest().withGroupId(groupId).withIpPermissions(rules);
String message = "Remove Ingress Rules from AWS Security Group with id [" + groupId + "].";
AWSDeferredResultAsyncHandler<RevokeSecurityGroupIngressRequest, RevokeSecurityGroupIngressResult> handler = new AWSDeferredResultAsyncHandler<RevokeSecurityGroupIngressRequest, RevokeSecurityGroupIngressResult>(this.service, message) {
@Override
protected Exception consumeError(Exception e) {
if (e instanceof AmazonEC2Exception && ((AmazonEC2Exception) e).getErrorCode().equals(SECURITY_GROUP_RULE_NOT_FOUND)) {
Utils.log(AWSUtils.class, AWSUtils.class.getSimpleName(), Level.WARNING, () -> String.format("Ingress rules cannot be removed because " + "they do not exist: %s", Utils.toString(e)));
return null;
} else {
return e;
}
}
};
this.client.revokeSecurityGroupIngressAsync(req, handler);
return handler.toDeferredResult().thenApply(r -> (Void) null);
} else {
return DeferredResult.completed(null);
}
}
Aggregations