Search in sources :

Example 1 with ProjectVersionView

use of com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView in project hub-detect by blackducksoftware.

the class Application method init.

@PostConstruct
public void init() {
    final long start = System.currentTimeMillis();
    try {
        detectInfo.init();
        detectOptionManager.init();
        final List<DetectOption> options = detectOptionManager.getDetectOptions();
        boolean isPrintHelp = false;
        boolean isPrintHelpDoc = false;
        boolean isInteractive = false;
        for (final String arg : applicationArguments.getSourceArgs()) {
            if (arg.equals("-h") || arg.equals("--help")) {
                isPrintHelp = true;
            } else if (arg.equals("-hdoc") || arg.equals("--helpdocument")) {
                isPrintHelpDoc = true;
            } else if (arg.equals("-i") || arg.equals("--interactive")) {
                isInteractive = true;
            }
        }
        if (isPrintHelp) {
            helpPrinter.printHelpMessage(System.out, options);
            return;
        }
        if (isPrintHelpDoc) {
            helpHtmlWriter.writeHelpMessage(String.format("hub-detect-%s-help.html", detectInfo.getDetectVersion()));
            return;
        }
        if (isInteractive) {
            final InteractiveReader interactiveReader = createInteractiveReader();
            final PrintStream interactivePrintStream = new PrintStream(System.out);
            interactiveManager.interact(interactiveReader, interactivePrintStream);
        }
        detectConfiguration.init();
        logger.info("Configuration processed completely.");
        if (!detectConfiguration.getSuppressConfigurationOutput()) {
            final DetectInfoPrinter infoPrinter = new DetectInfoPrinter();
            final DetectConfigurationPrinter detectConfigurationPrinter = new DetectConfigurationPrinter();
            infoPrinter.printInfo(System.out, detectInfo);
            detectConfigurationPrinter.print(System.out, detectInfo, detectConfiguration, options);
        }
        if (detectConfiguration.getTestConnection()) {
            hubServiceWrapper.assertHubConnection(new SilentLogger());
            return;
        }
        if (!detectConfiguration.getHubOfflineMode()) {
            hubServiceWrapper.init();
        }
        final DetectProject detectProject = detectProjectManager.createDetectProject();
        final List<File> createdBdioFiles = detectProjectManager.createBdioFiles(detectProject);
        if (!detectConfiguration.getHubOfflineMode()) {
            final ProjectVersionView projectVersionView = hubManager.updateHubProjectVersion(detectProject, createdBdioFiles);
            hubManager.performPostHubActions(detectProject, projectVersionView);
        } else if (!detectConfiguration.getHubSignatureScannerDisabled()) {
            hubSignatureScanner.scanPathsOffline(detectProject);
        }
        for (final ExitCodeReporter exitCodeReporter : exitCodeReporters) {
            exitCodeType = ExitCodeType.getWinningExitCodeType(exitCodeType, exitCodeReporter.getExitCodeType());
        }
    } catch (final Exception e) {
        populateExitCodeFromExceptionDetails(e);
    } finally {
        try {
            detectPhoneHomeManager.endPhoneHome();
        } catch (final Exception e) {
            logger.debug(String.format("Error trying to end the phone home task: %s", e.getMessage()));
        }
        if (!detectConfiguration.getSuppressResultsOutput()) {
            detectSummary.logResults(new Slf4jIntLogger(logger), exitCodeType);
        }
        detectFileManager.cleanupDirectories();
    }
    final long end = System.currentTimeMillis();
    logger.info(String.format("Hub-Detect run duration: %s", DurationFormatUtils.formatPeriod(start, end, "HH'h' mm'm' ss's' SSS'ms'")));
    if (detectConfiguration.getForceSuccess() && exitCodeType.getExitCode() != 0) {
        logger.warn("Forcing success: Exiting with 0. Desired exit code was ${exitCodeType.getExitCode()}.");
        System.exit(0);
    } else {
        System.exit(exitCodeType.getExitCode());
    }
}
Also used : PrintStream(java.io.PrintStream) InteractiveReader(com.blackducksoftware.integration.hub.detect.interactive.reader.InteractiveReader) ScannerInteractiveReader(com.blackducksoftware.integration.hub.detect.interactive.reader.ScannerInteractiveReader) ConsoleInteractiveReader(com.blackducksoftware.integration.hub.detect.interactive.reader.ConsoleInteractiveReader) DetectInfoPrinter(com.blackducksoftware.integration.hub.detect.help.print.DetectInfoPrinter) DetectUserFriendlyException(com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) DetectOption(com.blackducksoftware.integration.hub.detect.help.DetectOption) DetectProject(com.blackducksoftware.integration.hub.detect.model.DetectProject) ExitCodeReporter(com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeReporter) DetectConfigurationPrinter(com.blackducksoftware.integration.hub.detect.help.print.DetectConfigurationPrinter) Slf4jIntLogger(com.blackducksoftware.integration.log.Slf4jIntLogger) SilentLogger(com.blackducksoftware.integration.log.SilentLogger) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) File(java.io.File) PostConstruct(javax.annotation.PostConstruct)

