use of com.amazonaws.services.ec2.model.AuthorizeSecurityGroupEgressRequest in project photon-model by vmware.
the class AWSSecurityGroupClient method addInnerEgressRule.
public DeferredResult<Void> addInnerEgressRule(String securityGroupId) {
AuthorizeSecurityGroupEgressRequest req = new AuthorizeSecurityGroupEgressRequest().withGroupId(securityGroupId).withIpPermissions(Collections.singletonList(buildInnerRule(securityGroupId)));
String message = "Create internal Egress Rule on AWS Security Group with id [" + securityGroupId + "].";
AWSDeferredResultAsyncHandler<AuthorizeSecurityGroupEgressRequest, AuthorizeSecurityGroupEgressResult> handler = new AWSDeferredResultAsyncHandler<AuthorizeSecurityGroupEgressRequest, AuthorizeSecurityGroupEgressResult>(this.service, message) {
@Override
protected Exception consumeError(Exception e) {
if (e instanceof AmazonEC2Exception && ((AmazonEC2Exception) e).getErrorCode().equals(SECURITY_GROUP_RULE_DUPLICATE)) {
Utils.log(AWSUtils.class, AWSUtils.class.getSimpleName(), Level.WARNING, () -> String.format("Egress rule already exists: %s", Utils.toString(e)));
return null;
} else {
return e;
}
}
};
this.client.authorizeSecurityGroupEgressAsync(req, handler);
return handler.toDeferredResult().thenApply(r -> (Void) null);
}
use of com.amazonaws.services.ec2.model.AuthorizeSecurityGroupEgressRequest in project photon-model by vmware.
the class AWSSecurityGroupClient method addEgressRules.
public DeferredResult<Void> addEgressRules(String groupId, List<IpPermission> rules) {
if (CollectionUtils.isNotEmpty(rules)) {
AuthorizeSecurityGroupEgressRequest req = new AuthorizeSecurityGroupEgressRequest().withGroupId(groupId).withIpPermissions(rules);
String message = "Create Egress Rules on AWS Security Group with id [" + groupId + "].";
AWSDeferredResultAsyncHandler<AuthorizeSecurityGroupEgressRequest, AuthorizeSecurityGroupEgressResult> handler = new AWSDeferredResultAsyncHandler<AuthorizeSecurityGroupEgressRequest, AuthorizeSecurityGroupEgressResult>(this.service, message) {
@Override
protected Exception consumeError(Exception e) {
if (e instanceof AmazonEC2Exception && ((AmazonEC2Exception) e).getErrorCode().equals(SECURITY_GROUP_RULE_DUPLICATE)) {
Utils.log(AWSUtils.class, AWSUtils.class.getSimpleName(), Level.WARNING, () -> String.format("Egress rules already exist: %s", Utils.toString(e)));
return null;
} else {
return e;
}
}
};
this.client.authorizeSecurityGroupEgressAsync(req, handler);
return handler.toDeferredResult().thenApply(r -> (Void) null);
} else {
return DeferredResult.completed(null);
}
}
Aggregations