Search in sources :

Example 21 with ProductResult

use of com.mercedesbenz.sechub.domain.scan.product.ProductResult in project sechub by mercedes-benz.

the class PDSWebScanProductExecutor method executeByAdapter.

@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
    ProductExecutorContext executorContext = data.getProductExecutorContext();
    SecHubExecutionContext context = data.getSechubExecutionContext();
    NetworkTargetInfo info = data.getCurrentNetworkTargetInfo();
    /* we reuse config support created inside customize method */
    PDSExecutorConfigSuppport configSupport = (PDSExecutorConfigSuppport) data.getNetworkTargetDataProvider();
    URI targetURI = info.getURI();
    if (targetURI == null) {
        LOG.warn("NO target URI defined for PDS web scan execution");
        return Collections.emptyList();
    }
    NetworkTargetType targetType = info.getTargetType();
    if (configSupport.isTargetTypeForbidden(targetType)) {
        LOG.info("PDS adapter does not accept target type:{} so cancel execution");
        return Collections.emptyList();
    }
    LOG.debug("Trigger PDS adapter execution for target {} ", targetType);
    List<ProductResult> results = new ArrayList<>();
    /* @formatter:off */
    executorContext.useFirstFormerResultHavingMetaData(PDSMetaDataID.KEY_TARGET_URI, targetURI);
    PDSStorageContentProvider contentProvider = contentProviderFactory.createContentProvider(context, configSupport, getScanType());
    ProductResult result = resilientActionExecutor.executeResilient(() -> {
        try (InputStream sourceCodeZipFileInputStreamOrNull = contentProvider.getSourceZipFileInputStreamOrNull()) {
            PDSWebScanConfig pdsWebScanConfig = PDSWebScanConfigImpl.builder().configure(PDSAdapterConfigurationStrategy.builder().setScanType(getScanType()).setProductExecutorData(data).setConfigSupport(configSupport).setSourceCodeZipFileInputStreamOrNull(sourceCodeZipFileInputStreamOrNull).setContentProvider(contentProvider).setInstallSetup(installSetup).build()).configure(new WebConfigBuilderStrategy(context)).configure(new NetworkTargetProductServerDataAdapterConfigurationStrategy(configSupport, data.getCurrentNetworkTargetInfo().getTargetType())).setTargetURI(targetURI).setTargetType(info.getTargetType().name()).build();
            /* @formatter:on */
            /* execute PDS by adapter and return product result */
            String pdsResult = pdsAdapter.start(pdsWebScanConfig, executorContext.getCallback());
            ProductResult currentProductResult = executorContext.getCurrentProductResult();
            currentProductResult.setResult(pdsResult);
            return currentProductResult;
        }
    });
    results.add(result);
    return results;
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) NetworkTargetProductServerDataAdapterConfigurationStrategy(com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy) InputStream(java.io.InputStream) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) ArrayList(java.util.ArrayList) URI(java.net.URI) NetworkTargetInfo(com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo) PDSWebScanConfig(com.mercedesbenz.sechub.adapter.pds.PDSWebScanConfig) NetworkTargetType(com.mercedesbenz.sechub.domain.scan.NetworkTargetType) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) WebConfigBuilderStrategy(com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy)

Example 22 with ProductResult

use of com.mercedesbenz.sechub.domain.scan.product.ProductResult in project sechub by mercedes-benz.

the class IntegrationTestScanRestController method changeScanResults.

