Search in sources :

Example 1 with MetaDataInspection

use of com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection in project sechub by mercedes-benz.

the class PDSCodeScanProductExecutor method executeWithAdapter.

@Override
protected List<ProductResult> executeWithAdapter(SecHubExecutionContext context, ProductExecutorContext executorContext, PDSInstallSetup setup, TargetRegistryInfo info) throws Exception {
    LOG.debug("Trigger PDS adapter execution");
    PDSExecutorConfigSuppport configSupport = PDSExecutorConfigSuppport.createSupportAndAssertConfigValid(executorContext.getExecutorConfig(), systemEnvironment);
    if (configSupport.isTargetTypeForbidden(info.getTargetType())) {
        LOG.info("pds adapter does not accept target type:{} so cancel execution");
        return Collections.emptyList();
    }
    UUID jobUUID = context.getSechubJobUUID();
    String projectId = context.getConfiguration().getProjectId();
    JobStorage storage = storageService.getJobStorage(projectId, jobUUID);
    ProductResult result = resilientActionExecutor.executeResilient(() -> {
        AdapterMetaData metaDataOrNull = executorContext.getCurrentMetaDataOrNull();
        /* we reuse existing file upload checksum done by sechub */
        String sourceZipFileChecksum = fetchFileUploadChecksumIfNecessary(storage, metaDataOrNull);
        try (InputStream sourceCodeZipFileInputStream = fetchInputStreamIfNecessary(storage, metaDataOrNull)) {
            /* @formatter:off */
            Map<String, String> jobParams = configSupport.createJobParametersToSendToPDS(context.getConfiguration());
            PDSCodeScanConfig pdsCodeScanConfig = PDSCodeScanConfigImpl.builder().setPDSProductIdentifier(configSupport.getPDSProductIdentifier()).setTrustAllCertificates(configSupport.isTrustAllCertificatesEnabled()).setProductBaseUrl(configSupport.getProductBaseURL()).setSecHubJobUUID(context.getSechubJobUUID()).setSecHubConfigModel(context.getConfiguration()).configure(createAdapterOptionsStrategy(context)).setTimeToWaitForNextCheckOperationInMilliseconds(configSupport.getTimeToWaitForNextCheckOperationInMilliseconds(setup)).setTimeOutInMinutes(configSupport.getTimeoutInMinutes(setup)).setFileSystemSourceFolders(info.getCodeUploadFileSystemFolders()).setSourceCodeZipFileInputStream(sourceCodeZipFileInputStream).setSourceZipFileChecksum(sourceZipFileChecksum).setUser(configSupport.getUser()).setPasswordOrAPIToken(configSupport.getPasswordOrAPIToken()).setProjectId(projectId).setTraceID(context.getTraceLogIdAsString()).setJobParameters(jobParams).build();
            /* @formatter:on */
            /* inspect */
            MetaDataInspection inspection = scanMetaDataCollector.inspect(ProductIdentifier.PDS_CODESCAN.name());
            inspection.notice(MetaDataInspection.TRACE_ID, pdsCodeScanConfig.getTraceID());
            /* execute PDS by adapter and update product result */
            String pdsResult = pdsAdapter.start(pdsCodeScanConfig, executorContext.getCallback());
            // product result is set by callback
            ProductResult productResult = executorContext.getCurrentProductResult();
            productResult.setResult(pdsResult);
            return productResult;
        }
    });
    return Collections.singletonList(result);
}
Also used : MetaDataInspection(com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) InputStream(java.io.InputStream) PDSCodeScanConfig(com.mercedesbenz.sechub.adapter.pds.PDSCodeScanConfig) UUID(java.util.UUID) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage) AdapterMetaData(com.mercedesbenz.sechub.adapter.AdapterMetaData)

Example 2 with MetaDataInspection

use of com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection in project sechub by mercedes-benz.

the class CheckmarxProductExecutor method executeWithAdapter.

