use of com.sequenceiq.environment.parameters.dao.domain.AzureParameters 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.environment.parameters.dao.domain.AzureParameters 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.environment.parameters.dao.domain.AzureParameters 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.environment.parameters.dao.domain.AzureParameters in project cloudbreak by hortonworks.
the class AzureEnvironmentParametersConverterTest method convertTest.
@Test
void convertTest() {
when(environmentViewConverter.convert(any(Environment.class))).thenReturn(ENVIRONMENT_VIEW);
ParametersDto parameters = ParametersDto.builder().withId(ID).withAzureParameters(AzureParametersDto.builder().withEncryptionParameters(AzureResourceEncryptionParametersDto.builder().withEncryptionKeyUrl(KEY_URL).withEncryptionKeyResourceGroupName(KEY_RESOURCE_GROUP_NAME).build()).build()).build();
Environment environment = new Environment();
environment.setName(ENV_NAME);
environment.setAccountId(ACCOUNT_ID);
BaseParameters result = underTest.convert(environment, parameters);
assertEquals(AzureParameters.class, result.getClass());
AzureParameters azureResult = (AzureParameters) result;
assertEquals(ENV_NAME, azureResult.getName());
assertEquals(ACCOUNT_ID, azureResult.getAccountId());
assertEquals(ENVIRONMENT_VIEW, azureResult.getEnvironment());
assertEquals(ID, azureResult.getId());
assertEquals(KEY_URL, azureResult.getEncryptionKeyUrl());
assertEquals(KEY_RESOURCE_GROUP_NAME, azureResult.getEncryptionKeyResourceGroupName());
}
use of com.sequenceiq.environment.parameters.dao.domain.AzureParameters in project cloudbreak by hortonworks.
the class AzureEnvironmentParametersConverterTest method convertToDtoTest.
@Test
void convertToDtoTest() {
EnvironmentView environmentView = ENVIRONMENT_VIEW;
AzureParameters parameters = new AzureParameters();
parameters.setAccountId(ACCOUNT_ID);
parameters.setEnvironment(environmentView);
parameters.setId(ID);
parameters.setName(ENV_NAME);
parameters.setEncryptionKeyUrl(KEY_URL);
parameters.setDiskEncryptionSetId("DummyDesId");
parameters.setEncryptionKeyResourceGroupName(KEY_RESOURCE_GROUP_NAME);
ParametersDto result = underTest.convertToDto(parameters);
assertEquals(ACCOUNT_ID, result.getAccountId());
assertEquals(ID, result.getId());
assertEquals(ENV_NAME, result.getName());
assertEquals(KEY_URL, result.getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyUrl());
assertEquals("DummyDesId", result.getAzureParametersDto().getAzureResourceEncryptionParametersDto().getDiskEncryptionSetId());
assertEquals(KEY_RESOURCE_GROUP_NAME, result.getAzureParametersDto().getAzureResourceEncryptionParametersDto().getEncryptionKeyResourceGroupName());
}
Aggregations