@RequestMapping(path = APIConstants.API_ANONYMOUS + "integrationtest/project/{projectId}/job/{sechubJobUUID}/scan/productresult/{productIdentifier}", method = RequestMethod.PUT, produces = { MediaType.APPLICATION_JSON_VALUE })
public void changeScanResults(@RequestBody String body, @PathVariable("projectId") String projectId, @PathVariable("sechubJobUUID") UUID sechubJobUUID, @PathVariable("productIdentifier") ProductIdentifier productIdentifier) {
    List<ProductResult> originResults = productResultService.fetchAllResultsForJob(sechubJobUUID);
    ProductResult result = null;
    for (ProductResult originProductResult : originResults) {
        if (productIdentifier.equals(originProductResult.getProductIdentifier())) {
            result = originProductResult;
            break;
        }
    }
    ProductResult resultToPersist = null;
    if (result != null) {
        resultToPersist = result;
    } else {
        // We do not know which executor this has been done - it's a new one, so we
        // create just a new configuration info without UUID
        WithoutProductExecutorConfigInfo info = new WithoutProductExecutorConfigInfo(productIdentifier);
        resultToPersist = new ProductResult(sechubJobUUID, projectId, info, body);
    }
    resultToPersist.setResult(body);
    productResultRepository.save(resultToPersist);
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) WithoutProductExecutorConfigInfo(com.mercedesbenz.sechub.domain.scan.product.config.WithoutProductExecutorConfigInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 23 with ProductResult

use of com.mercedesbenz.sechub.domain.scan.product.ProductResult in project sechub by mercedes-benz.

the class IntegrationTestScanRestController method fetchScanResults.

@RequestMapping(path = APIConstants.API_ANONYMOUS + "integrationtest/project/{projectId}/scan/productresult/all-shrinked/{maxLength}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE })
public List<ProductResult> fetchScanResults(@PathVariable("projectId") String projectId, @PathVariable("maxLength") int maxLength) {
    if (maxLength < 10) {
        maxLength = 10;
    }
    List<ProductResult> originResults = productResultService.fetchAllResultsInProject(projectId);
    List<ProductResult> shrinkedResults = new ArrayList<ProductResult>();
    for (ProductResult originProductResult : originResults) {
        String result = originProductResult.getResult();
        if (result.length() > maxLength) {
            result = result.substring(0, maxLength - 3) + "...";
        }
        ProductExecutorConfigInfo info = new DefaultProductExecutorConfigInfo(originProductResult.getProductIdentifier(), originProductResult.getProductExecutorConfigUUID());
        ProductResult shrinked = new ProductResult(originProductResult.getSecHubJobUUID(), originProductResult.getProjectId(), info, result);
        shrinkedResults.add(shrinked);
    }
    return shrinkedResults;
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) ArrayList(java.util.ArrayList) WithoutProductExecutorConfigInfo(com.mercedesbenz.sechub.domain.scan.product.config.WithoutProductExecutorConfigInfo) ProductExecutorConfigInfo(com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigInfo) DefaultProductExecutorConfigInfo(com.mercedesbenz.sechub.domain.scan.product.config.DefaultProductExecutorConfigInfo) DefaultProductExecutorConfigInfo(com.mercedesbenz.sechub.domain.scan.product.config.DefaultProductExecutorConfigInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with ProductResult

use of com.mercedesbenz.sechub.domain.scan.product.ProductResult in project sechub by mercedes-benz.

the class SecHubReportProductTransformerService method createResult.

ReportTransformationResult createResult(UUID secHubJobUUID) throws SecHubExecutionException {
    notNull(secHubJobUUID, "secHubJobUUID may not be null!");
    List<ProductResult> reportProductResults = productResultRepository.findAllProductResults(secHubJobUUID, SERECO);
    if (reportProductResults.isEmpty()) {
        throw new SecHubExecutionException("No report result found for:" + secHubJobUUID);
    }
    int reportProductResultAmount = reportProductResults.size();
    if (reportProductResultAmount > 1) {
        LOG.warn("Found {} report product results, should normally be only one!", reportProductResultAmount);
    }
    ReportTransformationResult transformResult = null;
    for (ProductResult reportProductResult : reportProductResults) {
        for (ReportProductResultTransformer transformer : transformers) {
            if (transformer.canTransform(reportProductResult.getProductIdentifier())) {
                LOG.debug("Transformer {} is used to transform result", transformer.getClass().getSimpleName());
                ReportTransformationResult transformedResult = transformer.transform(reportProductResult);
                transformResult = resultMerger.merge(transformResult, transformedResult);
            }
        }
    }
    if (transformResult == null) {
        throw new SecHubExecutionException("No transformable report result format found for:" + secHubJobUUID);
    }
    return transformResult;
}
Also used : SecHubExecutionException(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) ReportProductResultTransformer(com.mercedesbenz.sechub.domain.scan.report.ReportProductResultTransformer)

Example 25 with ProductResult

use of com.mercedesbenz.sechub.domain.scan.product.ProductResult in project sechub by mercedes-benz.

the class FullScanDataService method getFullScanData.

@UseCaseAdminDownloadsFullScanDataForJob(@Step(number = 2, name = "Collect all scan data"))
public FullScanData getFullScanData(UUID sechubJobUUID) {
    assertion.assertIsValidJobUUID(sechubJobUUID);
    LOG.debug("Start getting full scan data for {}", sechubJobUUID);
    FullScanData data = new FullScanData();
    data.sechubJobUUID = sechubJobUUID;
    List<ProjectScanLog> logs = projectScanLogService.fetchLogsForJob(sechubJobUUID);
    data.allScanLogs.addAll(logs);
    List<ProductResult> results = productResultService.fetchAllResultsForJob(sechubJobUUID);
    for (ProductResult result : results) {
        ScanData scanData = new ScanData();
        scanData.productId = result.getProductIdentifier().toString();
        scanData.executorConfigUUID = result.getProductExecutorConfigUUID();
        scanData.result = result.getResult();
        scanData.metaData = result.getMetaData();
        data.allScanData.add(scanData);
    }
    return data;
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) ProjectScanLog(com.mercedesbenz.sechub.domain.scan.log.ProjectScanLog) UseCaseAdminDownloadsFullScanDataForJob(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminDownloadsFullScanDataForJob)

Aggregations

ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)30 ProductExecutorContext (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)10 ArrayList (java.util.ArrayList)10 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)8 UUID (java.util.UUID)8 InputStream (java.io.InputStream)6 URI (java.net.URI)6 WithoutProductExecutorConfigInfo (com.mercedesbenz.sechub.domain.scan.product.config.WithoutProductExecutorConfigInfo)5 MetaDataInspection (com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection)5 NetworkTargetProductServerDataAdapterConfigurationStrategy (com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy)4 NetworkTargetInfo (com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo)4 NetworkTargetType (com.mercedesbenz.sechub.domain.scan.NetworkTargetType)4 TargetType (com.mercedesbenz.sechub.domain.scan.TargetType)4 WebConfigBuilderStrategy (com.mercedesbenz.sechub.domain.scan.WebConfigBuilderStrategy)4 Test (org.junit.Test)4 AdapterMetaData (com.mercedesbenz.sechub.adapter.AdapterMetaData)3 SecHubAdapterOptionsBuilderStrategy (com.mercedesbenz.sechub.domain.scan.SecHubAdapterOptionsBuilderStrategy)3 ProductExecutorConfig (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig)3 JobStorage (com.mercedesbenz.sechub.storage.core.JobStorage)3 Test (org.junit.jupiter.api.Test)3