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