use of com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties in project hub-alert by blackducksoftware.
the class BlackDuckSSOConfigRetrieverTest method retrieveTestIT.
@Test
@Tags({ @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_BLACKDUCK_CONNECTION) })
public void retrieveTestIT() throws AlertException {
BlackDuckProperties blackDuckProperties = createBlackDuckProperties();
BlackDuckSSOConfigRetriever ssoConfigRetriever = BlackDuckSSOConfigRetriever.fromProperties(blackDuckProperties);
try {
BlackDuckSSOConfigView ssoConfig = ssoConfigRetriever.retrieve();
System.out.println("SSO Config:");
System.out.println(ssoConfig);
} catch (AlertException e) {
fail("SSO Config Retrieval Failed", e);
}
}
use of com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties in project hub-alert by blackducksoftware.
the class BlackDuckNotificationRetrieverFactoryTest method createBlackDuckProperties.
private BlackDuckProperties createBlackDuckProperties(String blackDuckUrl) {
ConfigurationModel configurationModel = createConfigurationModel(blackDuckUrl);
ProxyManager proxyManager = new ProxyManager(new MockSettingsUtility());
return new BlackDuckProperties(1L, new Gson(), BlackDuckServicesFactory.createDefaultObjectMapper(), new MockAlertProperties(), proxyManager, configurationModel);
}
use of com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties 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.provider.blackduck.BlackDuckProperties in project hub-alert by blackducksoftware.
the class NotificationExtractorBlackDuckServicesFactoryCache method createBlackDuckServicesFactory.
private BlackDuckServicesFactory createBlackDuckServicesFactory(Long blackDuckConfigId) throws AlertConfigurationException {
Optional<BlackDuckProperties> optionalProperties = blackDuckPropertiesFactory.createProperties(blackDuckConfigId);
if (optionalProperties.isPresent()) {
BlackDuckProperties blackDuckProperties = optionalProperties.get();
Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
try {
BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckCacheClient(intLogger);
return blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, intLogger);
} catch (AlertException e) {
throw new AlertConfigurationException("The BlackDuck configuration is invalid", e);
}
}
throw new AlertConfigurationException(String.format("No BlackDuck configuration with id '%s' existed", blackDuckConfigId));
}
use of com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties in project hub-alert by blackducksoftware.
the class BlackDuckProjectCustomFunctionAction method validateBlackDuckConfiguration.
private void validateBlackDuckConfiguration(Long blackDuckConfigId) {
BlackDuckProperties blackDuckProperties = blackDuckPropertiesFactory.createProperties(blackDuckConfigId).orElseThrow(() -> new ResponseStatusException(HttpStatus.BAD_REQUEST, "The BlackDuck configuration used in this Job does not exist"));
BlackDuckApiTokenValidator blackDuckAPITokenValidator = new BlackDuckApiTokenValidator(blackDuckProperties);
if (!blackDuckAPITokenValidator.isApiTokenValid()) {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid permissions. The BlackDuck user configured would not have proper access to notifications for these projects.");
}
}
Aggregations