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