Search in sources :

Example 6 with DetectUserFriendlyException

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;
}
Also used : Response(com.blackducksoftware.integration.hub.request.Response) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) Request(com.blackducksoftware.integration.hub.request.Request) File(java.io.File) UnauthenticatedRestConnection(com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection) IOException(java.io.IOException) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) ExecutableRunnerException(com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)

Example 7 with DetectUserFriendlyException

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);
    }
}
Also used : PolicyStatusDescription(com.blackducksoftware.integration.hub.service.model.PolicyStatusDescription) IntegrationRestException(com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException) ProjectService(com.blackducksoftware.integration.hub.service.ProjectService) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) IntegrationRestException(com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException) DoesNotExistException(com.blackducksoftware.integration.hub.exception.DoesNotExistException) HubTimeoutExceededException(com.blackducksoftware.integration.hub.exception.HubTimeoutExceededException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ReportService(com.blackducksoftware.integration.hub.service.ReportService) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) ScanStatusService(com.blackducksoftware.integration.hub.service.ScanStatusService) HubTimeoutExceededException(com.blackducksoftware.integration.hub.exception.HubTimeoutExceededException) File(java.io.File) ProjectVersionWrapper(com.blackducksoftware.integration.hub.service.model.ProjectVersionWrapper) HubService(com.blackducksoftware.integration.hub.service.HubService)

Example 8 with DetectUserFriendlyException

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();
}
Also used : CurrentVersionView(com.blackducksoftware.integration.hub.api.generated.response.CurrentVersionView) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) EncryptionException(com.blackducksoftware.integration.exception.EncryptionException) HubService(com.blackducksoftware.integration.hub.service.HubService)

Example 9 with DetectUserFriendlyException

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);
    }
}
Also used : DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) File(java.io.File)

Aggregations

DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)9 File (java.io.File)4 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)3 IOException (java.io.IOException)3 HubService (com.blackducksoftware.integration.hub.service.HubService)2 EncryptionException (com.blackducksoftware.integration.exception.EncryptionException)1 CurrentVersionView (com.blackducksoftware.integration.hub.api.generated.response.CurrentVersionView)1 CLIDownloadUtility (com.blackducksoftware.integration.hub.cli.CLIDownloadUtility)1 ExecutableRunnerException (com.blackducksoftware.integration.hub.detect.util.executable.ExecutableRunnerException)1 DoesNotExistException (com.blackducksoftware.integration.hub.exception.DoesNotExistException)1 HubTimeoutExceededException (com.blackducksoftware.integration.hub.exception.HubTimeoutExceededException)1 ProxyInfo (com.blackducksoftware.integration.hub.proxy.ProxyInfo)1 ProxyInfoBuilder (com.blackducksoftware.integration.hub.proxy.ProxyInfoBuilder)1 Request (com.blackducksoftware.integration.hub.request.Request)1 Response (com.blackducksoftware.integration.hub.request.Response)1 RestConnection (com.blackducksoftware.integration.hub.rest.RestConnection)1 UnauthenticatedRestConnection (com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnection)1 UnauthenticatedRestConnectionBuilder (com.blackducksoftware.integration.hub.rest.UnauthenticatedRestConnectionBuilder)1 IntegrationRestException (com.blackducksoftware.integration.hub.rest.exception.IntegrationRestException)1 ProjectService (com.blackducksoftware.integration.hub.service.ProjectService)1