Search in sources :

Example 1 with SecurityRuleV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.util.requests.SecurityRuleV4Request in project cloudbreak by hortonworks.

the class SecurityRuleToSecurityRuleV4RequestConverter method convert.

public SecurityRuleV4Request convert(SecurityRule source) {
    SecurityRuleV4Request securityRuleRequest = new SecurityRuleV4Request();
    securityRuleRequest.setPorts(Arrays.asList(source.getPorts()));
    securityRuleRequest.setProtocol(source.getProtocol());
    securityRuleRequest.setSubnet(source.getCidr());
    return securityRuleRequest;
}
Also used : SecurityRuleV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.util.requests.SecurityRuleV4Request)

Example 2 with SecurityRuleV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.util.requests.SecurityRuleV4Request in project cloudbreak by hortonworks.

the class SecurityAccessManifesterTest method instanceGroupRequest.

private InstanceGroupV4Request instanceGroupRequest(int index, InstanceGroupType groupType) {
    InstanceGroupV4Request instanceGroup = new InstanceGroupV4Request();
    instanceGroup.setName("ig-" + index);
    instanceGroup.setNodeCount(1);
    instanceGroup.setType(groupType);
    SecurityGroupV4Request securityGroupV4Request = new SecurityGroupV4Request();
    SecurityRuleV4Request securityRuleV4Request = new SecurityRuleV4Request();
    securityRuleV4Request.setProtocol("tcp");
    securityRuleV4Request.setPorts(List.of("22", "443"));
    securityGroupV4Request.setSecurityRules(Lists.newArrayList(securityRuleV4Request));
    instanceGroup.setSecurityGroup(securityGroupV4Request);
    return instanceGroup;
}
Also used : SecurityGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) SecurityRuleV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.util.requests.SecurityRuleV4Request)

Example 3 with SecurityRuleV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.util.requests.SecurityRuleV4Request in project cloudbreak by hortonworks.

the class SecurityAccessManifester method overrideSecurityAccess.

public void overrideSecurityAccess(InstanceGroupType instanceGroupType, List<InstanceGroupV4Request> instanceGroups, String securityGroupId, String cidrs) {
    instanceGroups.stream().filter(ig -> ig.getType() == instanceGroupType).forEach(ig -> {
        SecurityGroupV4Request securityGroup = ig.getSecurityGroup();
        if (securityGroup == null) {
            securityGroup = new SecurityGroupV4Request();
        }
        if (!internalApiCallCalculator.isInternalApiCall(securityGroup)) {
            if (!Strings.isNullOrEmpty(securityGroupId)) {
                securityGroup.setSecurityGroupIds(getSecurityGroupIds(securityGroupId));
                securityGroup.setSecurityRules(new ArrayList<>());
            } else if (!Strings.isNullOrEmpty(cidrs)) {
                List<SecurityRuleV4Request> generatedSecurityRules = new ArrayList<>();
                List<SecurityRuleV4Request> originalSecurityRules = securityGroup.getSecurityRules();
                for (String cidr : CidrUtil.cidrs(cidrs)) {
                    SecurityRuleUtil.propagateCidr(generatedSecurityRules, originalSecurityRules, cidr);
                }
                // Because of YCLOUD we should not set this if null
                if (originalSecurityRules != null) {
                    securityGroup.setSecurityRules(generatedSecurityRules);
                }
                securityGroup.setSecurityGroupIds(new HashSet<>());
            } else {
                securityGroup.setSecurityGroupIds(new HashSet<>());
                securityGroup.setSecurityRules(new ArrayList<>());
            }
        }
    });
}
Also used : SecurityRuleV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.util.requests.SecurityRuleV4Request) SecurityGroupSeparator.getSecurityGroupIds(com.sequenceiq.cloudbreak.util.SecurityGroupSeparator.getSecurityGroupIds) ArrayList(java.util.ArrayList) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) List(java.util.List) SecurityGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request) CidrUtil(com.sequenceiq.cloudbreak.util.CidrUtil) Service(org.springframework.stereotype.Service) SecurityRuleUtil(com.sequenceiq.cloudbreak.api.endpoint.v4.util.SecurityRuleUtil) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) SecurityGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet)

Example 4 with SecurityRuleV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.util.requests.SecurityRuleV4Request in project cloudbreak by hortonworks.

the class InstanceGroupV1ToInstanceGroupV4ConverterTest method generateRule.

private static SecurityRuleV4Request generateRule(InstanceGroupType instanceGroupType, String cidr) {
    SecurityRuleV4Request request = new SecurityRuleV4Request();
    request.setProtocol("tcp");
    request.setPorts(instanceGroupType == InstanceGroupType.CORE ? List.of("22") : List.of("22", "9443", "8443", "443"));
    request.setSubnet(cidr);
    return request;
}
Also used : SecurityRuleV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.util.requests.SecurityRuleV4Request)

Example 5 with SecurityRuleV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.util.requests.SecurityRuleV4Request in project cloudbreak by hortonworks.

the class InstanceGroupV1ToInstanceGroupV4Converter method createSecurityGroupFromEnvironment.

private SecurityGroupV4Request createSecurityGroupFromEnvironment(InstanceGroupType type, DetailedEnvironmentResponse environment) {
    if (environment == null) {
        SecurityGroupV4Request response = new SecurityGroupV4Request();
        SecurityRuleV4Request securityRule = new SecurityRuleV4Request();
        securityRule.setProtocol("tcp");
        securityRule.setSubnet("0.0.0.0/0");
        securityRule.setPorts(getPorts(type));
        response.setSecurityRules(List.of(securityRule));
        return response;
    } else {
        Optional<SecurityAccessResponse> securityAccess = Optional.of(environment).map(DetailedEnvironmentResponse::getSecurityAccess);
        if (securityAccess.isPresent() && anyNotNull(securityAccess.get().getSecurityGroupIdForKnox(), securityAccess.get().getDefaultSecurityGroupId(), securityAccess.get().getCidr())) {
            SecurityGroupV4Request securityGroup = new SecurityGroupV4Request();
            SecurityRuleV4Request securityRule = new SecurityRuleV4Request();
            securityRule.setProtocol("tcp");
            securityRule.setPorts(getPorts(type));
            securityGroup.setSecurityRules(List.of(securityRule));
            setupSecurityAccess(type, securityAccess.get(), securityGroup);
            return securityGroup;
        }
    }
    return null;
}
Also used : SecurityGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) SecurityAccessResponse(com.sequenceiq.environment.api.v1.environment.model.response.SecurityAccessResponse) SecurityRuleV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.util.requests.SecurityRuleV4Request)

Aggregations

SecurityRuleV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.util.requests.SecurityRuleV4Request)6 SecurityGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request)3 InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)2 Strings (com.google.common.base.Strings)1 SecurityRuleUtil (com.sequenceiq.cloudbreak.api.endpoint.v4.util.SecurityRuleUtil)1 CidrUtil (com.sequenceiq.cloudbreak.util.CidrUtil)1 SecurityGroupSeparator.getSecurityGroupIds (com.sequenceiq.cloudbreak.util.SecurityGroupSeparator.getSecurityGroupIds)1 InstanceGroupType (com.sequenceiq.common.api.type.InstanceGroupType)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1 SecurityAccessResponse (com.sequenceiq.environment.api.v1.environment.model.response.SecurityAccessResponse)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Inject (javax.inject.Inject)1 Service (org.springframework.stereotype.Service)1