Search in sources :

Example 11 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-docker-inspector by blackducksoftware.

the class DockerClientManager method deriveDockerTarFileGivenImageSpec.

private ImageTarWrapper deriveDockerTarFileGivenImageSpec() throws IntegrationException, IOException {
    ImageTarWrapper finalDockerTarfile;
    File imageTarDirectory = new File(programPaths.getDockerInspectorTargetDirPath());
    if (StringUtils.isNotBlank(config.getDockerImageId())) {
        finalDockerTarfile = getTarFileFromDockerImageById(config.getDockerImageId(), imageTarDirectory);
    } else if (StringUtils.isNotBlank(config.getDockerImageRepo())) {
        finalDockerTarfile = getTarFileFromDockerImage(config.getDockerImageRepo(), config.getDockerImageTag(), imageTarDirectory);
    } else {
        throw new BlackDuckIntegrationException("You must specify a docker image");
    }
    return finalDockerTarfile;
}
Also used : ImageTarWrapper(com.synopsys.integration.blackduck.dockerinspector.output.ImageTarWrapper) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) File(java.io.File)

Example 12 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project blackduck-docker-inspector by blackducksoftware.

the class BlackDuckClient method testBlackDuckConnection.

public void testBlackDuckConnection() throws BlackDuckIntegrationException {
    logger.trace(String.format("Black Duck username: %s", // ArgsWithSpacesTest tests this in output
    getBlackDuckUsername()));
    if (!config.isUploadBdio() || config.isOfflineMode()) {
        logger.debug("Upload of BDIO disabled or offline mode is enabled; skipping verification of Black Duck connection");
        return;
    }
    BlackDuckHttpClient httpConnection;
    try {
        httpConnection = createHttpConnection(intLogger);
        httpConnection.attemptAuthentication();
    } catch (IntegrationException e) {
        String msg = String.format("Error connecting to Black Duck: %s", e.getMessage());
        throw new BlackDuckIntegrationException(msg);
    }
    logger.info("Successful connection to Black Duck.");
}
Also used : IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) BlackDuckHttpClient(com.synopsys.integration.blackduck.http.client.BlackDuckHttpClient) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)

Example 13 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project synopsys-detect by blackducksoftware.

the class ImpactAnalysisBatchRunner method uploadFiles.

private ImpactAnalysisBatchOutput uploadFiles(ImpactAnalysisBatch impactAnalysisBatch) throws BlackDuckIntegrationException {
    List<ImpactAnalysisOutput> uploadOutputs = new ArrayList<>();
    try {
        List<ImpactAnalysisCallable> callables = createCallables(impactAnalysisBatch);
        List<Future<ImpactAnalysisOutput>> submitted = new ArrayList<>();
        for (ImpactAnalysisCallable callable : callables) {
            submitted.add(executorService.submit(callable));
        }
        for (Future<ImpactAnalysisOutput> future : submitted) {
            ImpactAnalysisOutput uploadOutput = future.get();
            uploadOutputs.add(uploadOutput);
        }
    } catch (InterruptedException e) {
        // Restore interrupted state...
        Thread.currentThread().interrupt();
        throw new BlackDuckIntegrationException(String.format("Encountered a problem uploading a impact analysis file: %s", e.getMessage()), e);
    } catch (Exception e) {
        throw new BlackDuckIntegrationException(String.format("Encountered a problem uploading a impact analysis file: %s", e.getMessage()), e);
    }
    return new ImpactAnalysisBatchOutput(uploadOutputs);
}
Also used : BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)

Example 14 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project synopsys-detect by blackducksoftware.

the class ReportService method getRiskReportData.

