Search in sources :

Example 11 with SecHubExecutionContext

use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext in project sechub by mercedes-benz.

the class ScanService method createExecutionContext.

private SecHubExecutionContext createExecutionContext(DomainMessage message) throws JSONConverterException {
    UUID uuid = message.get(SECHUB_UUID);
    String executedBy = message.get(EXECUTED_BY);
    SecHubConfiguration configuration = message.get(SECHUB_CONFIG);
    if (configuration == null) {
        throw new IllegalStateException("SecHubConfiguration not found in message - so cannot execute!");
    }
    SecHubExecutionContext executionContext = new SecHubExecutionContext(uuid, configuration, executedBy);
    buildOptions(executionContext);
    return executionContext;
}
Also used : SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) UUID(java.util.UUID)

Example 12 with SecHubExecutionContext

use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext in project sechub by mercedes-benz.

the class DefaultAdapterConfigurationStrategy method configure.

@Override
public <B extends AdapterConfigBuilder, C extends AdapterConfig> void configure(B configBuilder) {
    /* @formatter:off */
    SecHubExecutionContext context = data.getSechubExecutionContext();
    String projectId = context.getConfiguration().getProjectId();
    configBuilder.configure(new SecHubAdapterOptionsBuilderStrategy(data, scanType));
    configBuilder.setProductBaseUrl(configSupport.getProductBaseURL());
    configBuilder.setUser(configSupport.getUser());
    configBuilder.setPasswordOrAPIToken(configSupport.getPasswordOrAPIToken());
    configBuilder.setProjectId(projectId);
    configBuilder.setTraceID(context.getTraceLogIdAsString());
/* @formatter:on */
}
Also used : SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)

Example 13 with SecHubExecutionContext

use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext in project sechub by mercedes-benz.

the class CheckmarxProductExecutorMockTest method createExecutionContextForPseudoCodeScan.

private SecHubExecutionContext createExecutionContextForPseudoCodeScan() {
    SecHubExecutionContext context = mock(SecHubExecutionContext.class);
    SecHubConfiguration config = new SecHubConfiguration();
    config.setProjectId(PROJECT_EXAMPLE);
    SecHubCodeScanConfiguration codeScan = new SecHubCodeScanConfiguration();
    SecHubFileSystemConfiguration fileSystemConfig = new SecHubFileSystemConfiguration();
    fileSystemConfig.getFolders().add(PATH_EXAMPLE1);
    codeScan.setFileSystem(fileSystemConfig);
    config.setCodeScan(codeScan);
    when(context.getConfiguration()).thenReturn(config);
    return context;
}
Also used : SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) SecHubCodeScanConfiguration(com.mercedesbenz.sechub.commons.model.SecHubCodeScanConfiguration) SecHubFileSystemConfiguration(com.mercedesbenz.sechub.commons.model.SecHubFileSystemConfiguration)

Example 14 with SecHubExecutionContext

use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext in project sechub by mercedes-benz.

the class PDSAdapterConfigurationStrategy method handlePdsParts.

private void handlePdsParts(PDSAdapterConfigurator pdsConfigurable) {
    SecHubExecutionContext context = strategyConfig.productExecutorData.getSechubExecutionContext();
    Map<String, String> jobParameters = strategyConfig.configSupport.createJobParametersToSendToPDS(context.getConfiguration());
    pdsConfigurable.setJobParameters(jobParameters);
    pdsConfigurable.setReusingSecHubStorage(PDSExecutorConfigSuppport.isReusingSecHubStorage(jobParameters));
    pdsConfigurable.setScanType(strategyConfig.scanType);
    pdsConfigurable.setPdsProductIdentifier(strategyConfig.configSupport.getPDSProductIdentifier());
    pdsConfigurable.setSecHubJobUUID(context.getSechubJobUUID());
    pdsConfigurable.setSecHubConfigurationModel(context.getConfiguration());
    pdsConfigurable.setSourceCodeZipFileInputStreamOrNull(strategyConfig.sourceCodeZipFileInputStreamOrNull);
    pdsConfigurable.setBinaryTarFileInputStreamOrNull(strategyConfig.binariesTarFileInputStreamOrNull);
    pdsConfigurable.setSourceCodeZipFileRequired(strategyConfig.contentProvider.isSourceRequired());
    pdsConfigurable.setBinaryTarFileRequired(strategyConfig.contentProvider.isBinaryRequired());
    try {
        String sourceZipFileChecksum = strategyConfig.contentProvider.getSourceZipFileUploadChecksumOrNull();
        pdsConfigurable.setSourceCodeZipFileChecksumOrNull(sourceZipFileChecksum);
    } catch (IOException e) {
        throw new SecHubRuntimeException("Was not able to retrieve source zip upload checksum", e);
    }
    try {
        String binaryTarFileChecksum = strategyConfig.contentProvider.getBinariesTarFileUploadChecksumOrNull();
        pdsConfigurable.setBinariesTarFileChecksumOrNull(binaryTarFileChecksum);
    } catch (IOException e) {
        throw new SecHubRuntimeException("Was not able to retrieve tar file upload checksum", e);
    }
}
Also used : SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext) SecHubRuntimeException(com.mercedesbenz.sechub.commons.model.SecHubRuntimeException) IOException(java.io.IOException)

