use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class EnvironmentValidatorService method validateEncryptionKey.
public ValidationResult validateEncryptionKey(EnvironmentCreationDto creationDto) {
ValidationResultBuilder resultBuilder = ValidationResult.builder();
if (GCP.name().equalsIgnoreCase(creationDto.getCloudPlatform())) {
String encryptionKey = Optional.ofNullable(creationDto.getParameters()).map(parametersDto -> parametersDto.getGcpParametersDto()).map(gcpParametersDto -> gcpParametersDto.getGcpResourceEncryptionParametersDto()).map(gcpREParamsDto -> gcpREParamsDto.getEncryptionKey()).orElse(null);
if (StringUtils.isNotEmpty(encryptionKey)) {
if (!entitlementService.isGcpDiskEncryptionWithCMEKEnabled(creationDto.getAccountId())) {
resultBuilder.error(String.format("You have specified encryption-key to enable encryption for GCP resources with CMEK " + "but that feature is currently not enabled for this account." + " Please get 'CDP_CB_GCP_DISK_ENCRYPTION_WITH_CMEK' enabled for this account."));
} else {
ValidationResult validationResult = encryptionKeyValidator.validateEncryptionKey(encryptionKey);
resultBuilder.merge(validationResult);
}
}
}
return resultBuilder.build();
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenNetworkIdWithSubnetsNotExistsOnAzure.
@Test
void testValidateDuringRequestWhenNetworkIdWithSubnetsNotExistsOnAzure() {
int numberOfSubnets = 2;
AzureParams azureParams = NetworkTestUtils.getAzureParams(true, true, true);
NetworkDto networkDto = NetworkTestUtils.getNetworkDto(azureParams, null, null, azureParams.getNetworkId(), null, numberOfSubnets);
EnvironmentDto environmentDto = new EnvironmentDto();
EnvironmentValidationDto environmentValidationDto = EnvironmentValidationDto.builder().withEnvironmentDto(environmentDto).build();
when(cloudNetworkService.retrieveSubnetMetadata(environmentDto, networkDto)).thenReturn(Map.of(networkDto.getSubnetIds().stream().findFirst().get(), new CloudSubnet()));
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
underTest.validateDuringFlow(environmentValidationDto, networkDto, resultBuilder);
NetworkTestUtils.checkErrorsPresent(resultBuilder, List.of("If networkId (aNetworkId) and resourceGroupName (aResourceGroupId) are specified then" + " subnet ids must be specified and should exist on azure as well. Given subnetids: [\"key1\", \"key0\"], existing ones: [\"key1\"]"));
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringFlowWhenPrivateEndpointAndMultipleResourceGroup.
@Test
void testValidateDuringFlowWhenPrivateEndpointAndMultipleResourceGroup() {
ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
AzureParams azureParams = getAzureParams("", "networkResourceGroupName");
NetworkDto networkDto = getNetworkDto(azureParams);
when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(getCloudSubnets(false));
when(azureCloudSubnetParametersService.isPrivateEndpointNetworkPoliciesDisabled(any())).thenCallRealMethod();
EnvironmentValidationDto environmentValidationDto = environmentValidationDtoWithSingleRg(null, ResourceGroupUsagePattern.USE_MULTIPLE);
underTest.validateDuringFlow(environmentValidationDto, networkDto, validationResultBuilder);
assertTrue(validationResultBuilder.build().hasError());
NetworkTestUtils.checkErrorsPresent(validationResultBuilder, List.of("Private endpoint creation is not supported for multiple resource group deployment model, please use single single " + "resource groups to be able to use private endpoints in Azure!"));
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringRequestWhenNoNetworkCidrAndNoNetworkId.
@Test
void testValidateDuringRequestWhenNoNetworkCidrAndNoNetworkId() {
AzureParams azureParams = NetworkTestUtils.getAzureParams(true, false, true);
NetworkDto networkDto = NetworkTestUtils.getNetworkDto(azureParams, null, null, azureParams.getNetworkId(), null, 1);
ValidationResultBuilder resultBuilder = new ValidationResultBuilder();
underTest.validateDuringRequest(networkDto, resultBuilder);
NetworkTestUtils.checkErrorsPresent(resultBuilder, List.of("If resourceGroupName is specified, then networkId must be specified too.", "Either the AZURE network id or cidr needs to be defined!", "If subnetIds are specified, then networkId must be specified too."));
}
use of com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder in project cloudbreak by hortonworks.
the class AzureEnvironmentNetworkValidatorTest method testValidateDuringFlowWhenPrivateEndpointAndNetworkLinkAlreadyExists.
@Test
void testValidateDuringFlowWhenPrivateEndpointAndNetworkLinkAlreadyExists() {
ValidationResultBuilder envValidationResultBuilder = new ValidationResultBuilder();
ValidationResultBuilder azureValidationResultBuilder = new ValidationResultBuilder();
String message = "Network link for the network aNetworkLink already exists for Private DNS Zone " + "privatelink.postgres.database.azure.com in resource group mySingleRg. Please ensure that there is no existing network link and try again!";
EnvironmentValidationDto environmentValidationDto = environmentValidationDtoWithSingleRg(MY_SINGLE_RG, ResourceGroupUsagePattern.USE_SINGLE);
AzureParams azureParams = getAzureParams("", "networkResourceGroupName");
NetworkDto networkDto = getNetworkDto(azureParams);
when(cloudNetworkService.retrieveSubnetMetadata(any(EnvironmentDto.class), any())).thenReturn(getCloudSubnets(false));
when(azureCloudSubnetParametersService.isPrivateEndpointNetworkPoliciesDisabled(any())).thenCallRealMethod();
when(azureNetworkLinkService.validateExistingNetworkLink(any(), any(), eq(MY_SINGLE_RG))).thenReturn(azureValidationResultBuilder.error(message).build());
underTest.validateDuringFlow(environmentValidationDto, networkDto, envValidationResultBuilder);
assertTrue(envValidationResultBuilder.build().hasError());
NetworkTestUtils.checkErrorsPresent(envValidationResultBuilder, List.of(message));
}
Aggregations