use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class ProviderDataAccessorTest method init.
@BeforeEach
void init() throws Exception {
blackDuckPropertiesFactory = Mockito.mock(BlackDuckPropertiesFactory.class);
BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
Mockito.when(blackDuckPropertiesFactory.createProperties(Mockito.any(ConfigurationModel.class))).thenReturn(blackDuckProperties);
BlackDuckHttpClient blackDuckHttpClient = Mockito.mock(BlackDuckHttpClient.class);
Mockito.when(blackDuckProperties.createBlackDuckHttpClient(Mockito.any(IntLogger.class))).thenReturn(blackDuckHttpClient);
blackDuckServicesFactory = Mockito.mock(BlackDuckServicesFactory.class);
Mockito.when(blackDuckProperties.createBlackDuckServicesFactory(Mockito.any(BlackDuckHttpClient.class), Mockito.any(IntLogger.class))).thenReturn(blackDuckServicesFactory);
projectService = Mockito.mock(ProjectService.class);
Mockito.when(blackDuckServicesFactory.createProjectService()).thenReturn(projectService);
blackDuckApiClient = Mockito.mock(BlackDuckApiClient.class);
Mockito.when(blackDuckServicesFactory.getBlackDuckApiClient()).thenReturn(blackDuckApiClient);
projectUsersService = Mockito.mock(ProjectUsersService.class);
Mockito.when(blackDuckServicesFactory.createProjectUsersService()).thenReturn(projectUsersService);
apiDiscovery = Mockito.mock(ApiDiscovery.class);
UrlMultipleResponses<UserView> usersLink = Mockito.mock(UrlMultipleResponses.class);
Mockito.when(apiDiscovery.metaUsersLink()).thenReturn(usersLink);
Mockito.when(blackDuckServicesFactory.getApiDiscovery()).thenReturn(apiDiscovery);
ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
configurationFieldModel.setFieldValue(PROVIDER_CONFIG_NAME);
configurationModelConfigurationAccessor = Mockito.mock(ConfigurationModelConfigurationAccessor.class);
providerConfiguration = new ConfigurationModel(1L, 1L, "createdAt", "lastModified", ConfigContextEnum.GLOBAL, Map.of(PROVIDER_CONFIG_NAME, configurationFieldModel));
Mockito.when(configurationModelConfigurationAccessor.getConfigurationById(1L)).thenReturn(Optional.of(providerConfiguration));
Mockito.when(configurationModelConfigurationAccessor.getProviderConfigurationByName(Mockito.anyString())).thenReturn(Optional.of(providerConfiguration));
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class BlackDuckProviderDataAccessor method getProjectVersionNamesByHref.
@Override
public AlertPagedModel<String> getProjectVersionNamesByHref(Long providerConfigId, String projectHref, int pageNumber) {
Optional<ConfigurationModel> providerConfigOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
if (providerConfigOptional.isPresent()) {
try {
BlackDuckServicesFactory blackDuckServicesFactory = createBlackDuckServicesFactory(providerConfigOptional.get());
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
ProjectView foundProject = blackDuckApiClient.getResponse(new HttpUrl(projectHref), ProjectView.class);
BlackDuckPageDefinition blackDuckPageDefinition = new BlackDuckPageDefinition(BlackDuckRequestBuilder.DEFAULT_LIMIT, pageNumber * BlackDuckRequestBuilder.DEFAULT_LIMIT);
BlackDuckMultipleRequest<ProjectVersionView> projectVersionSpec = new BlackDuckRequestBuilder().commonGet().setBlackDuckPageDefinition(blackDuckPageDefinition).buildBlackDuckRequest(foundProject.metaVersionsLink());
BlackDuckPageResponse<ProjectVersionView> pageResponse = blackDuckApiClient.getPageResponse(projectVersionSpec);
return new AlertPagedModel<>(pageResponse.getTotalCount(), pageNumber, BlackDuckRequestBuilder.DEFAULT_LIMIT, pageResponse.getItems()).transformContent(ProjectVersionView::getVersionName);
} catch (IntegrationException e) {
logger.errorAndDebug(createProjectNotFoundString(providerConfigId, e.getMessage()), e);
}
}
return AlertPagedModel.empty(pageNumber, BlackDuckRequestBuilder.DEFAULT_LIMIT);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class BlackDuckDistributionFieldModelTestAction method testConfig.
@Override
public MessageResult testConfig(String configId, FieldModel fieldModel, FieldUtility registeredFieldValues) throws IntegrationException {
ArrayList<AlertFieldStatus> fieldStatuses = new ArrayList<>();
Optional<Long> optionalProviderConfigId = registeredFieldValues.getLong(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID);
if (optionalProviderConfigId.isPresent()) {
Long providerConfigId = optionalProviderConfigId.get();
boolean filterByProjects = registeredFieldValues.getBoolean(ProviderDescriptor.KEY_FILTER_BY_PROJECT).orElse(false);
if (filterByProjects) {
Collection<String> configuredProjects = registeredFieldValues.getAllStrings(ProviderDescriptor.KEY_CONFIGURED_PROJECT);
validateSelectedProjectExists(providerConfigId, configuredProjects).ifPresent(fieldStatuses::add);
Optional<String> optionalProjectNamePattern = registeredFieldValues.getString(ProviderDescriptor.KEY_PROJECT_NAME_PATTERN);
optionalProjectNamePattern.flatMap(projectNamePattern -> validatePatternMatchesProject(providerConfigId, projectNamePattern)).ifPresent(fieldStatuses::add);
registeredFieldValues.getString(ProviderDescriptor.KEY_PROJECT_VERSION_NAME_PATTERN).flatMap(projectVersionNamePattern -> validatePatternMatchesProjectVersion(providerConfigId, projectVersionNamePattern, optionalProjectNamePattern.orElse(null), configuredProjects)).ifPresent(fieldStatuses::add);
}
BlackDuckProperties blackDuckProperties = null;
Optional<ConfigurationModel> providerConfigurationOptional = configurationModelConfigurationAccessor.getConfigurationById(providerConfigId);
if (providerConfigurationOptional.isPresent()) {
ConfigurationModel providerConfiguration = providerConfigurationOptional.get();
StatefulProvider statefulProvider = blackDuckProvider.createStatefulProvider(providerConfiguration);
blackDuckProperties = (BlackDuckProperties) statefulProvider.getProperties();
}
if (null != blackDuckProperties) {
BlackDuckApiTokenValidator blackDuckAPITokenValidator = new BlackDuckApiTokenValidator(blackDuckProperties);
if (!blackDuckAPITokenValidator.isApiTokenValid()) {
fieldStatuses.add(AlertFieldStatus.error(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, "User permission failed, cannot read notifications from Black Duck."));
}
}
} else {
fieldStatuses.add(AlertFieldStatus.error(ProviderDescriptor.KEY_PROVIDER_CONFIG_ID, "A provider configuration is required"));
}
if (MessageResult.hasFieldStatusBySeverity(fieldStatuses, FieldStatusSeverity.ERROR)) {
return new MessageResult("There were errors with the BlackDuck provider fields", fieldStatuses);
}
return new MessageResult("Successfully tested BlackDuck provider fields", fieldStatuses);
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class BlackDuckGlobalApiAction method handleNewOrUpdatedConfig.
private void handleNewOrUpdatedConfig(FieldModel currentFieldModel) throws AlertException {
Optional<String> providerConfigName = currentFieldModel.getFieldValue(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME);
if (providerConfigName.isPresent()) {
Optional<ConfigurationModel> retrievedConfig = configurationModelConfigurationAccessor.getProviderConfigurationByName(providerConfigName.get());
if (retrievedConfig.isPresent()) {
ConfigurationModel blackDuckGlobalConfig = retrievedConfig.get();
boolean valid = blackDuckProvider.validate(blackDuckGlobalConfig);
boolean enabled = blackDuckGlobalConfig.getField(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED).flatMap(ConfigurationFieldModel::getFieldValue).map(Boolean::parseBoolean).orElse(false);
if (valid && enabled) {
providerLifecycleManager.scheduleTasksForProviderConfig(blackDuckProvider, retrievedConfig.get());
}
}
}
}
use of com.synopsys.integration.alert.common.persistence.model.ConfigurationModel in project hub-alert by blackducksoftware.
the class LdapManagerTest method testAuthenticationTypeDigest.
@Test
public void testAuthenticationTypeDigest() throws Exception {
final String authenticationType = "digest";
ConfigurationModel configurationModel = createConfigurationModel();
configurationModel.getField(AuthenticationDescriptor.KEY_LDAP_AUTHENTICATION_TYPE).get().setFieldValue(authenticationType);
DefaultConfigurationModelConfigurationAccessor configurationModelConfigurationAccessor = Mockito.mock(DefaultConfigurationModelConfigurationAccessor.class);
Mockito.when(configurationModelConfigurationAccessor.getConfigurationsByDescriptorKey(Mockito.any(DescriptorKey.class))).thenReturn(List.of(configurationModel));
UserManagementAuthoritiesPopulator authoritiesPopulator = Mockito.mock(UserManagementAuthoritiesPopulator.class);
LdapManager ldapManager = new LdapManager(AUTHENTICATION_DESCRIPTOR_KEY, configurationModelConfigurationAccessor, authoritiesPopulator, LDAP_USER_CONTEXT_MAPPER);
ldapManager.getAuthenticationProvider();
FieldUtility updatedProperties = ldapManager.getCurrentConfiguration();
assertEquals(authenticationType, updatedProperties.getField(AuthenticationDescriptor.KEY_LDAP_AUTHENTICATION_TYPE).flatMap(ConfigurationFieldModel::getFieldValue).orElse(null));
}
Aggregations