use of com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel in project hub-alert by blackducksoftware.
the class JiraServerEnvironmentVariableHandlerFactory method updateConfiguration.
private EnvironmentProcessingResult updateConfiguration() {
EnvironmentProcessingResult.Builder builder = new EnvironmentProcessingResult.Builder(VARIABLE_NAMES);
String url = environmentVariableUtility.getEnvironmentValue(URL_KEY).orElse(null);
if (StringUtils.isBlank(url)) {
return EnvironmentProcessingResult.empty();
}
String name = AlertRestConstants.DEFAULT_CONFIGURATION_NAME;
String userName = environmentVariableUtility.getEnvironmentValue(USERNAME_KEY).orElse(null);
String password = environmentVariableUtility.getEnvironmentValue(PASSWORD_KEY).orElse(null);
String createdAt = DateUtils.formatDate(DateUtils.createCurrentDateTimestamp(), DateUtils.UTC_DATE_FORMAT_TO_MINUTE);
JiraServerGlobalConfigModel configModel = new JiraServerGlobalConfigModel(null, name, url, userName, password);
configModel.setCreatedAt(createdAt);
configModel.setLastUpdated(createdAt);
environmentVariableUtility.getEnvironmentValue(DISABLE_PLUGIN_KEY).map(Boolean::valueOf).ifPresent(configModel::setDisablePluginCheck);
JiraServerGlobalConfigModel obfuscatedModel = configModel.obfuscate();
if (StringUtils.isNotBlank(obfuscatedModel.getUrl())) {
builder.addVariableValue(URL_KEY, obfuscatedModel.getUrl());
}
if (StringUtils.isNotBlank(obfuscatedModel.getUserName())) {
builder.addVariableValue(USERNAME_KEY, obfuscatedModel.getUserName());
}
obfuscatedModel.getDisablePluginCheck().map(String::valueOf).ifPresent(value -> builder.addVariableValue(DISABLE_PLUGIN_KEY, value));
obfuscatedModel.getIsPasswordSet().filter(Boolean::booleanValue).ifPresent(ignored -> builder.addVariableValue(PASSWORD_KEY, AlertConstants.MASKED_VALUE));
EnvironmentProcessingResult result = builder.build();
if (result.hasValues() && configAccessor.getConfigurationByName(name).isEmpty()) {
try {
configAccessor.createConfiguration(configModel);
} catch (AlertConfigurationException ex) {
logger.error("Failed to create config: ", ex);
}
}
return result;
}
use of com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigurationModelConverter method convert.
@Override
public Optional<JiraServerGlobalConfigModel> convert(ConfigurationModel globalConfigurationModel) {
String url = globalConfigurationModel.getField(URL_KEY).flatMap(ConfigurationFieldModel::getFieldValue).orElse(null);
if (StringUtils.isBlank(url)) {
return Optional.empty();
}
String username = globalConfigurationModel.getField(USERNAME_KEY).flatMap(ConfigurationFieldModel::getFieldValue).orElse(null);
String password = globalConfigurationModel.getField(PASSWORD_KEY).flatMap(ConfigurationFieldModel::getFieldValue).orElse(null);
JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(null, AlertRestConstants.DEFAULT_CONFIGURATION_NAME, url, username, password);
globalConfigurationModel.getField(DISABLE_PLUGIN_CHECK_KEY).flatMap(ConfigurationFieldModel::getFieldValue).map(Boolean::valueOf).ifPresent(model::setDisablePluginCheck);
return Optional.of(model);
}
use of com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel in project hub-alert by blackducksoftware.
the class JiraServerGlobalConfigurationValidatorTest method verifyPasswordIsMissingAndNotSaved.
@Test
void verifyPasswordIsMissingAndNotSaved() {
JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator();
JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, URL, USER_NAME, null);
ValidationResponseModel validationResponseModel = validator.validate(model);
Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
assertEquals(1, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
for (AlertFieldStatus status : alertFieldStatuses) {
assertEquals("password", status.getFieldName(), "Validation reported an error for an unexpected field.");
}
}
use of com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel in project hub-alert by blackducksoftware.
the class JiraServerGlobalCrudActionsTestIT method updateBadRequestTest.
@Test
void updateBadRequestTest() {
JiraServerGlobalCrudActions crudActions = new JiraServerGlobalCrudActions(authorizationManager, configAccessor, validator);
JiraServerGlobalConfigModel jiraServerGlobalConfigModel = createBasicJiraModel();
ActionResponse<JiraServerGlobalConfigModel> createActionResponse = crudActions.create(jiraServerGlobalConfigModel);
assertTrue(createActionResponse.isSuccessful());
assertTrue(createActionResponse.getContent().isPresent());
UUID uuid = UUID.fromString(createActionResponse.getContent().get().getId());
JiraServerGlobalConfigModel updatedJiraServerGlobalConfigModel = new JiraServerGlobalConfigModel(null, AlertRestConstants.DEFAULT_CONFIGURATION_NAME, "https://aNewURL", "a-different-username", null);
ActionResponse<JiraServerGlobalConfigModel> actionResponse = crudActions.update(uuid, updatedJiraServerGlobalConfigModel);
assertTrue(actionResponse.isError());
assertFalse(actionResponse.hasContent());
assertEquals(HttpStatus.BAD_REQUEST, actionResponse.getHttpStatus());
}
use of com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel in project hub-alert by blackducksoftware.
the class JiraServerGlobalCrudActionsTestIT method updateTest.
@Test
void updateTest() {
JiraServerGlobalCrudActions crudActions = new JiraServerGlobalCrudActions(authorizationManager, configAccessor, validator);
JiraServerGlobalConfigModel jiraServerGlobalConfigModel = createBasicJiraModel();
ActionResponse<JiraServerGlobalConfigModel> createActionResponse = crudActions.create(jiraServerGlobalConfigModel);
assertTrue(createActionResponse.isSuccessful());
assertTrue(createActionResponse.getContent().isPresent());
UUID uuid = UUID.fromString(createActionResponse.getContent().get().getId());
JiraServerGlobalConfigModel updatedJiraServerGlobalConfigModel = new JiraServerGlobalConfigModel(null, AlertRestConstants.DEFAULT_CONFIGURATION_NAME, "https://aNewURL", "a-different-username", "newPassword");
ActionResponse<JiraServerGlobalConfigModel> actionResponse = crudActions.update(uuid, updatedJiraServerGlobalConfigModel);
assertTrue(createActionResponse.isSuccessful());
assertTrue(actionResponse.hasContent());
assertEquals(HttpStatus.OK, actionResponse.getHttpStatus());
assertTrue(actionResponse.getContent().isPresent());
assertEquals("https://aNewURL", actionResponse.getContent().get().getUrl(), "The updated model does not have the correct updated value.");
}
Aggregations