Search in sources :

Example 1 with SecurityGroupV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request in project cloudbreak by hortonworks.

the class InstanceGroupV1ToInstanceGroupV4ConverterTest method createSecurityGroupFromEnvironmentTestForConvertTo.

// CHECKSTYLE:ON
// @formatter:on
@ParameterizedTest(name = "{0}")
@MethodSource("securityAccessDataProviderForConvertTo")
void createSecurityGroupFromEnvironmentTestForConvertTo(String testCaseName, InstanceGroupType instanceGroupType, boolean environmentSet, boolean securityAccessSet, String cidr, String defaultSecurityGroupId, String securityGroupIdKnox, boolean securityGroupExpected, boolean cidrExpected, Set<String> expectedSecurityGroups) {
    when(instanceGroupParameterConverter.convert(AWS_INSTANCE_GROUP_V1_PARAMETERS)).thenReturn(AWS_INSTANCE_GROUP_V4_PARAMETERS);
    DetailedEnvironmentResponse environment = environmentSet ? prepareEnvironment(securityAccessSet, cidr, defaultSecurityGroupId, securityGroupIdKnox) : null;
    if (environmentSet) {
        when(instanceTemplateConverter.convert(any(InstanceTemplateV1Request.class), eq(environment))).thenReturn(INSTANCE_TEMPLATE_V4_REQUEST);
    }
    Set<InstanceGroupV1Request> instanceGroups = prepareInstanceGroupV1Requests(instanceGroupType);
    List<InstanceGroupV4Request> results = underTest.convertTo(null, instanceGroups, environment);
    assertThat(results).hasSameSizeAs(instanceGroups);
    InstanceGroupV4Request first = results.get(0);
    assertThat(first.getType()).isEqualTo(instanceGroupType);
    SecurityGroupV4Request securityGroup = first.getSecurityGroup();
    assertThat(securityGroup != null).isEqualTo(securityGroupExpected);
    if (securityGroupExpected) {
        if (securityGroup.getSecurityGroupIds() != null) {
            assertThat(securityGroup.getSecurityGroupIds()).hasSameElementsAs(expectedSecurityGroups);
            assertThat(securityGroup.getSecurityRules()).usingFieldByFieldElementComparator().hasSameElementsAs(cidrExpected ? List.of(generateRule(instanceGroupType, cidr)) : List.of());
        }
    }
}
Also used : InstanceGroupV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request) InstanceTemplateV1Request(com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.InstanceTemplateV1Request) SecurityGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 2 with SecurityGroupV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request in project cloudbreak by hortonworks.

the class SdxService method prepareDefaultSecurityConfigs.

protected StackV4Request prepareDefaultSecurityConfigs(StackV4Request internalRequest, StackV4Request stackV4Request, CloudPlatform cloudPlatform) {
    if (internalRequest == null && !List.of("MOCK", "YARN").contains(cloudPlatform.name())) {
        stackV4Request.getInstanceGroups().forEach(instance -> {
            SecurityGroupV4Request groupRequest = new SecurityGroupV4Request();
            if (InstanceGroupType.CORE.equals(instance.getType())) {
                groupRequest.setSecurityRules(rulesWithPorts("22"));
            } else if (InstanceGroupType.GATEWAY.equals(instance.getType())) {
                groupRequest.setSecurityRules(rulesWithPorts("443", "22"));
            } else {
                throw new IllegalStateException("Unknown instance group type " + instance.getType());
            }
            instance.setSecurityGroup(groupRequest);
        });
    }
    return stackV4Request;
}
Also used : SecurityGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request)

Example 3 with SecurityGroupV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request 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 4 with SecurityGroupV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request 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 5 with SecurityGroupV4Request

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request in project cloudbreak by hortonworks.

the class SecurityGroupToSecurityGroupV4RequestConverter method convert.

public SecurityGroupV4Request convert(@Nonnull SecurityGroup source) {
    SecurityGroupV4Request securityGroupV2Request = new SecurityGroupV4Request();
    securityGroupV2Request.setSecurityGroupIds(source.getSecurityGroupIds());
    securityGroupV2Request.setSecurityRules(new ArrayList<>());
    for (SecurityRule securityRule : source.getSecurityRules()) {
        securityGroupV2Request.getSecurityRules().add(securityRuleToSecurityRuleV4RequestConverter.convert(securityRule));
    }
    return securityGroupV2Request;
}
Also used : SecurityGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request) SecurityRule(com.sequenceiq.cloudbreak.domain.SecurityRule)

Aggregations

SecurityGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.securitygroup.SecurityGroupV4Request)6 InstanceGroupV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request)3 SecurityRuleV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.util.requests.SecurityRuleV4Request)3 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)2 Strings (com.google.common.base.Strings)1 SecurityRuleUtil (com.sequenceiq.cloudbreak.api.endpoint.v4.util.SecurityRuleUtil)1 SecurityRule (com.sequenceiq.cloudbreak.domain.SecurityRule)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 InstanceGroupV1Request (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.InstanceGroupV1Request)1 InstanceTemplateV1Request (com.sequenceiq.distrox.api.v1.distrox.model.instancegroup.template.InstanceTemplateV1Request)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 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1 Service (org.springframework.stereotype.Service)1