Example 2 with ProjectVersionView

use of com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView in project hub-fortify-ssc-integration-service by blackducksoftware.

the class BlackDuckFortifyPushThread method call.

@Override
public Boolean call() throws DateTimeParseException, IntegrationException, IllegalArgumentException, JsonGenerationException, JsonMappingException, FileNotFoundException, UnsupportedEncodingException, IOException {
    logger.info("blackDuckFortifyMapper::" + blackDuckFortifyMapperGroup.toString());
    final List<HubProjectVersion> hubProjectVersions = blackDuckFortifyMapperGroup.getHubProjectVersion();
    // Get the last successful runtime of the job
    final Date getLastSuccessfulJobRunTime = getLastSuccessfulJobRunTime(propertyConstants.getBatchJobStatusFilePath());
    logger.debug("Last successful job excecution:" + getLastSuccessfulJobRunTime);
    // Get the project version view from Hub and calculate the max BOM updated date
    final List<ProjectVersionView> projectVersionItems = getProjectVersionItemsAndMaxBomUpdatedDate(hubProjectVersions);
    logger.info("Compare Dates: " + ((getLastSuccessfulJobRunTime != null && maxBomUpdatedDate.after(getLastSuccessfulJobRunTime)) || (getLastSuccessfulJobRunTime == null) || (!propertyConstants.isBatchJobStatusCheck())));
    logger.debug("maxBomUpdatedDate:: " + maxBomUpdatedDate);
    logger.debug("isBatchJobStatusCheck::" + propertyConstants.isBatchJobStatusCheck());
    if ((getLastSuccessfulJobRunTime != null && maxBomUpdatedDate.after(getLastSuccessfulJobRunTime)) || (getLastSuccessfulJobRunTime == null) || (!propertyConstants.isBatchJobStatusCheck())) {
        // Get the vulnerabilities for all Hub project versions and merge it
        List<Vulnerability> mergedVulnerabilities = mergeVulnerabilities(hubProjectVersions, projectVersionItems);
        if (mergedVulnerabilities.size() > 0) {
            if (hubProjectVersions.size() > 1) {
                // Removing Duplicates within multiple Hub Project Versions.
                mergedVulnerabilities = VulnerabilityUtil.removeDuplicates(mergedVulnerabilities);
            }
            final String fileDir = propertyConstants.getReportDir();
            final String fileName = hubProjectVersions.get(0).getHubProject() + UNDERSCORE + hubProjectVersions.get(0).getHubProjectVersion() + UNDERSCORE + DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS").format(LocalDateTime.now()) + ".csv";
            // Write the vulnerabilities to CSV
            CSVUtils.writeToCSV(mergedVulnerabilities, fileDir + fileName, ',');
            // Get the file token for upload
            String token = getFileToken();
            // Upload the vulnerabilities CSV to Fortify
            uploadCSV(token, fileDir + fileName, blackDuckFortifyMapperGroup.getFortifyApplicationId());
            // Delete the file token that is created for upload
            fortifyFileTokenApi.deleteFileToken();
        }
    }
    return true;
}
Also used : HubProjectVersion(com.blackducksoftware.integration.fortify.batch.model.HubProjectVersion) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) Vulnerability(com.blackducksoftware.integration.fortify.batch.model.Vulnerability) Date(java.util.Date)

Example 3 with ProjectVersionView

use of com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView in project hub-fortify-ssc-integration-service by blackducksoftware.

the class CSVUtilsTest method testWriteToCSV.