Example 15 with SecHubExecutionContext

use of com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext in project sechub by mercedes-benz.

the class PDSInfraScanProductExecutor method executeByAdapter.

@Override
protected List<ProductResult> executeByAdapter(ProductExecutorData data) throws Exception {
    NetworkTargetInfo info = data.getCurrentNetworkTargetInfo();
    Set<URI> targetURIs = info.getURIs();
    if (targetURIs.isEmpty()) {
        /* no targets defined */
        return Collections.emptyList();
    }
    NetworkTargetType targetType = info.getTargetType();
    ProductExecutorContext executorContext = data.getProductExecutorContext();
    /* we reuse config support created inside customize method */
    PDSExecutorConfigSuppport configSupport = (PDSExecutorConfigSuppport) data.getNetworkTargetDataProvider();
    if (configSupport.isTargetTypeForbidden(targetType)) {
        LOG.info("pds adapter does not accept target type:{} so cancel execution");
        return Collections.emptyList();
    }
    LOG.debug("Trigger pds infra scan adapter execution for target {}", targetType);
    List<ProductResult> results = new ArrayList<>();
    SecHubExecutionContext context = data.getSechubExecutionContext();
    PDSStorageContentProvider contentProvider = contentProviderFactory.createContentProvider(context, configSupport, getScanType());
    for (URI targetURI : targetURIs) {
        /* @formatter:off */
        /* special behavior, because having multiple results here, we must find former result corresponding to
             * target URI.
             */
        executorContext.useFirstFormerResultHavingMetaData(PDSMetaDataID.KEY_TARGET_URI, targetURI);
        PDSInfraScanConfig pdsInfraScanConfig = PDSInfraScanConfigImpl.builder().configure(PDSAdapterConfigurationStrategy.builder().setScanType(getScanType()).setProductExecutorData(data).setConfigSupport(configSupport).setContentProvider(contentProvider).setInstallSetup(installSetup).build()).configure(new NetworkTargetProductServerDataAdapterConfigurationStrategy(configSupport, data.getCurrentNetworkTargetInfo().getTargetType())).setTargetIPs(info.getIPs()).setTargetURIs(info.getURIs()).build();
        /* @formatter:on */
        /* execute PDS by adapter and return product result */
        String xml = pdsAdapter.start(pdsInfraScanConfig, executorContext.getCallback());
        ProductResult currentProductResult = executorContext.getCurrentProductResult();
        currentProductResult.setResult(xml);
        results.add(currentProductResult);
    }
    return results;
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) NetworkTargetProductServerDataAdapterConfigurationStrategy(com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy) ProductExecutorContext(com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext) ArrayList(java.util.ArrayList) URI(java.net.URI) NetworkTargetInfo(com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo) PDSInfraScanConfig(com.mercedesbenz.sechub.adapter.pds.PDSInfraScanConfig) NetworkTargetType(com.mercedesbenz.sechub.domain.scan.NetworkTargetType) SecHubExecutionContext(com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)

Aggregations

SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)24 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)14 Test (org.junit.jupiter.api.Test)10 LinkedList (java.util.LinkedList)8 ProductExecutorContext (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorContext)6 ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)6 InputStream (java.io.InputStream)3 Test (org.junit.Test)3 AdapterException (com.mercedesbenz.sechub.adapter.AdapterException)2 AdapterLogId (com.mercedesbenz.sechub.adapter.AdapterLogId)2 NetworkTargetProductServerDataAdapterConfigurationStrategy (com.mercedesbenz.sechub.domain.scan.NetworkTargetProductServerDataAdapterConfigurationStrategy)2 NetworkTargetInfo (com.mercedesbenz.sechub.domain.scan.NetworkTargetRegistry.NetworkTargetInfo)2 NetworkTargetType (com.mercedesbenz.sechub.domain.scan.NetworkTargetType)2 ProductExecutorCallback (com.mercedesbenz.sechub.domain.scan.product.ProductExecutorCallback)2 ProductExecutorConfig (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfig)2 ProductExecutorConfigSetup (com.mercedesbenz.sechub.domain.scan.product.config.ProductExecutorConfigSetup)2 ScanMockData (com.mercedesbenz.sechub.domain.scan.project.ScanMockData)2 ScanProjectMockDataConfiguration (com.mercedesbenz.sechub.domain.scan.project.ScanProjectMockDataConfiguration)2 UUIDTraceLogID (com.mercedesbenz.sechub.sharedkernel.UUIDTraceLogID)2 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)2