Search in sources :

Example 1 with AzureResourceEncryptionParametersDto

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

the class EnvironmentResponseConverter method azureEnvParamsToAzureEnvironmentParams.

private AzureEnvironmentParameters azureEnvParamsToAzureEnvironmentParams(ParametersDto parameters) {
    AzureResourceGroupDto resourceGroupDto = Optional.ofNullable(parameters.getAzureParametersDto()).map(AzureParametersDto::getAzureResourceGroupDto).filter(rgDto -> Objects.nonNull(rgDto.getResourceGroupUsagePattern())).filter(rgDto -> Objects.nonNull(rgDto.getResourceGroupCreation())).orElse(null);
    AzureResourceEncryptionParametersDto resourceEncryptionParametersDto = Optional.ofNullable(parameters.getAzureParametersDto()).map(AzureParametersDto::getAzureResourceEncryptionParametersDto).orElse(null);
    return AzureEnvironmentParameters.builder().withAzureResourceGroup(getIfNotNull(resourceGroupDto, this::azureParametersToAzureResourceGroup)).withResourceEncryptionParameters(getIfNotNull(resourceEncryptionParametersDto, this::azureParametersToAzureResourceEncryptionParameters)).build();
}
Also used : GcpEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters) AzureResourceGroupDto(com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto) NullUtil.getIfNotNull(com.sequenceiq.cloudbreak.util.NullUtil.getIfNotNull) GcpResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.GcpResourceEncryptionParametersDto) ResourceGroupUsage(com.sequenceiq.environment.api.v1.environment.model.request.azure.ResourceGroupUsage) EnvironmentNetworkResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentNetworkResponse) LoggerFactory(org.slf4j.LoggerFactory) AzureResourceEncryptionParameters(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceEncryptionParameters) AuthenticationDto(com.sequenceiq.environment.environment.dto.AuthenticationDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) AzureEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureEnvironmentParameters) GcpResourceEncryptionParameters(com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpResourceEncryptionParameters) SecurityAccessResponse(com.sequenceiq.environment.api.v1.environment.model.response.SecurityAccessResponse) AwsEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters) AwsDiskEncryptionParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsDiskEncryptionParameters) CredentialViewConverter(com.sequenceiq.environment.credential.v1.converter.CredentialViewConverter) ResourceGroupUsagePattern(com.sequenceiq.environment.parameter.dto.ResourceGroupUsagePattern) SimpleEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.SimpleEnvironmentResponse) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) YarnEnvironmentParameters(com.sequenceiq.environment.api.v1.environment.model.request.yarn.YarnEnvironmentParameters) ProxyConfigToProxyResponseConverter(com.sequenceiq.environment.proxy.v1.converter.ProxyConfigToProxyResponseConverter) Tunnel(com.sequenceiq.common.api.type.Tunnel) CredentialToCredentialV1ResponseConverter(com.sequenceiq.environment.credential.v1.converter.CredentialToCredentialV1ResponseConverter) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) SecurityGroupSeparator.getSecurityGroupIds(com.sequenceiq.cloudbreak.util.SecurityGroupSeparator.getSecurityGroupIds) AzureResourceGroup(com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup) TagResponse(com.sequenceiq.environment.api.v1.environment.model.response.TagResponse) NullUtil(com.sequenceiq.cloudbreak.util.NullUtil) SecurityAccessDto(com.sequenceiq.environment.environment.dto.SecurityAccessDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) LocationResponse(com.sequenceiq.environment.api.v1.environment.model.response.LocationResponse) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) EnvironmentAuthenticationResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentAuthenticationResponse) S3GuardRequestParameters(com.sequenceiq.environment.api.v1.environment.model.request.aws.S3GuardRequestParameters) NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) LocationDto(com.sequenceiq.environment.environment.dto.LocationDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) EnvironmentTags(com.sequenceiq.environment.environment.domain.EnvironmentTags) Optional(java.util.Optional) EnvironmentViewDto(com.sequenceiq.environment.environment.dto.EnvironmentViewDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) EnvironmentDeletionType(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentDeletionType) GcpParametersDto(com.sequenceiq.environment.parameter.dto.GcpParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) AzureResourceGroupDto(com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto)

Example 2 with AzureResourceEncryptionParametersDto

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

the class AzureParameterValidator method validateEncryptionParameters.

