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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations