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