Search in sources :

Example 1 with EnvironmentCreationDto

use of com.sequenceiq.environment.environment.dto.EnvironmentCreationDto 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 EnvironmentCreationDto

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

the class EnvironmentApiConverterTest method testAzureSingleRgEnabledAndEmptyAzureRequest.

@Test
void testAzureSingleRgEnabledAndEmptyAzureRequest() {
    EnvironmentRequest request = createEnvironmentRequest(AZURE);
    request.setAzure(null);
    FreeIpaCreationDto freeIpaCreationDto = mock(FreeIpaCreationDto.class);
    EnvironmentTelemetry environmentTelemetry = mock(EnvironmentTelemetry.class);
    AccountTelemetry accountTelemetry = mock(AccountTelemetry.class);
    Features features = mock(Features.class);
    NetworkDto networkDto = mock(NetworkDto.class);
    when(credentialService.getCloudPlatformByCredential(anyString(), anyString(), any())).thenReturn(AZURE.name());
    when(freeIpaConverter.convert(request.getFreeIpa(), "id", CloudConstants.AWS)).thenReturn(freeIpaCreationDto);
    when(accountTelemetry.getFeatures()).thenReturn(features);
    when(accountTelemetryService.getOrDefault(any())).thenReturn(accountTelemetry);
    when(telemetryApiConverter.convert(eq(request.getTelemetry()), any(), anyString())).thenReturn(environmentTelemetry);
    when(tunnelConverter.convert(request.getTunnel())).thenReturn(request.getTunnel());
    when(networkRequestToDtoConverter.convert(request.getNetwork())).thenReturn(networkDto);
    EnvironmentCreationDto actual = testInitCreationDto(request);
    assertEquals(ResourceGroupUsagePattern.USE_MULTIPLE, actual.getParameters().getAzureParametersDto().getAzureResourceGroupDto().getResourceGroupUsagePattern());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) EnvironmentTelemetry(com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry) FreeIpaCreationDto(com.sequenceiq.environment.environment.dto.FreeIpaCreationDto) AccountTelemetry(com.sequenceiq.environment.telemetry.domain.AccountTelemetry) EnvironmentRequest(com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest) Features(com.sequenceiq.common.api.telemetry.model.Features) ExperimentalFeatures(com.sequenceiq.environment.environment.domain.ExperimentalFeatures) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with EnvironmentCreationDto

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

the class EnvironmentController method post.

@Override
@CheckPermissionByAccount(action = AuthorizationResourceAction.CREATE_ENVIRONMENT)
@CheckPermissionByRequestProperty(path = "credentialName", type = NAME, action = DESCRIBE_CREDENTIAL)
public DetailedEnvironmentResponse post(@RequestObject @Valid EnvironmentRequest request) {
    EnvironmentCreationDto environmentCreationDto = environmentApiConverter.initCreationDto(request);
    EnvironmentDto envDto = environmentCreationService.create(environmentCreationDto);
    return environmentResponseConverter.dtoToDetailedResponse(envDto);
}
Also used : EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) CheckPermissionByRequestProperty(com.sequenceiq.authorization.annotation.CheckPermissionByRequestProperty) CheckPermissionByAccount(com.sequenceiq.authorization.annotation.CheckPermissionByAccount)

Example 4 with EnvironmentCreationDto

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

the class EnvironmentCreationServiceTest method testParameterVerificationError.