public ReportData getRiskReportData(ProjectView project, ProjectVersionView version) throws IntegrationException {
    ReportData reportData = new ReportData();
    reportData.setProjectName(project.getName());
    reportData.setProjectURL(project.getHref().string());
    reportData.setProjectVersion(version.getVersionName());
    reportData.setProjectVersionURL(getReportVersionUrl(version));
    reportData.setPhase(version.getPhase().toString());
    reportData.setDistribution(version.getDistribution().toString());
    List<BomComponent> components = new ArrayList<>();
    logger.trace("Getting the Report Contents using the Aggregate Bom Rest Server");
    List<ProjectVersionComponentVersionView> bomEntries;
    try {
        bomEntries = blackDuckApiClient.getAllResponses(version.metaComponentsLink());
    } catch (NoSuchElementException e) {
        throw new BlackDuckIntegrationException("BOM could not be read.  This is likely because you lack sufficient permissions.  Please check your permissions.");
    }
    HttpUrl originalVersionUrl = version.getHref();
    boolean policyFailure = false;
    for (ProjectVersionComponentVersionView projectVersionComponentView : bomEntries) {
        String policyStatus = projectVersionComponentView.getApprovalStatus().toString();
        if (StringUtils.isBlank(policyStatus)) {
            HttpUrl componentPolicyStatusURL;
            if (!StringUtils.isBlank(projectVersionComponentView.getComponentVersion())) {
                componentPolicyStatusURL = getComponentPolicyURL(originalVersionUrl, projectVersionComponentView.getComponentVersion());
            } else {
                componentPolicyStatusURL = getComponentPolicyURL(originalVersionUrl, projectVersionComponentView.getComponent());
            }
            if (!policyFailure) {
                // FIXME if we could check if Black Duck has the policy module we could remove a lot of the mess
                try {
                    PolicyStatusView bomPolicyStatus = blackDuckApiClient.getResponse(componentPolicyStatusURL, PolicyStatusView.class);
                    policyStatus = bomPolicyStatus.getApprovalStatus().toString();
                } catch (IntegrationException e) {
                    policyFailure = true;
                    logger.debug("Could not get the component policy status, the Black Duck policy module is not enabled");
                }
            }
        }
        BomComponent component = createBomComponentFromBomComponentView(projectVersionComponentView);
        component.setPolicyStatus(policyStatus);
        populatePolicyRuleInfo(component, projectVersionComponentView);
        components.add(component);
    }
    reportData.setComponents(components);
    LocalDateTime dateTime = getDateTimeOfLatestScanForProjectVersion(version, project.getName());
    reportData.setDateTimeOfLatestScan(dateTime);
    return reportData;
}
Also used : LocalDateTime(java.time.LocalDateTime) BomComponent(com.synopsys.integration.detect.workflow.blackduck.report.BomComponent) PolicyStatusView(com.synopsys.integration.blackduck.api.generated.deprecated.view.PolicyStatusView) IntegrationException(com.synopsys.integration.exception.IntegrationException) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException) ArrayList(java.util.ArrayList) HttpUrl(com.synopsys.integration.rest.HttpUrl) ReportData(com.synopsys.integration.detect.workflow.blackduck.report.ReportData) NoSuchElementException(java.util.NoSuchElementException) ProjectVersionComponentVersionView(com.synopsys.integration.blackduck.api.generated.view.ProjectVersionComponentVersionView)

Example 15 with BlackDuckIntegrationException

use of com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException in project synopsys-detect by blackducksoftware.

the class BinaryUploadOperation method throwExceptionForError.

// BinaryScanBatchOutput used to do this, but our understanding of what needs to happen has been
// changing rapidly. Once we're confident we know what it should do, it should presumably move back there.
private void throwExceptionForError(BinaryScanBatchOutput binaryScanBatchOutput) throws BlackDuckIntegrationException {
    for (BinaryScanOutput binaryScanOutput : binaryScanBatchOutput) {
        if (binaryScanOutput.getResult() == Result.FAILURE) {
            // Black Duck responses are single-line message (loggable as-is), but nginx Bad Gateway responses are
            // multi-line html with the message embedded (that mess up the log).
            // cleanResponse() attempts to produce something reasonable to log in either case
            String cleanedBlackDuckResponse = cleanResponse(binaryScanOutput.getResponse());
            String uploadErrorMessage = String.format("Error when uploading binary scan: %s (Black Duck response: %s)", binaryScanOutput.getErrorMessage().orElse(binaryScanOutput.getStatusMessage()), cleanedBlackDuckResponse);
            logger.error(uploadErrorMessage);
            throw new BlackDuckIntegrationException(uploadErrorMessage);
        }
    }
}
Also used : BinaryScanOutput(com.synopsys.integration.blackduck.codelocation.binaryscanner.BinaryScanOutput) BlackDuckIntegrationException(com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)

Aggregations

BlackDuckIntegrationException (com.synopsys.integration.blackduck.exception.BlackDuckIntegrationException)29 File (java.io.File)8 HttpUrl (com.synopsys.integration.rest.HttpUrl)7 ArrayList (java.util.ArrayList)7 IntegrationException (com.synopsys.integration.exception.IntegrationException)6 IOException (java.io.IOException)6 Future (java.util.concurrent.Future)5 UploadBatchOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadBatchOutput)3 UploadOutput (com.synopsys.integration.blackduck.codelocation.upload.UploadOutput)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 ApiDiscovery (com.synopsys.integration.blackduck.api.generated.discovery.ApiDiscovery)2 ProjectVersionReportView (com.synopsys.integration.blackduck.api.generated.view.ProjectVersionReportView)2 BdioFileContent (com.synopsys.integration.blackduck.bdio2.model.BdioFileContent)2 Bdio2ContentExtractor (com.synopsys.integration.blackduck.bdio2.util.Bdio2ContentExtractor)2 UploadTarget (com.synopsys.integration.blackduck.codelocation.upload.UploadTarget)2 BlackDuckPageResponse (com.synopsys.integration.blackduck.http.BlackDuckPageResponse)2 BlackDuckApiClient (com.synopsys.integration.blackduck.service.BlackDuckApiClient)2 DataService (com.synopsys.integration.blackduck.service.DataService)2 BlackDuckRequestBuilderEditor (com.synopsys.integration.blackduck.service.request.BlackDuckRequestBuilderEditor)2 IntLogger (com.synopsys.integration.log.IntLogger)2