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());
}
}
}
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;
}
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;
}
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<>());
}
}
});
}
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;
}
Aggregations