@Test
void testParameterVerificationError() {
    ParametersDto parametersDto = ParametersDto.builder().withAwsParameters(AwsParametersDto.builder().withDynamoDbTableName("dynamo").build()).build();
    final EnvironmentCreationDto environmentCreationDto = EnvironmentCreationDto.builder().withName(ENVIRONMENT_NAME).withAccountId(ACCOUNT_ID).withAuthentication(AuthenticationDto.builder().build()).withCreator(CRN).withAccountId(ACCOUNT_ID).withParameters(parametersDto).withLocation(LocationDto.builder().withName("test").withDisplayName("test").withLatitude(0.1).withLongitude(0.1).build()).build();
    final Environment environment = new Environment();
    environment.setName(ENVIRONMENT_NAME);
    environment.setId(1L);
    environment.setAccountId(ACCOUNT_ID);
    Credential credential = new Credential();
    credential.setCloudPlatform("platform");
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    validationResultBuilder.error("error");
    when(environmentService.isNameOccupied(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(false);
    when(environmentDtoConverter.creationDtoToEnvironment(eq(environmentCreationDto))).thenReturn(environment);
    when(environmentResourceService.getCredentialFromRequest(any(), eq(ACCOUNT_ID))).thenReturn(credential);
    when(authenticationDtoConverter.dtoToAuthentication(any())).thenReturn(new EnvironmentAuthentication());
    when(validatorService.validateNetworkCreation(any(), any())).thenReturn(validationResultBuilder);
    when(environmentService.getRegionsByEnvironment(eq(environment))).thenReturn(getCloudRegions());
    when(environmentDtoConverter.environmentToLocationDto(any(Environment.class))).thenReturn(LocationDto.builder().withName("loc").build());
    when(validatorService.validateParentChildRelation(any(), any())).thenReturn(ValidationResult.builder().build());
    when(validatorService.validateFreeIpaCreation(any())).thenReturn(ValidationResult.builder().build());
    when(validationResult.merge(any())).thenReturn(ValidationResult.builder().error("nogood"));
    when(environmentService.save(any())).thenReturn(environment);
    assertThrows(BadRequestException.class, () -> environmentCreationServiceUnderTest.create(environmentCreationDto));
    verify(validatorService, Mockito.times(1)).validatePublicKey(any());
    verify(environmentService, never()).save(any());
    verify(environmentResourceService, never()).createAndSetNetwork(any(), any(), any(), any(), any());
    verify(reactorFlowManager, never()).triggerCreationFlow(anyLong(), eq(ENVIRONMENT_NAME), eq(USER), anyString());
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Environment(com.sequenceiq.environment.environment.domain.Environment) AwsDiskEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto) ParametersDto(com.sequenceiq.environment.parameter.dto.ParametersDto) AzureParametersDto(com.sequenceiq.environment.parameter.dto.AzureParametersDto) AzureResourceEncryptionParametersDto(com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto) AwsParametersDto(com.sequenceiq.environment.parameter.dto.AwsParametersDto) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with EnvironmentCreationDto

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

the class EnvironmentCreationServiceTest method testEncryptionKeyUrlValidationError.

@Test
void testEncryptionKeyUrlValidationError() {
    final EnvironmentCreationDto environmentCreationDto = EnvironmentCreationDto.builder().withName(ENVIRONMENT_NAME).withCloudPlatform("AZURE").withCreator(CRN).withAccountId(ACCOUNT_ID).withAuthentication(AuthenticationDto.builder().build()).withParameters(ParametersDto.builder().withAzureParameters(AzureParametersDto.builder().withEncryptionParameters(AzureResourceEncryptionParametersDto.builder().withEncryptionKeyUrl("dummy-key-url").build()).build()).build()).build();
    final Environment environment = new Environment();
    environment.setName(ENVIRONMENT_NAME);
    environment.setId(1L);
    environment.setAccountId(ACCOUNT_ID);
    Credential credential = new Credential();
    credential.setCloudPlatform("AZURE");
    ValidationResultBuilder validationResultBuilder = new ValidationResultBuilder();
    validationResultBuilder.error("error");
    when(validatorService.validateEncryptionKeyUrl(any(), any())).thenReturn(validationResultBuilder.build());
    when(environmentService.isNameOccupied(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(false);
    when(environmentDtoConverter.creationDtoToEnvironment(eq(environmentCreationDto))).thenReturn(environment);
    when(environmentResourceService.getCredentialFromRequest(any(), any())).thenReturn(credential);
    when(validatorService.validateParentChildRelation(any(), any())).thenReturn(ValidationResult.builder().build());
    when(validatorService.validateNetworkCreation(any(), any())).thenReturn(ValidationResult.builder());
    when(validatorService.validateFreeIpaCreation(any())).thenReturn(ValidationResult.builder().build());
    when(authenticationDtoConverter.dtoToAuthentication(any())).thenReturn(new EnvironmentAuthentication());
    when(entitlementService.azureEnabled(eq(ACCOUNT_ID))).thenReturn(true);
    when(environmentService.save(any())).thenReturn(environment);
    assertThrows(BadRequestException.class, () -> environmentCreationServiceUnderTest.create(environmentCreationDto));
}
Also used : Credential(com.sequenceiq.environment.credential.domain.Credential) EnvironmentAuthentication(com.sequenceiq.environment.environment.domain.EnvironmentAuthentication) ValidationResultBuilder(com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder) Environment(com.sequenceiq.environment.environment.domain.Environment) EnvironmentCreationDto(com.sequenceiq.environment.environment.dto.EnvironmentCreationDto) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

EnvironmentCreationDto (com.sequenceiq.environment.environment.dto.EnvironmentCreationDto)21 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)18 Test (org.junit.jupiter.api.Test)16 Environment (com.sequenceiq.environment.environment.domain.Environment)11 Credential (com.sequenceiq.environment.credential.domain.Credential)10 EnvironmentAuthentication (com.sequenceiq.environment.environment.domain.EnvironmentAuthentication)9 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)9 EnvironmentRequest (com.sequenceiq.environment.api.v1.environment.model.request.EnvironmentRequest)8 ExperimentalFeatures (com.sequenceiq.environment.environment.domain.ExperimentalFeatures)8 FreeIpaCreationDto (com.sequenceiq.environment.environment.dto.FreeIpaCreationDto)8 EnvironmentTelemetry (com.sequenceiq.environment.environment.dto.telemetry.EnvironmentTelemetry)8 ValidationResultBuilder (com.sequenceiq.cloudbreak.validation.ValidationResult.ValidationResultBuilder)7 Features (com.sequenceiq.common.api.telemetry.model.Features)7 ParametersDto (com.sequenceiq.environment.parameter.dto.ParametersDto)6 AccountTelemetry (com.sequenceiq.environment.telemetry.domain.AccountTelemetry)6 AwsDiskEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AwsDiskEncryptionParametersDto)5 AwsParametersDto (com.sequenceiq.environment.parameter.dto.AwsParametersDto)5 AzureParametersDto (com.sequenceiq.environment.parameter.dto.AzureParametersDto)5 AzureResourceEncryptionParametersDto (com.sequenceiq.environment.parameter.dto.AzureResourceEncryptionParametersDto)5 EnvironmentBackup (com.sequenceiq.environment.environment.dto.EnvironmentBackup)4