@Override
protected List<ProductResult> executeWithAdapter(SecHubExecutionContext context, ProductExecutorContext executorContext, CheckmarxInstallSetup setup, TargetRegistryInfo data) throws Exception {
    LOG.debug("Trigger checkmarx adapter execution");
    UUID jobUUID = context.getSechubJobUUID();
    String projectId = context.getConfiguration().getProjectId();
    JobStorage storage = storageService.getJobStorage(projectId, jobUUID);
    CheckmarxExecutorConfigSuppport configSupport = CheckmarxExecutorConfigSuppport.createSupportAndAssertConfigValid(executorContext.getExecutorConfig(), systemEnvironment);
    CheckmarxResilienceCallback callback = new CheckmarxResilienceCallback(configSupport, executorContext);
    /* start resilient */
    ProductResult result = resilientActionExecutor.executeResilient(() -> {
        AdapterMetaData metaDataOrNull = executorContext.getCurrentMetaDataOrNull();
        try (InputStream sourceCodeZipFileInputStream = fetchInputStreamIfNecessary(storage, metaDataOrNull)) {
            /* @formatter:off */
            CheckmarxAdapterConfig checkMarxConfig = CheckmarxConfig.builder().configure(createAdapterOptionsStrategy(context)).setTrustAllCertificates(setup.isHavingUntrustedCertificate()).setUser(configSupport.getUser()).setPasswordOrAPIToken(configSupport.getPasswordOrAPIToken()).setProductBaseUrl(configSupport.getProductBaseURL()).setAlwaysFullScan(callback.isAlwaysFullScanEnabled()).setTimeToWaitForNextCheckOperationInMinutes(scanResultCheckPeriodInMinutes).setTimeOutInMinutes(scanResultCheckTimeOutInMinutes).setFileSystemSourceFolders(data.getCodeUploadFileSystemFolders()).setSourceCodeZipFileInputStream(sourceCodeZipFileInputStream).setTeamIdForNewProjects(configSupport.getTeamIdForNewProjects(projectId)).setClientSecret(configSupport.getClientSecret()).setEngineConfigurationName(configSupport.getEngineConfigurationName()).setPresetIdForNewProjects(configSupport.getPresetIdForNewProjects(projectId)).setProjectId(projectId).setTraceID(context.getTraceLogIdAsString()).build();
            /* @formatter:on */
            /* inspect */
            MetaDataInspection inspection = scanMetaDataCollector.inspect(ProductIdentifier.CHECKMARX.name());
            inspection.notice(MetaDataInspection.TRACE_ID, checkMarxConfig.getTraceID());
            inspection.notice("presetid", checkMarxConfig.getPresetIdForNewProjectsOrNull());
            inspection.notice("engineconfigurationname", checkMarxConfig.getEngineConfigurationName());
            inspection.notice("teamid", checkMarxConfig.getTeamIdForNewProjects());
            inspection.notice("alwaysFullScanEnabled", checkMarxConfig.isAlwaysFullScanEnabled());
            /* execute checkmarx by adapter and update product result */
            String xml = checkmarxAdapter.start(checkMarxConfig, executorContext.getCallback());
            // product result is set by callback
            ProductResult productResult = executorContext.getCurrentProductResult();
            productResult.setResult(xml);
            return productResult;
        }
    }, callback);
    return Collections.singletonList(result);
}
Also used : MetaDataInspection(com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) InputStream(java.io.InputStream) CheckmarxAdapterConfig(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterConfig) UUID(java.util.UUID) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage) AdapterMetaData(com.mercedesbenz.sechub.adapter.AdapterMetaData)

Example 3 with MetaDataInspection

use of com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection in project sechub by mercedes-benz.

the class CheckmarxProductExecutor method executeByAdapter.