// CHECKSTYLE:ON
private ValidationResult validateEncryptionParameters(ValidationResultBuilder validationResultBuilder, AzureParametersDto azureParametersDto, String accountId) {
    AzureResourceEncryptionParametersDto azureResourceEncryptionParametersDto = azureParametersDto.getAzureResourceEncryptionParametersDto();
    String encryptionKeyUrl = azureResourceEncryptionParametersDto.getEncryptionKeyUrl();
    String encryptionKeyResourceGroupName = azureResourceEncryptionParametersDto.getEncryptionKeyResourceGroupName();
    if (encryptionKeyUrl != null) {
        if (!entitlementService.isAzureDiskSSEWithCMKEnabled(accountId)) {
            LOGGER.info("Invalid request, CDP_CB_AZURE_DISK_SSE_WITH_CMK entitlement turned off for account {}", accountId);
            return validationResultBuilder.error("You specified encryptionKeyUrl to use Server Side Encryption for Azure Managed disks with CMK, " + "but that feature is currently disabled. Get 'CDP_CB_AZURE_DISK_SSE_WITH_CMK' enabled for your account to use SSE with CMK.").build();
        }
        if (encryptionKeyResourceGroupName == null && USE_MULTIPLE.equals(azureParametersDto.getAzureResourceGroupDto().getResourceGroupUsagePattern())) {
            LOGGER.info("Invalid request, neither --encryption-key-resource-group-name nor --resource-group-name is present.");
            return validationResultBuilder.error("To use Server Side Encryption for Azure Managed disks with CMK, at least one of --encryption-key-resource-group-name or " + "--resource-group-name should be specified. Please provide --resource-group-name, if encryption key is present in the same " + "resource group you wish to create the environment in, or provide --encryption-key-resource-group-name.").build();
        }
    }
    if (encryptionKeyResourceGroupName != null) {
        if (!entitlementService.isAzureDiskSSEWithCMKEnabled(accountId)) {
            LOGGER.info("Invalid request, CDP_CB_AZURE_DISK_SSE_WITH_CMK entitlement turned off for account {}", accountId);
            return validationResultBuilder.error("You specified encryptionKeyResourceGroupName to provide the resource group name which contains the encryption key" + "for Server Side Encryption of Azure Managed disks, but that feature is currently disabled. " + "Get 'CDP_CB_AZURE_DISK_SSE_WITH_CMK' enabled for your account to use SSE with CMK.").build();
        }
        if (encryptionKeyUrl == null) {
            LOGGER.info("Invalid request, encryptionKeyResourceGroupName cannot be specified without encryptionKeyUrl");
            return validationResultBuilder.error("You specified encryptionKeyResourceGroupName to provide the resource group name which contains the encryption key for " + "Server Side Encryption of Azure Managed disks. Please specify encryptionKeyUrl to use Server Side Encryption for " + "Azure Managed disks with CMK.").build();
        }
    }
    String diskEncryptionSetId = azureResourceEncryptionParametersDto.getDiskEncryptionSetId();
    if (diskEncryptionSetId != null) {
        LOGGER.info("Invalid request, diskEncryptionSetId cannot be specified");
        return validationResultBuilder.error("Specifying diskEncryptionSetId in request is Invalid. " + "Please specify encryptionKeyUrl to use Server Side Encryption for Azure Managed disks with CMK.").build();
    }
    LOGGER.debug("Validation of encryption parameters is successful.");
    return validationResultBuilder.build();
}
Also used : AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)

Example 3 with AzureResourceEncryptionParametersDto

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

the class AzureParameterValidator method validate.

@Override
public ValidationResult validate(EnvironmentValidationDto environmentValidationDto, ParametersDto parametersDto, ValidationResultBuilder validationResultBuilder) {
    EnvironmentDto environmentDto = environmentValidationDto.getEnvironmentDto();
    LOGGER.debug("ParametersDto: {}", parametersDto);
    AzureParametersDto azureParametersDto = parametersDto.azureParametersDto();
    if (Objects.isNull(azureParametersDto)) {
        return validationResultBuilder.build();
    }
    ValidationResult validationResult;
    AzureResourceEncryptionParametersDto azureResourceEncryptionParametersDto = azureParametersDto.getAzureResourceEncryptionParametersDto();
    if (azureResourceEncryptionParametersDto != null) {
        validationResult = validateEncryptionParameters(validationResultBuilder, azureParametersDto, environmentDto.getAccountId());
        if (validationResult.hasError()) {
            return validationResult;
        }
    }
    AzureResourceGroupDto azureResourceGroupDto = azureParametersDto.getAzureResourceGroupDto();
    if (Objects.isNull(azureResourceGroupDto)) {
        return validationResultBuilder.build();
    }
    validationResult = validateEntitlement(validationResultBuilder, azureResourceGroupDto, environmentDto.getAccountId());
    if (validationResult.hasError()) {
        return validationResult;
    }
    if (USE_MULTIPLE.equals(azureResourceGroupDto.getResourceGroupUsagePattern())) {
        return validateMultipleResourceGroupUsage(validationResultBuilder, azureResourceGroupDto);
    }
    if (USE_EXISTING.equals(azureResourceGroupDto.getResourceGroupCreation())) {
        return validateExistingResourceGroupUsage(validationResultBuilder, environmentDto, azureResourceGroupDto);
    }
    return validationResultBuilder.build();
}
Also used : AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) AzureResourceGroupDto(com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto)

