Search in sources :

Example 1 with ValidationResultBuilder

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();
}
Also used : Environment(com.sequenceiq.environment.environment.domain.Environment) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) CredentialService(com.sequenceiq.environment.credential.service.CredentialService) EnvironmentResourceService(com.sequenceiq.environment.environment.service.EnvironmentResourceService) TagValidator(com.sequenceiq.environment.environment.validation.validators.TagValidator) PublicKeyValidator(com.sequenceiq.environment.environment.validation.validators.PublicKeyValidator) LoggerFactory(org.slf4j.LoggerFactory) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) AuthenticationDto(com.sequenceiq.environment.environment.dto.AuthenticationDto) PublicKeyConnector(com.sequenceiq.cloudbreak.cloud.PublicKeyConnector) StringUtils(org.apache.commons.lang3.StringUtils) AwsEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) HashSet(java.util.HashSet) Value(org.springframework.beans.factory.annotation.Value) EncryptionKeyArnValidator(com.sequenceiq.environment.environment.validation.validators.EncryptionKeyArnValidator) EncryptionKeyUrlValidator(com.sequenceiq.environment.environment.validation.validators.EncryptionKeyUrlValidator) AWS(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.AWS) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) NetworkCreationValidator(com.sequenceiq.environment.environment.validation.validators.NetworkCreationValidator) Matcher(java.util.regex.Matcher) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Map(java.util.Map) FreeIpaCreationAwsSpotParametersDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationAwsSpotParametersDto) PlatformResourceRequest(com.sequenceiq.environment.platformresource.PlatformResourceRequest) ENVIRONMENT(com.sequenceiq.common.model.CredentialType.ENVIRONMENT) BadRequestException(javax.ws.rs.BadRequestException) EnvironmentStatus(com.sequenceiq.environment.environment.EnvironmentStatus) EncryptionKeyValidator(com.sequenceiq.environment.environment.validation.validators.EncryptionKeyValidator) Logger(org.slf4j.Logger) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) EnvironmentEditDto(com.sequenceiq.environment.environment.dto.EnvironmentEditDto) SecurityGroupSeparator.getSecurityGroupIds(com.sequenceiq.cloudbreak.util.SecurityGroupSeparator.getSecurityGroupIds) PlatformParameterService(com.sequenceiq.environment.platformresource.PlatformParameterService) Set(java.util.Set) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) GetCloudParameterException(com.sequenceiq.cloudbreak.cloud.service.GetCloudParameterException) S3GuardRequestParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.S3GuardRequestParameters) NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) FreeIpaCreationAwsParametersDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationAwsParametersDto) Optional(java.util.Optional) GCP(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform.GCP) Pattern(java.util.regex.Pattern) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult)

Example 2 with ValidationResultBuilder

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\"]"));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) CloudSubnet(com.sequenceiq.cloudbreak.cloud.model.CloudSubnet) Test(org.junit.jupiter.api.Test)

Example 3 with ValidationResultBuilder

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!"));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) Test(org.junit.jupiter.api.Test)

Example 4 with ValidationResultBuilder

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."));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Test(org.junit.jupiter.api.Test)

Example 5 with ValidationResultBuilder

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));
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) AzureParams(com.sequenceiq.environment.network.dto.AzureParams) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) EnvironmentValidationDto(com.sequenceiq.environment.environment.dto.EnvironmentValidationDto) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)169 Test (org.junit.jupiter.api.Test)107 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)67 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)62 EnvironmentValidationDto (com.sequenceiq.environment.environment.dto.EnvironmentValidationDto)35 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)33 AzureParams (com.sequenceiq.environment.network.dto.AzureParams)33 Test (org.junit.Test)20 SpiFileSystem (com.sequenceiq.cloudbreak.cloud.model.SpiFileSystem)16 Environment (com.sequenceiq.environment.environment.domain.Environment)11 ObjectStorageMetadataRequest (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataRequest)10 ObjectStorageMetadataResponse (com.sequenceiq.cloudbreak.cloud.model.objectstorage.ObjectStorageMetadataResponse)10 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)10 Credential (com.sequenceiq.environment.credential.domain.Credential)10 Region (com.sequenceiq.environment.environment.domain.Region)9 PlatformResourceRequest (com.sequenceiq.environment.platformresource.PlatformResourceRequest)9 EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)7 InstanceProfile (com.amazonaws.services.identitymanagement.model.InstanceProfile)6 Role (com.amazonaws.services.identitymanagement.model.Role)6 GatewayTopologyV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.topology.GatewayTopologyV4Request)6