use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class JobConfigActions method testProviderConfig.
private MessageResult testProviderConfig(FieldUtility fieldUtility, String jobId, FieldModel fieldModel) throws IntegrationException {
Optional<FieldModelTestAction> providerTestAction = fieldUtility.getString(ChannelDescriptor.KEY_PROVIDER_TYPE).flatMap(providerName -> descriptorProcessor.retrieveTestAction(providerName, ConfigContextEnum.DISTRIBUTION));
if (providerTestAction.isPresent()) {
MessageResult providerConfigTestResult = providerTestAction.get().testConfig(jobId, fieldModel, fieldUtility);
if (!providerConfigTestResult.hasErrors()) {
return providerConfigTestResult;
} else {
List<AlertFieldStatus> deescalatedErrors = providerConfigTestResult.fieldErrors().stream().map(fieldStatus -> AlertFieldStatus.warning(fieldStatus.getFieldName(), fieldStatus.getFieldMessage())).collect(Collectors.toList());
List<AlertFieldStatus> allWarnings = ListUtils.union(providerConfigTestResult.fieldWarnings(), deescalatedErrors);
return new MessageResult("Provider Config Invalid", allWarnings);
}
}
return new MessageResult("Provider Config Valid");
}
use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class ConfigActionTestIT method deleteSensitiveFieldFromConfig.
@Test
void deleteSensitiveFieldFromConfig() {
GlobalConfigurationModelToConcreteConversionService conversionService = new GlobalConfigurationModelToConcreteConversionService(List.of(), descriptorMap);
AuthorizationManager authorizationManager = Mockito.mock(AuthorizationManager.class);
Mockito.when(authorizationManager.hasDeletePermission(Mockito.anyString(), Mockito.anyString())).thenReturn(Boolean.TRUE);
Mockito.when(authorizationManager.hasWritePermission(Mockito.anyString(), Mockito.anyString())).thenReturn(Boolean.TRUE);
ConfigActions configActions = new ConfigActions(authorizationManager, descriptorAccessor, configurationModelConfigurationAccessor, fieldModelProcessor, descriptorProcessor, configurationFieldModelConverter, descriptorMap, pkixErrorResponseFactory, encryptionUtility, settingsDescriptorKey, conversionService);
ConfigurationFieldModel proxyHost = ConfigurationFieldModel.create(ProxyManager.KEY_PROXY_HOST);
proxyHost.setFieldValue("proxyHost");
ConfigurationFieldModel proxyPort = ConfigurationFieldModel.create(ProxyManager.KEY_PROXY_PORT);
proxyPort.setFieldValue("80");
ConfigurationFieldModel proxyUsername = ConfigurationFieldModel.create(ProxyManager.KEY_PROXY_USERNAME);
proxyUsername.setFieldValue("username");
ConfigurationFieldModel proxyPassword = ConfigurationFieldModel.createSensitive(ProxyManager.KEY_PROXY_PWD);
proxyPassword.setFieldValue("somestuff");
ConfigurationFieldModel encryptionPassword = ConfigurationFieldModel.createSensitive(SettingsDescriptor.KEY_ENCRYPTION_PWD);
encryptionPassword.setFieldValue("pants");
ConfigurationFieldModel encryptionSalt = ConfigurationFieldModel.createSensitive(SettingsDescriptor.KEY_ENCRYPTION_GLOBAL_SALT);
encryptionSalt.setFieldValue("salty pants");
ConfigurationModel configurationModel = configurationModelConfigurationAccessor.createConfiguration(settingsDescriptorKey, ConfigContextEnum.GLOBAL, Set.of(proxyHost, proxyPort, proxyUsername, proxyPassword, encryptionPassword, encryptionSalt));
FieldValueModel proxyHostFieldValue = new FieldValueModel(Set.of("proxyHost"), true);
FieldValueModel proxyPortFieldValue = new FieldValueModel(Set.of("80"), true);
FieldValueModel proxyUsernameFieldValue = new FieldValueModel(Set.of(), false);
FieldValueModel proxyPasswordFieldValue = new FieldValueModel(Set.of(), false);
FieldValueModel encryptionPasswordFieldValue = new FieldValueModel(Set.of("encryptionPassword"), true);
FieldValueModel encryptionSaltFieldValue = new FieldValueModel(Set.of("sodiumChloride"), true);
Long longConfigId = configurationModel.getConfigurationId();
String configId = String.valueOf(longConfigId);
FieldModel fieldModel = new FieldModel(configId, settingsDescriptorKey.getUniversalKey(), ConfigContextEnum.GLOBAL.name(), new HashMap<>(Map.of(ProxyManager.KEY_PROXY_HOST, proxyHostFieldValue, ProxyManager.KEY_PROXY_PORT, proxyPortFieldValue, ProxyManager.KEY_PROXY_USERNAME, proxyUsernameFieldValue, ProxyManager.KEY_PROXY_PWD, proxyPasswordFieldValue, SettingsDescriptor.KEY_ENCRYPTION_PWD, encryptionPasswordFieldValue, SettingsDescriptor.KEY_ENCRYPTION_GLOBAL_SALT, encryptionSaltFieldValue)));
ActionResponse<FieldModel> response = configActions.update(longConfigId, fieldModel);
assertTrue(response.hasContent());
FieldModel updatedConfig = response.getContent().orElseThrow(() -> new AssertionFailedError("content missing from response."));
assertTrue(updatedConfig.getFieldValue(ProxyManager.KEY_PROXY_USERNAME).isEmpty(), "Need to remove username in order to remove password as well.");
assertTrue(updatedConfig.getFieldValue(ProxyManager.KEY_PROXY_PWD).isEmpty(), "Saving an empty values should remove it from DB.");
}
use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class ConfigActions method updateWithoutChecks.
@Override
protected ActionResponse<FieldModel> updateWithoutChecks(Long id, FieldModel resource) {
Optional<ConfigurationModel> optionalPreviousConfig = configurationModelConfigurationAccessor.getConfigurationById(id);
FieldModel previousFieldModel = optionalPreviousConfig.isPresent() ? modelConverter.convertToFieldModel(optionalPreviousConfig.get()) : null;
try {
FieldModel updatedFieldModel = fieldModelProcessor.performBeforeUpdateAction(resource);
Collection<ConfigurationFieldModel> updatedFields = fieldModelProcessor.fillFieldModelWithExistingData(id, updatedFieldModel);
ConfigurationModel configurationModel = configurationModelConfigurationAccessor.updateConfiguration(id, updatedFields);
globalConfigurationModelToConcreteConversionService.updateDefaultConcreteModel(updatedFieldModel.getDescriptorName(), configurationModel);
FieldModel dbSavedModel = modelConverter.convertToFieldModel(configurationModel);
FieldModel afterUpdateAction = fieldModelProcessor.performAfterUpdateAction(previousFieldModel, dbSavedModel);
FieldModel responseModel = dbSavedModel.fill(afterUpdateAction);
return new ActionResponse<>(HttpStatus.OK, responseModel);
} catch (AlertException ex) {
logger.error("Error creating configuration", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, String.format("Error creating config: %s", ex.getMessage()));
}
}
use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class ConfigActions method findFieldModel.
@Override
protected Optional<FieldModel> findFieldModel(Long id) {
Optional<FieldModel> optionalModel = Optional.empty();
Optional<ConfigurationModel> configurationModel = configurationModelConfigurationAccessor.getConfigurationById(id);
if (configurationModel.isPresent()) {
try {
FieldModel configurationFieldModel = modelConverter.convertToFieldModel(configurationModel.get());
FieldModel fieldModel = fieldModelProcessor.performAfterReadAction(configurationFieldModel);
optionalModel = Optional.of(fieldModel);
} catch (AlertException ex) {
logger.error(String.format("Error finding configuration for id: %d", id), ex);
}
}
return optionalModel;
}
use of com.synopsys.integration.alert.common.rest.model.FieldModel in project hub-alert by blackducksoftware.
the class ConfigActions method validateWithoutChecks.
@Override
protected ValidationActionResponse validateWithoutChecks(FieldModel resource) {
if (!encryptionUtility.isInitialized() && !settingsDescriptorKey.getUniversalKey().equals(resource.getDescriptorName())) {
ValidationResponseModel validationResponseModel = ValidationResponseModel.generalError(ConfigurationFieldValidator.ENCRYPTION_MISSING);
return new ValidationActionResponse(HttpStatus.INTERNAL_SERVER_ERROR, validationResponseModel);
}
Set<AlertFieldStatus> fieldStatuses = descriptorProcessor.retrieveDescriptor(resource.getDescriptorName()).flatMap(Descriptor::getGlobalValidator).map(globalValidator -> globalValidator.validate(resource)).orElse(Set.of());
ValidationResponseModel responseModel;
HttpStatus status = HttpStatus.OK;
if (fieldStatuses.isEmpty()) {
responseModel = ValidationResponseModel.success("The configuration is valid");
} else {
status = HttpStatus.BAD_REQUEST;
responseModel = ValidationResponseModel.fromStatusCollection("There were problems with the configuration", fieldStatuses);
}
return new ValidationActionResponse(status, responseModel);
}
Aggregations