Search in sources :

Example 1 with AuthorizeSecurityGroupEgressRequest

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);
}
Also used : AWSUtils(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils) AuthorizeSecurityGroupEgressResult(com.amazonaws.services.ec2.model.AuthorizeSecurityGroupEgressResult) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) AuthorizeSecurityGroupEgressRequest(com.amazonaws.services.ec2.model.AuthorizeSecurityGroupEgressRequest)

Example 2 with AuthorizeSecurityGroupEgressRequest

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);
    }
}
Also used : AWSUtils(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils) AuthorizeSecurityGroupEgressResult(com.amazonaws.services.ec2.model.AuthorizeSecurityGroupEgressResult) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) AmazonEC2Exception(com.amazonaws.services.ec2.model.AmazonEC2Exception) AuthorizeSecurityGroupEgressRequest(com.amazonaws.services.ec2.model.AuthorizeSecurityGroupEgressRequest)

Aggregations

AmazonServiceException (com.amazonaws.AmazonServiceException)2 AmazonEC2Exception (com.amazonaws.services.ec2.model.AmazonEC2Exception)2 AuthorizeSecurityGroupEgressRequest (com.amazonaws.services.ec2.model.AuthorizeSecurityGroupEgressRequest)2 AuthorizeSecurityGroupEgressResult (com.amazonaws.services.ec2.model.AuthorizeSecurityGroupEgressResult)2 AWSUtils (com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils)2