use of com.sequenceiq.environment.environment.validation.EnvironmentValidatorService in project cloudbreak by hortonworks.
the class EnvironmentModificationService method editSecurityAccessIfChanged.
private void editSecurityAccessIfChanged(EnvironmentEditDto editDto, Environment environment) {
SecurityAccessDto securityAccessDto = editDto.getSecurityAccess();
if (securityAccessDto != null) {
EnvironmentValidatorService validatorService = environmentService.getValidatorService();
ValidationResult validationResult = validatorService.validateSecurityAccessModification(securityAccessDto, environment);
if (validationResult.hasError()) {
throw new BadRequestException(validationResult.getFormattedErrors());
}
validationResult = validatorService.validateSecurityGroups(editDto, environment);
if (validationResult.hasError()) {
throw new BadRequestException(validationResult.getFormattedErrors());
}
environmentService.editSecurityAccess(environment, securityAccessDto);
}
}
use of com.sequenceiq.environment.environment.validation.EnvironmentValidatorService in project cloudbreak by hortonworks.
the class EnvironmentModificationService method editAuthenticationIfChanged.
@VisibleForTesting
void editAuthenticationIfChanged(EnvironmentEditDto editDto, Environment environment) {
AuthenticationDto authenticationDto = editDto.getAuthentication();
if (authenticationDto != null) {
EnvironmentValidatorService validatorService = environmentService.getValidatorService();
ValidationResult validationResult = validatorService.validateAuthenticationModification(editDto, environment);
if (validationResult.hasError()) {
throw new BadRequestException(validationResult.getFormattedErrors());
}
EnvironmentAuthentication originalAuthentication = environment.getAuthentication();
if (environmentResourceService.isRawSshKeyUpdateSupported(environment)) {
EnvironmentAuthentication updated = authenticationDtoConverter.dtoToSshUpdatedAuthentication(authenticationDto);
updated.setLoginUserName(originalAuthentication.getLoginUserName());
updated.setId(originalAuthentication.getId());
environment.setAuthentication(updated);
} else if (environmentResourceService.isExistingSshKeyUpdateSupported(environment)) {
environment.setAuthentication(authenticationDtoConverter.dtoToAuthentication(authenticationDto));
boolean cleanupOldSshKey = true;
if (StringUtils.isNotEmpty(authenticationDto.getPublicKey())) {
cleanupOldSshKey = environmentResourceService.createAndUpdateSshKey(environment);
}
if (cleanupOldSshKey) {
String oldSshKeyId = originalAuthentication.getPublicKeyId();
LOGGER.info("The '{}' of ssh key is replaced with {}", oldSshKeyId, environment.getAuthentication().getPublicKeyId());
if (originalAuthentication.isManagedKey()) {
environmentResourceService.deletePublicKey(environment, oldSshKeyId);
}
} else {
LOGGER.info("Authentication modification was unsuccessful. The authentication was reverted to the previous version.");
environment.setAuthentication(originalAuthentication);
}
}
}
}
Aggregations