Example 4 with AzureResourceEncryptionParametersDto

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

the class AzureEnvironmentParametersConverter method postConvert.

@Override
protected void postConvert(BaseParameters baseParameters, Environment environment, ParametersDto parametersDto) {
    super.postConvert(baseParameters, environment, parametersDto);
    AzureParameters azureParameters = (AzureParameters) baseParameters;
    Optional<AzureParametersDto> azureParametersDto = Optional.of(parametersDto).map(ParametersDto::getAzureParametersDto);
    azureParameters.setResourceGroupName(azureParametersDto.map(AzureParametersDto::getAzureResourceGroupDto).map(AzureResourceGroupDto::getName).orElse(null));
    azureParameters.setResourceGroupCreation(azureParametersDto.map(AzureParametersDto::getAzureResourceGroupDto).map(AzureResourceGroupDto::getResourceGroupCreation).orElse(null));
    azureParameters.setResourceGroupUsagePattern(azureParametersDto.map(AzureParametersDto::getAzureResourceGroupDto).map(AzureResourceGroupDto::getResourceGroupUsagePattern).orElse(null));
    azureParameters.setEncryptionKeyUrl(azureParametersDto.map(AzureParametersDto::getAzureResourceEncryptionParametersDto).map(AzureResourceEncryptionParametersDto::getEncryptionKeyUrl).orElse(null));
    azureParameters.setEncryptionKeyResourceGroupName(azureParametersDto.map(AzureParametersDto::getAzureResourceEncryptionParametersDto).map(AzureResourceEncryptionParametersDto::getEncryptionKeyResourceGroupName).orElse(null));
}
Also used : AzureParameters(com.sequenceiq.environment.parameters.dao.domain.AzureParameters) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureResourceGroupDto(com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto)

Example 5 with AzureResourceEncryptionParametersDto

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

the class EnvironmentDetailsToCDPEnvironmentDetailsConverter method convertAzureDetails.

private UsageProto.CDPEnvironmentAzureDetails convertAzureDetails(ParametersDto parametersDto) {
    UsageProto.CDPEnvironmentAzureDetails.Builder builder = UsageProto.CDPEnvironmentAzureDetails.newBuilder();
    if (parametersDto != null) {
        AzureParametersDto azureParametersDto = parametersDto.getAzureParametersDto();
        if (azureParametersDto != null) {
            builder.setSingleResourceGroup(azureParametersDto.getAzureResourceGroupDto().getResourceGroupUsagePattern().isSingleResourceGroup());
            Optional<String> encryptionKeyUrl = Optional.of(azureParametersDto).map(AzureParametersDto::getAzureResourceEncryptionParametersDto).map(AzureResourceEncryptionParametersDto::getEncryptionKeyUrl);
            builder.setResourceEncryptionEnabled(encryptionKeyUrl.isPresent());
        }
    }
    return builder.build();
}
Also used : AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto)

Aggregations

AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)5 AzureParametersDto (com.sequenceiq.environment.parameter.dto.AzureParametersDto)4 AzureResourceGroupDto (com.sequenceiq.environment.parameter.dto.AzureResourceGroupDto)3 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)2 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)2 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 NullUtil (com.sequenceiq.cloudbreak.util.NullUtil)1 NullUtil.getIfNotNull (com.sequenceiq.cloudbreak.util.NullUtil.getIfNotNull)1 SecurityGroupSeparator.getSecurityGroupIds (com.sequenceiq.cloudbreak.util.SecurityGroupSeparator.getSecurityGroupIds)1 ValidationResult (com.sequenceiq.cloudbreak.validation.ValidationResult)1 Tunnel (com.sequenceiq.common.api.type.Tunnel)1 AwsDiskEncryptionParameters (com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsDiskEncryptionParameters)1 AwsEnvironmentParameters (com.sequenceiq.environment.api.v1.environment.model.request.aws.AwsEnvironmentParameters)1 S3GuardRequestParameters (com.sequenceiq.environment.api.v1.environment.model.request.aws.S3GuardRequestParameters)1 AzureEnvironmentParameters (com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureEnvironmentParameters)1 AzureResourceEncryptionParameters (com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceEncryptionParameters)1 AzureResourceGroup (com.sequenceiq.environment.api.v1.environment.model.request.azure.AzureResourceGroup)1 ResourceGroupUsage (com.sequenceiq.environment.api.v1.environment.model.request.azure.ResourceGroupUsage)1 GcpEnvironmentParameters (com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpEnvironmentParameters)1 GcpResourceEncryptionParameters (com.sequenceiq.environment.api.v1.environment.model.request.gcp.GcpResourceEncryptionParameters)1