use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class JiraServerGlobalTestActionTest method createAuthorizationManager.
private AuthorizationManager createAuthorizationManager(int assignedPermissions) {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = ChannelKeys.JIRA_SERVER;
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, assignedPermissions);
return authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class AbstractJobResourceActions method checkContextAndDescriptorKey.
private boolean checkContextAndDescriptorKey(FieldModel fieldModel, BiFunction<ConfigContextEnum, DescriptorKey, Boolean> permissionChecker) {
ConfigContextEnum configContextEnum = ConfigContextEnum.valueOf(fieldModel.getContext());
DescriptorKey descriptorKey = descriptorMap.getDescriptorKey(fieldModel.getDescriptorName()).orElseThrow(() -> new AlertRuntimeException("Could not find DescriptorKey for: " + fieldModel.getDescriptorName()));
return permissionChecker.apply(configContextEnum, descriptorKey);
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class AlertStartupInitializer method initializeConfiguration.
private void initializeConfiguration(Collection<DescriptorKey> descriptorKeys) {
for (DescriptorKey descriptorKey : descriptorKeys) {
logger.info(LINE_DIVIDER);
logger.info("Descriptor: {}", descriptorKey.getUniversalKey());
logger.info(LINE_DIVIDER);
logger.info(" Starting Descriptor Initialization...");
try {
List<DefinedFieldModel> fieldsForDescriptor = descriptorAccessor.getFieldsForDescriptor(descriptorKey, ConfigContextEnum.GLOBAL).stream().sorted(Comparator.comparing(DefinedFieldModel::getKey)).collect(Collectors.toList());
List<ConfigurationModel> foundConfigurationModels = fieldConfigurationModelConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(descriptorKey, ConfigContextEnum.GLOBAL);
Map<String, ConfigurationFieldModel> existingConfiguredFields = new HashMap<>();
foundConfigurationModels.forEach(config -> existingConfiguredFields.putAll(config.getCopyOfKeyToFieldMap()));
Set<ConfigurationFieldModel> configurationModels = createFieldModelsFromDefinedFields(descriptorKey, fieldsForDescriptor, existingConfiguredFields);
logConfiguration(configurationModels);
updateConfigurationFields(descriptorKey, foundConfigurationModels, configurationModels);
} catch (IllegalArgumentException | SecurityException | AlertException ex) {
logger.error("error initializing descriptor", ex);
} finally {
logger.info(" Finished Descriptor Initialization...");
logger.info(LINE_DIVIDER);
}
}
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class AlertStartupInitializer method createFieldModelsFromDefinedFields.
private Set<ConfigurationFieldModel> createFieldModelsFromDefinedFields(DescriptorKey descriptorKey, List<DefinedFieldModel> fieldsForDescriptor, Map<String, ConfigurationFieldModel> existingConfiguredFields) {
Set<ConfigurationFieldModel> configurationModels = new HashSet<>();
logger.info(" ### Environment Variables ### ");
for (DefinedFieldModel fieldModel : fieldsForDescriptor) {
String key = fieldModel.getKey();
String convertedKey = environmentUtility.convertKeyToProperty(descriptorKey, key);
boolean hasEnvironmentValue = environmentUtility.hasEnvironmentValue(convertedKey);
logger.info(" {}", convertedKey);
logger.debug(" Environment Variable Found - {}", hasEnvironmentValue);
String defaultValue = null;
if (existingConfiguredFields.containsKey(key)) {
Optional<String> fieldValue = existingConfiguredFields.get(key).getFieldValue();
if (fieldValue.isPresent()) {
defaultValue = fieldValue.get();
}
}
environmentUtility.getEnvironmentValue(convertedKey, defaultValue).flatMap(value -> modelConverter.convertFromDefinedFieldModel(fieldModel, value, StringUtils.isNotBlank(value))).ifPresent(configurationModels::add);
}
return configurationModels;
}
use of com.synopsys.integration.alert.descriptor.api.model.DescriptorKey in project hub-alert by blackducksoftware.
the class EmailGlobalConfigurationActionTest method testUpdate.
@Test
public void testUpdate() throws AlertConfigurationException {
AuthenticationTestUtils authenticationTestUtils = new AuthenticationTestUtils();
DescriptorKey descriptorKey = ChannelKeys.EMAIL;
PermissionKey permissionKey = new PermissionKey(ConfigContextEnum.GLOBAL.name(), descriptorKey.getUniversalKey());
Map<PermissionKey, Integer> permissions = Map.of(permissionKey, AuthenticationTestUtils.FULL_PERMISSIONS);
AuthorizationManager authorizationManager = authenticationTestUtils.createAuthorizationManagerWithCurrentUserSet("admin", "admin", () -> new PermissionMatrixModel(permissions));
EmailGlobalConfigurationValidator validator = new EmailGlobalConfigurationValidator();
EmailGlobalConfigAccessor emailGlobalConfigAccessor = Mockito.mock(EmailGlobalConfigAccessor.class);
EmailGlobalConfigModel model = new EmailGlobalConfigModel();
model.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
model.setSmtpHost("host");
model.setSmtpFrom("from");
model.setSmtpAuth(true);
model.setSmtpUsername("user");
model.setSmtpPassword("password");
Mockito.when(emailGlobalConfigAccessor.getConfiguration()).thenReturn(Optional.of(model));
Mockito.when(emailGlobalConfigAccessor.updateConfiguration(Mockito.eq(model))).thenReturn(model);
Mockito.when(emailGlobalConfigAccessor.doesConfigurationExist()).thenReturn(true);
EmailGlobalCrudActions configActions = new EmailGlobalCrudActions(authorizationManager, emailGlobalConfigAccessor, validator);
ActionResponse<EmailGlobalConfigModel> response = configActions.update(model);
assertEquals(HttpStatus.OK, response.getHttpStatus());
assertTrue(response.hasContent());
assertEquals(model.obfuscate(), response.getContent().get());
}
Aggregations