@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
    LOG.debug("Trigger checkmarx adapter execution");
    UUID jobUUID = data.getSechubExecutionContext().getSechubJobUUID();
    String projectId = data.getSechubExecutionContext().getConfiguration().getProjectId();
    JobStorage storage = storageService.getJobStorage(projectId, jobUUID);
    CheckmarxExecutorConfigSuppport configSupport = CheckmarxExecutorConfigSuppport.createSupportAndAssertConfigValid(data.getProductExecutorContext().getExecutorConfig(), systemEnvironment);
    CheckmarxResilienceCallback callback = new CheckmarxResilienceCallback(configSupport, data.getProductExecutorContext());
    /* start resilient */
    ProductResult result = resilientActionExecutor.executeResilient(() -> {
        AdapterMetaData metaDataOrNull = data.getProductExecutorContext().getCurrentMetaDataOrNull();
        try (InputStream sourceCodeZipFileInputStream = fetchInputStreamIfNecessary(storage, metaDataOrNull)) {
            /* @formatter:off */
            @SuppressWarnings("deprecation") CheckmarxAdapterConfig checkMarxConfig = CheckmarxConfig.builder().configure(new SecHubAdapterOptionsBuilderStrategy(data, getScanType())).setTrustAllCertificates(installSetup.isHavingUntrustedCertificate()).setUser(configSupport.getUser()).setPasswordOrAPIToken(configSupport.getPasswordOrAPIToken()).setProductBaseUrl(configSupport.getProductBaseURL()).setAlwaysFullScan(callback.isAlwaysFullScanEnabled()).setTimeToWaitForNextCheckOperationInMinutes(scanResultCheckPeriodInMinutes).setTimeOutInMinutes(scanResultCheckTimeOutInMinutes).setFileSystemSourceFolders(// to support mocked Checkmarx adapters we MUST use still the deprecated method!
            data.getCodeUploadFileSystemFolders()).setSourceCodeZipFileInputStream(sourceCodeZipFileInputStream).setTeamIdForNewProjects(configSupport.getTeamIdForNewProjects(projectId)).setClientSecret(configSupport.getClientSecret()).setEngineConfigurationName(configSupport.getEngineConfigurationName()).setPresetIdForNewProjects(configSupport.getPresetIdForNewProjects(projectId)).setProjectId(projectId).setTraceID(data.getSechubExecutionContext().getTraceLogIdAsString()).build();
            /* @formatter:on */
            /* inspect */
            MetaDataInspection inspection = scanMetaDataCollector.inspect(ProductIdentifier.CHECKMARX.name());
            inspection.notice(MetaDataInspection.TRACE_ID, checkMarxConfig.getTraceID());
            inspection.notice("presetid", checkMarxConfig.getPresetIdForNewProjectsOrNull());
            inspection.notice("engineconfigurationname", checkMarxConfig.getEngineConfigurationName());
            inspection.notice("teamid", checkMarxConfig.getTeamIdForNewProjects());
            inspection.notice("alwaysFullScanEnabled", checkMarxConfig.isAlwaysFullScanEnabled());
            /* execute checkmarx by adapter and update product result */
            String xml = checkmarxAdapter.start(checkMarxConfig, data.getProductExecutorContext().getCallback());
            // product result is set by callback
            ProductResult productResult = data.getProductExecutorContext().getCurrentProductResult();
            productResult.setResult(xml);
            return productResult;
        }
    }, callback);
    return Collections.singletonList(result);
}
Also used : MetaDataInspection(com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection) SecHubAdapterOptionsBuilderStrategy(com.mercedesbenz.sechub.domain.scan.SecHubAdapterOptionsBuilderStrategy) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) InputStream(java.io.InputStream) CheckmarxAdapterConfig(com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterConfig) UUID(java.util.UUID) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage) AdapterMetaData(com.mercedesbenz.sechub.adapter.AdapterMetaData)

Example 4 with MetaDataInspection

use of com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection in project sechub by mercedes-benz.

the class PDSCodeScanProductExecutor method executeByAdapter.

@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
    LOG.debug("Trigger PDS adapter execution");
    ProductExecutorContext executorContext = data.getProductExecutorContext();
    PDSExecutorConfigSuppport configSupport = PDSExecutorConfigSuppport.createSupportAndAssertConfigValid(executorContext.getExecutorConfig(), systemEnvironment);
    SecHubExecutionContext context = data.getSechubExecutionContext();
    PDSStorageContentProvider contentProvider = contentProviderFactory.createContentProvider(context, configSupport, getScanType());
    ProductResult result = resilientActionExecutor.executeResilient(() -> {
        try (InputStream sourceCodeZipFileInputStreamOrNull = contentProvider.getSourceZipFileInputStreamOrNull();
            InputStream binariesTarFileInputStreamOrNull = contentProvider.getBinariesTarFileInputStreamOrNull()) {
            /* @formatter:off */
            PDSCodeScanConfig pdsCodeScanConfig = PDSCodeScanConfigImpl.builder().configure(PDSAdapterConfigurationStrategy.builder().setScanType(getScanType()).setProductExecutorData(data).setConfigSupport(configSupport).setSourceCodeZipFileInputStreamOrNull(sourceCodeZipFileInputStreamOrNull).setBinariesTarFileInputStreamOrNull(binariesTarFileInputStreamOrNull).setContentProvider(contentProvider).setInstallSetup(installSetup).build()).build();
            /* @formatter:on */
            /* inspect */
            MetaDataInspection inspection = scanMetaDataCollector.inspect(ProductIdentifier.PDS_CODESCAN.name());
            inspection.notice(MetaDataInspection.TRACE_ID, pdsCodeScanConfig.getTraceID());
            /* execute PDS by adapter and update product result */
            String pdsResult = pdsAdapter.start(pdsCodeScanConfig, executorContext.getCallback());
            // product result is set by callback
            ProductResult productResult = executorContext.getCurrentProductResult();
            productResult.setResult(pdsResult);
            return productResult;
        }
    });
    return Collections.singletonList(result);
}
Also used : MetaDataInspection(com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) InputStream(java.io.InputStream) PDSCodeScanConfig(com.mercedesbenz.sechub.adapter.pds.PDSCodeScanConfig) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)

