Search in sources :

Example 1 with SecHubRuntimeException

use of com.mercedesbenz.sechub.commons.model.SecHubRuntimeException in project sechub by mercedes-benz.

the class SchedulerRestartJobService method sendPurgeJobResultsSynchronousRequest.

@IsSendingSyncMessage(MessageID.REQUEST_PURGE_JOB_RESULTS)
private void sendPurgeJobResultsSynchronousRequest(ScheduleSecHubJob secHubJob) {
    DomainMessage request = DomainMessageFactory.createEmptyRequest(MessageID.REQUEST_PURGE_JOB_RESULTS);
    request.set(MessageDataKeys.SECHUB_UUID, secHubJob.getUUID());
    request.set(MessageDataKeys.ENVIRONMENT_BASE_URL, sechubEnvironment.getServerBaseUrl());
    DomainMessageSynchronousResult result = eventBus.sendSynchron(request);
    if (result.hasFailed()) {
        throw new SecHubRuntimeException("Purge failed!");
    }
}
Also used : DomainMessageSynchronousResult(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult) SecHubRuntimeException(com.mercedesbenz.sechub.commons.model.SecHubRuntimeException) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) IsSendingSyncMessage(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessage)

Example 2 with SecHubRuntimeException

use of com.mercedesbenz.sechub.commons.model.SecHubRuntimeException in project sechub by mercedes-benz.

the class SecHubFileStructureDataProviderBuilder method addAllUsages.

private void addAllUsages(MutableSecHubFileStructureDataProvider data, Optional<? extends SecHubDataConfigurationUsageByName> scanDefinitionObject, boolean mustHave) {
    if (!scanDefinitionObject.isPresent()) {
        if (mustHave) {
            new IllegalStateException("For scanType:" + scanType + " the configuration entry is missing.");
        }
        return;
    }
    SecHubDataConfigurationUsageByName usageByName = scanDefinitionObject.get();
    Set<String> names = usageByName.getNamesOfUsedDataConfigurationObjects();
    if (names.isEmpty()) {
        if (mustHave) {
            new SecHubRuntimeException("Confgiguration file problem. For scanType:" + scanType + " at least one data configuration must be referenced");
        }
    }
    data.addAcceptedReferenceNames(names);
}
Also used : SecHubRuntimeException(com.mercedesbenz.sechub.commons.model.SecHubRuntimeException) SecHubDataConfigurationUsageByName(com.mercedesbenz.sechub.commons.model.SecHubDataConfigurationUsageByName)

Example 3 with SecHubRuntimeException

use of com.mercedesbenz.sechub.commons.model.SecHubRuntimeException in project sechub by mercedes-benz.

the class DefaultExecutorConfigSupport method getNamePatternIdProvider.

/**
 * Resolves a name pattern provider for given id
 *
 * @param id
 * @param failWhenNotConfigured when <code>false</code> missing name provider
 *                              will be replaced by fallback implementation
 *                              returning always null (nothing configured)
 * @return provider never <code>null</code>
 * @throws SecHubRuntimeException when name pattern provider cannot be resolved
 */
public NamePatternIdProvider getNamePatternIdProvider(String id, boolean failWhenNotConfigured) {
    NamePatternIdProvider provider = namePatternIdProviders.get(id);
    if (provider != null) {
        return provider;
    }
    String parameterValue = getParameter(id);
    if (parameterValue == null) {
        if (failWhenNotConfigured) {
            throw new SecHubRuntimeException("No parameter found for necessary mapping key:" + id);
        } else {
            return FALLBACK_NOT_FOUND_PROVIDER;
        }
    }
    NamePatternIdProvider newProvider = providerFactory.createProvider(id, parameterValue);
    namePatternIdProviders.put(id, newProvider);
    LOG.debug("Created NamePatternIdProvider:{}", newProvider.getProviderId());
    return newProvider;
}
Also used : SecHubRuntimeException(com.mercedesbenz.sechub.commons.model.SecHubRuntimeException) NamePatternIdProvider(com.mercedesbenz.sechub.domain.scan.config.NamePatternIdProvider)

Example 4 with SecHubRuntimeException

use of com.mercedesbenz.sechub.commons.model.SecHubRuntimeException 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 5 with SecHubRuntimeException

use of com.mercedesbenz.sechub.commons.model.SecHubRuntimeException in project sechub by mercedes-benz.

the class DownloadSpdxScanReportService method getScanSpdxJsonReport.

public String getScanSpdxJsonReport(String projectId, UUID jobUUID) {
    /* validate */
    assertion.assertIsValidProjectId(projectId);
    assertion.assertIsValidJobUUID(jobUUID);
    scanAssertService.assertUserHasAccessToProject(projectId);
    scanAssertService.assertProjectAllowsReadAccess(projectId);
    /* audit */
    auditLogService.log("starts download of SPDX Json report for job: {}", jobUUID);
    List<ProductResult> productResults = productResultRepository.findAllProductResults(jobUUID, ProductIdentifier.SERECO);
    if (productResults.size() != 1) {
        throw new SecHubRuntimeException("Did not found exactly one SERECO product result. Instead, " + productResults.size() + " product results were found.");
    }
    ProductResult productResult = productResults.iterator().next();
    String spdxJson = spdxJsonResolver.resolveSpdxJson(productResult);
    if (spdxJson == null) {
        throw new NotFoundException("There was no JSON SPDX report available for job: " + jobUUID);
    }
    return spdxJson;
}
Also used : ProductResult(com.mercedesbenz.sechub.domain.scan.product.ProductResult) SecHubRuntimeException(com.mercedesbenz.sechub.commons.model.SecHubRuntimeException) NotFoundException(com.mercedesbenz.sechub.sharedkernel.error.NotFoundException)

Aggregations

SecHubRuntimeException (com.mercedesbenz.sechub.commons.model.SecHubRuntimeException)8 IOException (java.io.IOException)4 StringInputStream (com.amazonaws.util.StringInputStream)2 JobStorage (com.mercedesbenz.sechub.storage.core.JobStorage)2 InputStream (java.io.InputStream)2 SecHubDataConfigurationUsageByName (com.mercedesbenz.sechub.commons.model.SecHubDataConfigurationUsageByName)1 NamePatternIdProvider (com.mercedesbenz.sechub.domain.scan.config.NamePatternIdProvider)1 ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)1 NotFoundException (com.mercedesbenz.sechub.sharedkernel.error.NotFoundException)1 SecHubExecutionContext (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionContext)1 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)1 DomainMessageSynchronousResult (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult)1 IsSendingSyncMessage (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessage)1 UUID (java.util.UUID)1