@Test
public void testWriteToCSV() {
    System.out.println("Executing testWriteToCSV");
    ProjectVersionView projectVersionItem = null;
    List<VulnerableComponentView> vulnerableComponentViews;
    try {
        projectVersionItem = hubServices.getProjectVersion(PROJECT_NAME, VERSION_NAME);
        vulnerableComponentViews = hubServices.getVulnerabilityComponentViews(projectVersionItem);
        bomUpdatedValueAt = hubServices.getBomLastUpdatedAt(projectVersionItem);
    } catch (final IllegalArgumentException e1) {
        e1.printStackTrace();
        throw new RuntimeException(e1);
    } catch (final IntegrationException e1) {
        e1.printStackTrace();
        throw new RuntimeException(e1);
    }
    System.out.println("vulnerableComponentViews size::" + vulnerableComponentViews.size());
    assertNotNull(vulnerableComponentViews);
    assertNotNull(bomUpdatedValueAt);
    final List<Vulnerability> vulnerabilities = VulnerabilityUtil.transformMapping(vulnerableComponentViews, PROJECT_NAME, VERSION_NAME, bomUpdatedValueAt, propertyConstants);
    System.out.println("vulnerabilities size::" + vulnerabilities.size());
    assertEquals(vulnerableComponentViews.size(), vulnerabilities.size());
    try {
        // csvUtils.writeToCSV(vulnerabilities, PROJECT_NAME + "_" + VERSION_NAME + new Date(), ',');
        CSVUtils.writeToCSV(vulnerabilities, "sample.csv", ',');
    } catch (final Exception e) {
        e.printStackTrace();
    }
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) Vulnerability(com.blackducksoftware.integration.fortify.batch.model.Vulnerability) VulnerableComponentView(com.blackducksoftware.integration.hub.api.generated.view.VulnerableComponentView) IOException(java.io.IOException) JsonIOException(com.google.gson.JsonIOException) IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 4 with ProjectVersionView

use of com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView in project hub-fortify-ssc-integration-service by blackducksoftware.

the class HubServicesTest method getVulnerability.

@Test
public void getVulnerability() throws Exception {
    System.out.println("Executing getVulnerability");
    ProjectVersionView projectVersionItem = null;
    try {
        projectVersionItem = hubServices.getProjectVersion(PROJECT_NAME, VERSION_NAME);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IntegrationException e) {
        e.printStackTrace();
    }
    List<VulnerableComponentView> vulnerableComponentViews = hubServices.getVulnerabilityComponentViews(projectVersionItem);
    System.out.println("vulnerableComponentViews size::" + vulnerableComponentViews.size() + ", vulnerableComponentViews::" + vulnerableComponentViews);
    assertNotNull(vulnerableComponentViews);
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) VulnerableComponentView(com.blackducksoftware.integration.hub.api.generated.view.VulnerableComponentView) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with ProjectVersionView

use of com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView in project hub-fortify-ssc-integration-service by blackducksoftware.

the class HubServicesTest method getProjectVersion.

@Test
public void getProjectVersion() {
    System.out.println("Executing getProjectVersion");
    ProjectVersionView projectVersionItem = null;
    try {
        projectVersionItem = hubServices.getProjectVersion(PROJECT_NAME, VERSION_NAME);
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (IntegrationException e) {
        e.printStackTrace();
    }
    assertNotNull(projectVersionItem);
}
Also used : IntegrationException(com.blackducksoftware.integration.exception.IntegrationException) ProjectVersionView(com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ProjectVersionView (com.blackducksoftware.integration.hub.api.generated.view.ProjectVersionView)12 IntegrationException (com.blackducksoftware.integration.exception.IntegrationException)9 Test (org.junit.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 Date (java.util.Date)4 Vulnerability (com.blackducksoftware.integration.fortify.batch.model.Vulnerability)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 HubProjectVersion (com.blackducksoftware.integration.fortify.batch.model.HubProjectVersion)2 VulnerableComponentView (com.blackducksoftware.integration.hub.api.generated.view.VulnerableComponentView)2 JsonIOException (com.google.gson.JsonIOException)2 File (java.io.File)2 ProjectRequest (com.blackducksoftware.integration.hub.api.generated.component.ProjectRequest)1 HubScanConfig (com.blackducksoftware.integration.hub.configuration.HubScanConfig)1 HubScanConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubScanConfigBuilder)1 HubServerConfig (com.blackducksoftware.integration.hub.configuration.HubServerConfig)1 DetectUserFriendlyException (com.blackducksoftware.integration.hub.detect.exception.DetectUserFriendlyException)1 ExitCodeReporter (com.blackducksoftware.integration.hub.detect.exitcode.ExitCodeReporter)1 DetectOption (com.blackducksoftware.integration.hub.detect.help.DetectOption)1 DetectConfigurationPrinter (com.blackducksoftware.integration.hub.detect.help.print.DetectConfigurationPrinter)1