Example 5 with MetaDataInspection

use of com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection in project sechub by mercedes-benz.

the class PDSLicenseScanProductExecutor method executeByAdapter.

@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
    LOG.debug("Trigger PDS adapter execution");
    ProductExecutorContext executorContext = data.getProductExecutorContext();
    PDSExecutorConfigSuppport configSupport = PDSExecutorConfigSuppport.createSupportAndAssertConfigValid(executorContext.getExecutorConfig(), systemEnvironment);
    SecHubExecutionContext context = data.getSechubExecutionContext();
    PDSStorageContentProvider contentProvider = contentProviderFactory.createContentProvider(context, configSupport, getScanType());
    ProductResult result = resilientActionExecutor.executeResilient(() -> {
        try (InputStream sourceCodeZipFileInputStreamOrNull = contentProvider.getSourceZipFileInputStreamOrNull();
            InputStream binariesTarFileInputStreamOrNull = contentProvider.getBinariesTarFileInputStreamOrNull()) {
            /* @formatter:off */
            PDSLicenseScanConfig pdsLicenseScanConfig = PDSLicenseScanConfigImpl.builder().configure(PDSAdapterConfigurationStrategy.builder().setScanType(getScanType()).setProductExecutorData(data).setConfigSupport(configSupport).setSourceCodeZipFileInputStreamOrNull(sourceCodeZipFileInputStreamOrNull).setBinariesTarFileInputStreamOrNull(binariesTarFileInputStreamOrNull).setContentProvider(contentProvider).setInstallSetup(installSetup).build()).build();
            /* @formatter:on */
            /* inspect */
            MetaDataInspection inspection = scanMetaDataCollector.inspect(ProductIdentifier.PDS_LICENSESCAN.name());
            inspection.notice(MetaDataInspection.TRACE_ID, pdsLicenseScanConfig.getTraceID());
            /* execute PDS by adapter and update product result */
            String pdsResult = pdsAdapter.start(pdsLicenseScanConfig, executorContext.getCallback());
            // product result is set by callback
            ProductResult productResult = executorContext.getCurrentProductResult();
            productResult.setResult(pdsResult);
            return productResult;
        }
    });
    return Collections.singletonList(result);
}
Also used : MetaDataInspection(com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection) ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) InputStream(java.io.InputStream) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) PDSLicenseScanConfig(com.mercedesbenz.sechub.adapter.pds.PDSLicenseScanConfig)

Aggregations

ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)5 MetaDataInspection (com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection)5 InputStream (java.io.InputStream)5 AdapterMetaData (com.mercedesbenz.sechub.adapter.AdapterMetaData)3 JobStorage (com.mercedesbenz.sechub.storage.core.JobStorage)3 UUID (java.util.UUID)3 CheckmarxAdapterConfig (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterConfig)2 PDSCodeScanConfig (com.mercedesbenz.sechub.adapter.pds.PDSCodeScanConfig)2 ProductExecutorContext (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)2 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)2 PDSLicenseScanConfig (com.mercedesbenz.sechub.adapter.pds.PDSLicenseScanConfig)1 SecHubAdapterOptionsBuilderStrategy (com.mercedesbenz.sechub.domain.scan.SecHubAdapterOptionsBuilderStrategy)1