use of com.synopsys.integration.log.Slf4jIntLogger in project hub-alert by blackducksoftware.
the class BlackDuckPhoneHomeHandler method populatePhoneHomeData.
@Override
public PhoneHomeRequestBodyBuilder populatePhoneHomeData(ConfigurationModel configurationModel, NameVersion alertArtifactInfo) {
String registrationId = null;
String blackDuckUrl = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
String blackDuckVersion = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
try {
descriptorAccessor.getRegisteredDescriptorById(configurationModel.getDescriptorId());
StatefulProvider statefulProvider = provider.createStatefulProvider(configurationModel);
BlackDuckProperties blackDuckProperties = (BlackDuckProperties) statefulProvider.getProperties();
BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(logger);
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, new Slf4jIntLogger(logger));
BlackDuckRegistrationService blackDuckRegistrationService = blackDuckServicesFactory.createBlackDuckRegistrationService();
BlackDuckServerData blackDuckServerData = blackDuckRegistrationService.getBlackDuckServerData();
blackDuckVersion = blackDuckServerData.getVersion();
registrationId = blackDuckServerData.getRegistrationKey().orElse(null);
blackDuckUrl = blackDuckProperties.getBlackDuckUrl().orElse(PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE);
} catch (IntegrationException ignored) {
// ignoring this exception
}
// We must check if the reg id is blank because of an edge case in which Black Duck can authenticate (while the webserver is coming up) without registration
if (StringUtils.isBlank(registrationId)) {
registrationId = PhoneHomeRequestBody.UNKNOWN_FIELD_VALUE;
}
PhoneHomeRequestBodyBuilder phoneHomeBuilder = new PhoneHomeRequestBodyBuilder(registrationId, blackDuckUrl, alertArtifactInfo, UniquePhoneHomeProduct.BLACK_DUCK, blackDuckVersion);
return phoneHomeBuilder;
}
use of com.synopsys.integration.log.Slf4jIntLogger in project hub-alert by blackducksoftware.
the class BlackDuckGlobalFieldModelTestAction method testConfig.
@Override
public MessageResult testConfig(String configId, FieldModel fieldModel, FieldUtility registeredFieldValues) throws IntegrationException {
Slf4jIntLogger intLogger = new Slf4jIntLogger(logger);
String apiToken = registeredFieldValues.getStringOrEmpty(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY);
String url = registeredFieldValues.getStringOrEmpty(BlackDuckDescriptor.KEY_BLACKDUCK_URL);
String timeout = registeredFieldValues.getStringOrEmpty(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT);
Long parsedConfigurationId = ProviderProperties.UNKNOWN_CONFIG_ID;
if (StringUtils.isNotBlank(configId)) {
try {
parsedConfigurationId = Long.valueOf(configId);
} catch (NumberFormatException ex) {
throw new AlertException("Configuration id not valid.");
}
}
BlackDuckProperties blackDuckProperties = blackDuckPropertiesFactory.createProperties(parsedConfigurationId, registeredFieldValues);
BlackDuckServerConfigBuilder blackDuckServerConfigBuilder = blackDuckProperties.createServerConfigBuilderWithoutAuthentication(intLogger, NumberUtils.toInt(timeout, 300));
blackDuckServerConfigBuilder.setApiToken(apiToken);
blackDuckServerConfigBuilder.setUrl(url);
validateBlackDuckConfiguration(blackDuckServerConfigBuilder);
BlackDuckServerConfig blackDuckServerConfig = blackDuckServerConfigBuilder.build();
ConnectionResult connectionResult = blackDuckServerConfig.attemptConnection(intLogger);
if (connectionResult.isFailure()) {
String failureMessage = connectionResult.getFailureMessage().orElse("");
Exception errorException = connectionResult.getException().orElse(null);
if (RestConstants.UNAUTHORIZED_401 == connectionResult.getHttpStatusCode()) {
throw AlertFieldException.singleFieldError(String.format("Invalid credential(s) for: %s. %s", url, failureMessage), BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, "This API Key isn't valid, try a different one.");
} else if (connectionResult.getHttpStatusCode() > 0) {
// TODO why are we throwing a non-alert exception?
HttpUrl connectionUrl = new HttpUrl(url);
throw new IntegrationRestException(HttpMethod.GET, connectionUrl, connectionResult.getHttpStatusCode(), String.format("Could not connect to: %s", url), failureMessage, errorException);
}
throw new AlertException(String.format("Could not connect to: %s. %s", url, failureMessage), errorException);
}
BlackDuckApiTokenValidator blackDuckAPITokenValidator = new BlackDuckApiTokenValidator(blackDuckProperties);
if (!blackDuckAPITokenValidator.isApiTokenValid()) {
throw AlertFieldException.singleFieldError(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, "User permission failed. Cannot read notifications from Black Duck.");
}
return new MessageResult("Successfully connected to BlackDuck server.");
}
use of com.synopsys.integration.log.Slf4jIntLogger in project hub-alert by blackducksoftware.
the class BlackDuckCacheHttpClientCache method retrieveOrCreateBlackDuckCacheHttpClient.
public BlackDuckHttpClient retrieveOrCreateBlackDuckCacheHttpClient(Long blackDuckConfigId) throws IntegrationException {
BlackDuckHttpClient cachedClient = httpClientCache.get(blackDuckConfigId);
if (null != cachedClient) {
return cachedClient;
}
BlackDuckProperties properties = blackDuckPropertiesFactory.createProperties(blackDuckConfigId).orElseThrow(() -> new AlertConfigurationException(String.format("No BlackDuck configuration with id %s", blackDuckConfigId)));
BlackDuckHttpClient blackDuckCacheClient = properties.createBlackDuckCacheClient(new Slf4jIntLogger(logger));
httpClientCache.put(blackDuckConfigId, blackDuckCacheClient);
return blackDuckCacheClient;
}
use of com.synopsys.integration.log.Slf4jIntLogger in project hub-alert by blackducksoftware.
the class BlackDuckIssueTrackerCallbackEventHandler method createBlackDuckServicesFactory.
private Optional<BlackDuckServicesFactory> createBlackDuckServicesFactory(BlackDuckProperties blackDuckProperties) {
IntLogger intLogger = new Slf4jIntLogger(logger);
try {
BlackDuckHttpClient blackDuckHttpClient = blackDuckProperties.createBlackDuckHttpClient(intLogger);
BlackDuckServicesFactory blackDuckServicesFactory = blackDuckProperties.createBlackDuckServicesFactory(blackDuckHttpClient, intLogger);
return Optional.of(blackDuckServicesFactory);
} catch (AlertException e) {
logger.error("Failed to create a BlackDuck http client", e);
return Optional.empty();
}
}
use of com.synopsys.integration.log.Slf4jIntLogger in project hub-alert by blackducksoftware.
the class BlackDuckDataSyncTask method runProviderTask.
@Override
public void runProviderTask() {
try {
BlackDuckProperties providerProperties = getProviderProperties();
Optional<BlackDuckHttpClient> optionalBlackDuckHttpClient = providerProperties.createBlackDuckHttpClientAndLogErrors(logger);
if (optionalBlackDuckHttpClient.isPresent()) {
BlackDuckHttpClient blackDuckHttpClient = optionalBlackDuckHttpClient.get();
BlackDuckServicesFactory blackDuckServicesFactory = providerProperties.createBlackDuckServicesFactory(blackDuckHttpClient, new Slf4jIntLogger(logger));
ProjectUsersService projectUsersService = blackDuckServicesFactory.createProjectUsersService();
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
ApiDiscovery apiDiscovery = blackDuckServicesFactory.getApiDiscovery();
List<ProjectView> projectViews = blackDuckApiClient.getAllResponses(apiDiscovery.metaProjectsLink());
Map<ProjectView, ProviderProject> blackDuckToAlertProjects = mapBlackDuckProjectsToAlertProjects(projectViews, blackDuckApiClient);
Map<ProviderProject, Set<String>> projectToEmailAddresses = getEmailsPerProject(blackDuckToAlertProjects, projectUsersService);
Set<String> allRelevantBlackDuckUsers = getAllActiveBlackDuckUserEmailAddresses(blackDuckApiClient, apiDiscovery);
blackDuckDataAccessor.updateProjectAndUserData(providerProperties.getConfigId(), projectToEmailAddresses, allRelevantBlackDuckUsers);
} else {
logger.error("Missing BlackDuck global configuration.");
}
} catch (IntegrationException | AlertRuntimeException e) {
logger.error(String.format("Could not retrieve the current data from the BlackDuck server: %s", e.getMessage()), e);
}
}
Aggregations