use of com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException in project hub-detect by blackducksoftware.
the class DockerInspectorManager method getShellScript.
private File getShellScript() throws DetectUserFriendlyException {
if (null == this.dockerInspectorShellScript) {
try {
final File shellScriptFile;
final File airGapHubDockerInspectorShellScript = new File(this.detectConfiguration.getDockerInspectorAirGapPath(), "hub-docker-inspector.sh");
this.logger.debug(String.format("Verifying air gap shell script present at %s", airGapHubDockerInspectorShellScript.getCanonicalPath()));
if (StringUtils.isNotBlank(this.detectConfiguration.getDockerInspectorPath())) {
shellScriptFile = new File(this.detectConfiguration.getDockerInspectorPath());
} else if (airGapHubDockerInspectorShellScript.exists()) {
shellScriptFile = airGapHubDockerInspectorShellScript;
} else {
String hubDockerInspectorShellScriptUrl = LATEST_URL;
if (!"latest".equals(this.detectConfiguration.getDockerInspectorVersion())) {
hubDockerInspectorShellScriptUrl = String.format("https://blackducksoftware.github.io/hub-docker-inspector/hub-docker-inspector-%s.sh", this.detectConfiguration.getDockerInspectorVersion());
}
this.logger.info(String.format("Getting the Docker inspector shell script from %s", hubDockerInspectorShellScriptUrl));
final UnauthenticatedRestConnection restConnection = this.detectConfiguration.createUnauthenticatedRestConnection(hubDockerInspectorShellScriptUrl);
final Request request = new Request.Builder().uri(hubDockerInspectorShellScriptUrl).build();
String shellScriptContents = null;
Response response = null;
try {
response = restConnection.executeRequest(request);
shellScriptContents = response.getContentString();
} finally {
if (response != null) {
response.close();
}
}
shellScriptFile = this.detectFileManager.createFile(BomToolType.DOCKER, String.format("hub-docker-inspector-%s.sh", this.detectConfiguration.getDockerInspectorVersion()));
this.detectFileManager.writeToFile(shellScriptFile, shellScriptContents);
shellScriptFile.setExecutable(true);
}
this.dockerInspectorShellScript = shellScriptFile;
} catch (final Exception e) {
throw new DetectUserFriendlyException(String.format("There was a problem retrieving the docker inspector shell script: %s", e.getMessage()), e, ExitCodeType.FAILURE_GENERAL_ERROR);
}
}
return this.dockerInspectorShellScript;
}
use of com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException in project hub-detect by blackducksoftware.
the class HubManager method performPostHubActions.
public void performPostHubActions(final DetectProject detectProject, final ProjectVersionView projectVersionView) throws DetectUserFriendlyException {
try {
if (detectConfiguration.getPolicyCheck() || detectConfiguration.getRiskReportPdf() || detectConfiguration.getNoticesReport()) {
final ProjectService projectService = hubServiceWrapper.createProjectService();
final ScanStatusService scanStatusService = hubServiceWrapper.createScanStatusService();
waitForBomUpdate(hubServiceWrapper.createHubService(), scanStatusService, projectVersionView);
if (detectConfiguration.getPolicyCheck()) {
final PolicyStatusDescription policyStatusDescription = policyChecker.getPolicyStatus(projectService, projectVersionView);
logger.info(policyStatusDescription.getPolicyStatusMessage());
if (policyChecker.policyViolated(policyStatusDescription)) {
exitCodeType = ExitCodeType.FAILURE_POLICY_VIOLATION;
}
}
if (detectConfiguration.getRiskReportPdf()) {
final ReportService reportService = hubServiceWrapper.createReportService();
logger.info("Creating risk report pdf");
final File pdfFile = reportService.createReportPdfFile(new File(detectConfiguration.getRiskReportPdfOutputDirectory()), detectProject.getProjectName(), detectProject.getProjectVersionName());
logger.info(String.format("Created risk report pdf : %s", pdfFile.getCanonicalPath()));
}
if (detectConfiguration.getNoticesReport()) {
final ReportService reportService = hubServiceWrapper.createReportService();
logger.info("Creating notices report");
final File noticesFile = reportService.createNoticesReportFile(new File(detectConfiguration.getNoticesReportOutputDirectory()), detectProject.getProjectName(), detectProject.getProjectVersionName());
if (noticesFile != null) {
logger.info(String.format("Created notices report : %s", noticesFile.getCanonicalPath()));
}
}
}
if (null != detectProject.getDetectCodeLocations() && !detectProject.getDetectCodeLocations().isEmpty() && !detectConfiguration.getHubSignatureScannerDisabled()) {
// only log BOM URL if we have updated it in some way
final ProjectService projectService = hubServiceWrapper.createProjectService();
final HubService hubService = hubServiceWrapper.createHubService();
final ProjectVersionWrapper projectVersionWrapper = projectService.getProjectVersion(detectProject.getProjectName(), detectProject.getProjectVersionName());
final String componentsLink = hubService.getFirstLinkSafely(projectVersionWrapper.getProjectVersionView(), ProjectVersionView.COMPONENTS_LINK);
logger.info(String.format("To see your results, follow the URL: %s", componentsLink));
} else {
logger.debug("Found no code locations and did not run a scan.");
}
} catch (final IllegalStateException e) {
throw new DetectUserFriendlyException(String.format("Your Hub configuration is not valid: %s", e.getMessage()), e, ExitCodeType.FAILURE_HUB_CONNECTIVITY);
} catch (final IntegrationRestException e) {
throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_HUB_CONNECTIVITY);
} catch (final HubTimeoutExceededException e) {
throw new DetectUserFriendlyException(e.getMessage(), e, ExitCodeType.FAILURE_TIMEOUT);
} catch (final Exception e) {
throw new DetectUserFriendlyException(String.format("There was a problem: %s", e.getMessage()), e, ExitCodeType.FAILURE_GENERAL_ERROR);
}
}
use of com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException in project hub-detect by blackducksoftware.
the class HubServiceWrapper method init.
public void init() throws IntegrationException, DetectUserFriendlyException {
try {
slf4jIntLogger = new Slf4jIntLogger(logger);
hubServerConfig = createHubServerConfig(slf4jIntLogger);
hubServicesFactory = createHubServicesFactory(slf4jIntLogger, hubServerConfig);
} catch (IllegalStateException | EncryptionException e) {
throw new DetectUserFriendlyException(String.format("Not able to initialize Hub connection: %s", e.getMessage()), e, ExitCodeType.FAILURE_HUB_CONNECTIVITY);
}
final HubService hubService = createHubService();
final CurrentVersionView currentVersion = hubService.getResponse(ApiDiscovery.CURRENT_VERSION_LINK_RESPONSE);
logger.info(String.format("Successfully connected to Hub (version %s)!", currentVersion.version));
detectPhoneHomeManager.init(createPhoneHomeService());
detectPhoneHomeManager.startPhoneHome();
}
use of com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException in project hub-detect by blackducksoftware.
the class DetectConfiguration method ensureDirectoryExists.
private void ensureDirectoryExists(final String directoryPath, final String failureMessage) throws DetectUserFriendlyException {
final File directory = new File(directoryPath);
directory.mkdirs();
if (!directory.exists() || !directory.isDirectory()) {
throw new DetectUserFriendlyException(String.format("The directory ${directoryPath} does not exist. %s", failureMessage), ExitCodeType.FAILURE_GENERAL_ERROR);
}
}
Aggregations