use of com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet in project cloudbreak by hortonworks.
the class EnvironmentModificationServiceTest method testUpdateAzureResourceEncryptionParametersByEnvironmentCrn.
@Test
void testUpdateAzureResourceEncryptionParametersByEnvironmentCrn() {
UpdateAzureResourceEncryptionDto updateAzureResourceEncryptionDto = UpdateAzureResourceEncryptionDto.builder().withAzureResourceEncryptionParametersDto(AzureResourceEncryptionParametersDto.builder().withEncryptionKeyUrl("dummyKeyUrl").withEncryptionKeyResourceGroupName("dummyResourceGroupName").build()).build();
CreatedDiskEncryptionSet createdDiskEncryptionSet = new CreatedDiskEncryptionSet.Builder().withDiskEncryptionSetId("dummyId").build();
Environment env = new Environment();
env.setParameters(new AzureParameters());
when(environmentService.getValidatorService()).thenReturn(validatorService);
when(environmentService.findByResourceCrnAndAccountIdAndArchivedIsFalse(eq(ENVIRONMENT_NAME), eq(ACCOUNT_ID))).thenReturn(Optional.of(env));
when(validatorService.validateEncryptionKeyUrl(any(String.class), any(String.class))).thenReturn(ValidationResult.builder().build());
when(environmentDtoConverter.environmentToDto(env)).thenReturn(new EnvironmentDto());
when(environmentEncryptionService.createEncryptionResources(any(EnvironmentDto.class))).thenReturn(createdDiskEncryptionSet);
environmentModificationServiceUnderTest.updateAzureResourceEncryptionParametersByEnvironmentCrn(ACCOUNT_ID, ENVIRONMENT_NAME, updateAzureResourceEncryptionDto);
ArgumentCaptor<AzureParameters> azureParametersArgumentCaptor = ArgumentCaptor.forClass(AzureParameters.class);
verify(azureParametersRepository).save(azureParametersArgumentCaptor.capture());
assertEquals("dummyKeyUrl", azureParametersArgumentCaptor.getValue().getEncryptionKeyUrl());
assertEquals("dummyResourceGroupName", azureParametersArgumentCaptor.getValue().getEncryptionKeyResourceGroupName());
}
use of com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet in project cloudbreak by hortonworks.
the class ResourceEncryptionInitializationHandlerTest method acceptTestEnvironmentShouldBeUpdatedWhenEncryptionKeyUrlIsPresentAndStatusNotYetInitialized.
@Test
void acceptTestEnvironmentShouldBeUpdatedWhenEncryptionKeyUrlIsPresentAndStatusNotYetInitialized() {
doAnswer(i -> null).when(eventSender).sendEvent(baseNamedFlowEventCaptor.capture(), any(Headers.class));
Environment environment = new Environment();
environment.setParameters(newAzureParameters());
when(environmentService.findEnvironmentById(ENVIRONMENT_ID)).thenReturn(Optional.of(environment));
CreatedDiskEncryptionSet createdDiskEncryptionSet = new CreatedDiskEncryptionSet.Builder().withDiskEncryptionSetId(DISK_ENCRYPTION_SET_ID).build();
when(environmentEncryptionService.createEncryptionResources(any(EnvironmentDto.class))).thenReturn(createdDiskEncryptionSet);
underTest.accept(environmentDtoEvent);
verify(eventSender).sendEvent(baseNamedFlowEventCaptor.capture(), headersArgumentCaptor.capture());
verify(environmentService).save(environment);
AzureParameters azureParameters = (AzureParameters) environment.getParameters();
assertEquals(azureParameters.getDiskEncryptionSetId(), DISK_ENCRYPTION_SET_ID);
assertEquals(environment.getStatus(), EnvironmentStatus.ENVIRONMENT_ENCRYPTION_RESOURCES_INITIALIZED);
verifyEnvCreationEvent();
}
use of com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet in project cloudbreak by hortonworks.
the class EnvironmentEncryptionServiceTest method testCreateEncryptionResourcesShouldCallCreateDiskEncryptionSetWhenCloudPlatformAzure.
@Test
void testCreateEncryptionResourcesShouldCallCreateDiskEncryptionSetWhenCloudPlatformAzure() {
when(cloudPlatformConnectors.get(any(CloudPlatformVariant.class))).thenReturn(cloudConnector);
when(cloudConnector.encryptionResources()).thenReturn(encryptionResources);
EnvironmentDto environmentDto = EnvironmentDto.builder().withResourceCrn(ENVIRONMENT_CRN).withId(ENVIRONMENT_ID).withName(ENVIRONMENT_NAME).withCloudPlatform(CLOUD_PLATFORM).withCredential(credential).withLocationDto(LocationDto.builder().withName(REGION).build()).withParameters(ParametersDto.builder().withAzureParameters(AzureParametersDto.builder().withEncryptionParameters(AzureResourceEncryptionParametersDto.builder().withEncryptionKeyUrl(KEY_URL).build()).withResourceGroup(AzureResourceGroupDto.builder().withResourceGroupUsagePattern(ResourceGroupUsagePattern.USE_SINGLE).withName(RESOURCE_GROUP_NAME).build()).build()).build()).build();
CreatedDiskEncryptionSet dummyDes = new CreatedDiskEncryptionSet.Builder().withDiskEncryptionSetId(DISK_ENCRYPTION_SET_ID).build();
when(encryptionResources.createDiskEncryptionSet(any(DiskEncryptionSetCreationRequest.class))).thenReturn(dummyDes);
CreatedDiskEncryptionSet createdDes = underTest.createEncryptionResources(environmentDto);
assertEquals(createdDes.getDiskEncryptionSetId(), DISK_ENCRYPTION_SET_ID);
}
use of com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet in project cloudbreak by hortonworks.
the class EnvironmentModificationService method updateAzureResourceEncryptionParameters.
private EnvironmentDto updateAzureResourceEncryptionParameters(String accountId, String environmentName, AzureResourceEncryptionParametersDto dto, Environment environment) {
AzureParameters azureParameters = (AzureParameters) environment.getParameters();
if (azureParameters.getEncryptionKeyUrl() == null) {
ValidationResult validateKey = environmentService.getValidatorService().validateEncryptionKeyUrl(dto.getEncryptionKeyUrl(), accountId);
if (!validateKey.hasError()) {
azureParameters.setEncryptionKeyUrl(dto.getEncryptionKeyUrl());
azureParameters.setEncryptionKeyResourceGroupName(dto.getEncryptionKeyResourceGroupName());
// creating the DES
try {
CreatedDiskEncryptionSet createdDiskEncryptionSet = environmentEncryptionService.createEncryptionResources(environmentDtoConverter.environmentToDto(environment));
azureParameters.setDiskEncryptionSetId(createdDiskEncryptionSet.getDiskEncryptionSetId());
azureParametersRepository.save(azureParameters);
} catch (Exception e) {
throw new BadRequestException(e);
}
LOGGER.debug("Successfully created the Disk encryption set for the environment {}.", environmentName);
} else {
throw new BadRequestException(validateKey.getFormattedErrors());
}
} else if (azureParameters.getEncryptionKeyUrl().equals(dto.getEncryptionKeyUrl())) {
LOGGER.info("Encryption Key '%s' is already set for the environment '%s'. ", azureParameters.getEncryptionKeyUrl(), environmentName);
} else {
throw new BadRequestException(String.format("Encryption Key '%s' is already set for the environment '%s'. " + "Modifying the encryption key is not allowed.", azureParameters.getEncryptionKeyUrl(), environmentName));
}
return environmentDtoConverter.environmentToDto(environment);
}
use of com.sequenceiq.cloudbreak.cloud.model.encryption.CreatedDiskEncryptionSet in project cloudbreak by hortonworks.
the class ResourceEncryptionInitializationHandler method initializeEncryptionResources.
private void initializeEncryptionResources(EnvironmentDto environmentDto, Environment environment) {
String environmentName = environment.getName();
LOGGER.info("Initializing encryption resources for environment \"{}\".", environmentName);
try {
CreatedDiskEncryptionSet createdDiskEncryptionSet = environmentEncryptionService.createEncryptionResources(environmentDto);
LOGGER.info("Created Disk Encryption Set resource for environment \"{}\": {}", environmentName, createdDiskEncryptionSet);
AzureParameters azureParameters = (AzureParameters) environment.getParameters();
azureParameters.setDiskEncryptionSetId(createdDiskEncryptionSet.getDiskEncryptionSetId());
environment.setStatus(EnvironmentStatus.ENVIRONMENT_ENCRYPTION_RESOURCES_INITIALIZED);
environment.setStatusReason(null);
environmentService.save(environment);
LOGGER.info("Finished initializing encryption resources for environment \"{}\".", environmentName);
} catch (Exception e) {
LOGGER.error(String.format("Failed to initialize encryption resources for environment \"%s\"", environmentName), e);
throw new CloudbreakServiceException("Error occurred while initializing encryption resources: " + e.getMessage(), e);
}
}
Aggregations