Search in sources :

Example 1 with GcpResourceEncryptionParametersDto

use of com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto in project cloudbreak by hortonworks.

the class EnvironmentDetailsToCDPEnvironmentDetailsConverter method convertGcpDetails.

private UsageProto.CDPEnvironmentGcpDetails convertGcpDetails(ParametersDto parametersDto) {
    UsageProto.CDPEnvironmentGcpDetails.Builder builder = UsageProto.CDPEnvironmentGcpDetails.newBuilder();
    if (parametersDto != null) {
        GcpParametersDto gcpParametersDto = parametersDto.getGcpParametersDto();
        if (gcpParametersDto != null) {
            Optional<String> encryptionKey = Optional.of(gcpParametersDto).map(GcpParametersDto::getGcpResourceEncryptionParametersDto).map(GcpResourceEncryptionParametersDto::getEncryptionKey);
            builder.setResourceEncryptionEnabled(encryptionKey.isPresent());
        }
    }
    return builder.build();
}
Also used : GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto)

Example 2 with GcpResourceEncryptionParametersDto

use of com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto in project cloudbreak by hortonworks.

the class GcpEnvironmentParametersConverter method postConvert.

@Override
protected void postConvert(BaseParameters baseParameters, Environment environment, ParametersDto parametersDto) {
    super.postConvert(baseParameters, environment, parametersDto);
    GcpParameters gcpParameters = (GcpParameters) baseParameters;
    Optional<GcpParametersDto> gcpParametersDto = Optional.of(parametersDto).map(ParametersDto::getGcpParametersDto);
    gcpParameters.setEncryptionKey(gcpParametersDto.map(GcpParametersDto::getGcpResourceEncryptionParametersDto).map(GcpResourceEncryptionParametersDto::getEncryptionKey).orElse(null));
}
Also used : GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) GcpParameters(com.sequenceiq.environment.parameters.dao.domain.GcpParameters)

Example 3 with GcpResourceEncryptionParametersDto

use of com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto in project cloudbreak by hortonworks.

the class GcpParameterValidator method validate.

@Override
public ValidationResult validate(EnvironmentValidationDto environmentValidationDto, ParametersDto parametersDto, ValidationResultBuilder validationResultBuilder) {
    EnvironmentDto environmentDto = environmentValidationDto.getEnvironmentDto();
    LOGGER.debug("ParametersDto: {}", parametersDto);
    GcpParametersDto gcpParametersDto = parametersDto.getGcpParametersDto();
    if (Objects.isNull(gcpParametersDto)) {
        return validationResultBuilder.build();
    }
    ValidationResult validationResult;
    GcpResourceEncryptionParametersDto gcpResourceEncryptionParametersDto = gcpParametersDto.getGcpResourceEncryptionParametersDto();
    if (gcpResourceEncryptionParametersDto != null) {
        validationResult = validateGcpEncryptionParameters(validationResultBuilder, gcpParametersDto, environmentDto.getAccountId());
        if (validationResult.hasError()) {
            return validationResult;
        }
    }
    return validationResultBuilder.build();
}
Also used : GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult)

Example 4 with GcpResourceEncryptionParametersDto

use of com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto in project cloudbreak by hortonworks.

the class EnvironmentModificationService method editEnvironmentParameters.

private void editEnvironmentParameters(EnvironmentEditDto editDto, Environment environment) {
    ParametersDto parametersDto = editDto.getParameters();
    if (parametersDto != null) {
        Optional<BaseParameters> original = parametersService.findByEnvironment(environment.getId());
        if (original.isPresent()) {
            BaseParameters originalParameters = original.get();
            parametersDto.setId(originalParameters.getId());
            if (originalParameters instanceof AwsParameters) {
                AwsParameters awsOriginalParameters = (AwsParameters) originalParameters;
                parametersDto.getAwsParametersDto().setFreeIpaSpotPercentage(awsOriginalParameters.getFreeIpaSpotPercentage());
                validateAwsParameters(environment, parametersDto);
            }
        }
        if (parametersDto.getGcpParametersDto() != null) {
            String encryptionKey = Optional.of(parametersDto.getGcpParametersDto()).map(GcpParametersDto::getGcpResourceEncryptionParametersDto).map(GcpResourceEncryptionParametersDto::getEncryptionKey).orElse(null);
            ValidationResult validationResult = environmentService.getValidatorService().validateEncryptionKey(encryptionKey, editDto.getAccountId());
            if (validationResult.hasError()) {
                throw new BadRequestException(validationResult.getFormattedErrors());
            }
        }
        BaseParameters parameters = parametersService.saveParameters(environment, parametersDto);
        if (parameters != null) {
            environment.setParameters(parameters);
        }
    }
}
Also used : GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) AwsParameters(com.sequenceiq.environment.parameters.dao.domain.AwsParameters) BadRequestException(javax.ws.rs.BadRequestException) GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) BaseParameters(com.sequenceiq.environment.parameters.dao.domain.BaseParameters)

Example 5 with GcpResourceEncryptionParametersDto

use of com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto in project cloudbreak by hortonworks.

the class GcpParameterValidator method validateGcpEncryptionParameters.

private ValidationResult validateGcpEncryptionParameters(ValidationResultBuilder validationResultBuilder, GcpParametersDto gcpParametersDto, String accountId) {
    GcpResourceEncryptionParametersDto gcpResourceEncryptionParametersDto = gcpParametersDto.getGcpResourceEncryptionParametersDto();
    String encryptionKey = gcpResourceEncryptionParametersDto.getEncryptionKey();
    if (encryptionKey != null) {
        if (!entitlementService.isGcpDiskEncryptionWithCMEKEnabled(accountId)) {
            LOGGER.info("Invalid request, CDP_CB_GCP_DISK_ENCRYPTION_WITH_CMEK entitlement turned off for account {}", accountId);
            return validationResultBuilder.error("You specified encryptionKey to encrypt resources with CMEK, " + "but that feature is currently disabled." + "Get 'CDP_CB_GCP_DISK_ENCRYPTION_WITH_CMEK' enabled for your account to use resource encryption with CMEK.").build();
        }
    }
    LOGGER.debug("Validation of encryption parameters is successful.");
    return validationResultBuilder.build();
}
Also used : GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto)

Aggregations

GcpResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto)5 GcpParametersDto (com.sequenceiq.environment.parameter.dto.GcpParametersDto)4 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)2 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)2 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)1 AwsParameters (com.sequenceiq.environment.parameters.dao.domain.AwsParameters)1 BaseParameters (com.sequenceiq.environment.parameters.dao.domain.BaseParameters)1 GcpParameters (com.sequenceiq.environment.parameters.dao.domain.GcpParameters)1 BadRequestException (javax.ws.rs.BadRequestException)1