use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.
the class SettingsProxyValidatorTest method validateNonProxyHostsTest.
@Test
void validateNonProxyHostsTest() {
SettingsProxyModel settingsProxyModel = new SettingsProxyModel();
settingsProxyModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
settingsProxyModel.setProxyPort(PORT);
settingsProxyModel.setNonProxyHosts(List.of("nonProxyHost"));
ValidationResponseModel validationResponseModel = settingsProxyValidator.validate(settingsProxyModel);
assertTrue(validationResponseModel.hasErrors());
assertEquals(1, validationResponseModel.getErrors().size());
assertTrue(validationResponseModel.getErrors().containsKey(SettingsProxyValidator.PROXY_HOST_FIELD_NAME));
}
use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.
the class StartupLogTest method testLogConfiguration.
@Test
void testLogConfiguration() throws Exception {
SettingsProxyModel settingsProxyModel = new SettingsProxyModel();
settingsProxyModel.setProxyHost("google.com");
settingsProxyModel.setProxyPort(3218);
settingsProxyModel.setProxyUsername("AUser");
settingsProxyModel.setIsProxyPasswordSet(true);
settingsProxyModel.setProxyPassword("aPassword");
SettingsUtility mockSettingsUtility = Mockito.mock(SettingsUtility.class);
Mockito.when(mockSettingsUtility.getConfiguration()).thenReturn(Optional.of(settingsProxyModel));
ProxyManager proxyManager = new ProxyManager(mockSettingsUtility);
MockAlertProperties testAlertProperties = new MockAlertProperties();
ConfigurationLogger configurationLogger = new ConfigurationLogger(proxyManager, testAlertProperties);
configurationLogger.initializeComponent();
assertTrue(outputLogger.isLineContainingText("Alert Proxy Authenticated: true"));
}
use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.
the class ProxyConfigurationModelConverter method convert.
@Override
public Optional<SettingsProxyModel> convert(ConfigurationModel globalConfigurationModel) {
Optional<SettingsProxyModel> convertedModel = Optional.empty();
SettingsProxyModel model = new SettingsProxyModel();
try {
globalConfigurationModel.getField(FIELD_KEY_HOST).flatMap(ConfigurationFieldModel::getFieldValue).ifPresent(model::setProxyHost);
globalConfigurationModel.getField(FIELD_KEY_PORT).flatMap(ConfigurationFieldModel::getFieldValue).map(Integer::valueOf).ifPresent(model::setProxyPort);
globalConfigurationModel.getField(FIELD_KEY_NON_PROXY_HOSTS).map(ConfigurationFieldModel::getFieldValues).map(ArrayList::new).ifPresent(model::setNonProxyHosts);
globalConfigurationModel.getField(FIELD_KEY_USERNAME).flatMap(ConfigurationFieldModel::getFieldValue).ifPresent(model::setProxyUsername);
globalConfigurationModel.getField(FIELD_KEY_PASSWORD).flatMap(ConfigurationFieldModel::getFieldValue).ifPresent(model::setProxyPassword);
convertedModel = Optional.of(model);
} catch (NumberFormatException ex) {
logger.error("Error converting field model to concrete proxy configuration", ex);
}
return convertedModel;
}
use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.
the class ProxySettingsEnvironmentHandlerFactory method updateFunction.
private EnvironmentProcessingResult updateFunction() {
EnvironmentProcessingResult.Builder builder = new EnvironmentProcessingResult.Builder(PROXY_CONFIGURATION_KEYSET);
SettingsProxyModel configModel = new SettingsProxyModel();
configModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
configureProxySettings(configModel);
// TODO: Refactor and remove duplicate code after 6.10.0 model package refactor
ValidationResponseModel validationResponseModel = validator.validate(configModel);
if (validationResponseModel.hasErrors()) {
logger.error("Error inserting startup values: {}", validationResponseModel.getMessage());
Map<String, AlertFieldStatus> errors = validationResponseModel.getErrors();
for (Map.Entry<String, AlertFieldStatus> error : errors.entrySet()) {
AlertFieldStatus status = error.getValue();
logger.error("Field: '{}' failed with the error: {}", status.getFieldName(), status.getFieldMessage());
}
return EnvironmentProcessingResult.empty();
}
SettingsProxyModel obfuscatedModel = configModel.obfuscate();
obfuscatedModel.getProxyHost().ifPresent(value -> builder.addVariableValue(PROXY_HOST_KEY, value));
obfuscatedModel.getProxyPort().map(String::valueOf).ifPresent(value -> builder.addVariableValue(PROXY_PORT_KEY, value));
obfuscatedModel.getProxyUsername().ifPresent(value -> builder.addVariableValue(PROXY_USERNAME_KEY, value));
obfuscatedModel.getNonProxyHosts().map(String::valueOf).ifPresent(value -> builder.addVariableValue(PROXY_NON_PROXY_HOSTS_KEY, value));
if (Boolean.TRUE.equals(obfuscatedModel.getIsProxyPasswordSet())) {
builder.addVariableValue(PROXY_PASSWORD_KEY, AlertConstants.MASKED_VALUE);
}
EnvironmentProcessingResult result = builder.build();
if (result.hasValues()) {
try {
configAccessor.createConfiguration(configModel);
} catch (AlertConfigurationException ex) {
logger.error("Error creating the configuration: {}", ex.getMessage());
}
}
return result;
}
Aggregations