Search in sources :

Example 16 with JobStorage

use of com.mercedesbenz.sechub.storage.core.JobStorage in project sechub by mercedes-benz.

the class ScanService method cleanupStorage.

/*
     * Cleans storage for current job
     */
private void cleanupStorage(SecHubExecutionContext context) {
    if (context == null) {
        LOG.warn("No context available so no cleanup possible");
        return;
    }
    SecHubConfiguration configuration = context.getConfiguration();
    if (configuration == null) {
        LOG.warn("No configuration available so no cleanup possible");
        return;
    }
    String projectId = configuration.getProjectId();
    UUID jobUUID = context.getSechubJobUUID();
    JobStorage storage = storageService.getJobStorage(projectId, jobUUID);
    try {
        storage.deleteAll();
    } catch (IOException e) {
        LOG.error("Was not able to delete storage for job {}", jobUUID, e);
    }
}
Also used : SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) IOException(java.io.IOException) UUID(java.util.UUID) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage)

Example 17 with JobStorage

use of com.mercedesbenz.sechub.storage.core.JobStorage in project sechub by mercedes-benz.

the class PDSStorageContentProviderFactory method createContentProvider.

public PDSStorageContentProvider createContentProvider(SecHubExecutionContext context, ReuseSecHubStorageInfoProvider reuseSecHubStorageProvider, ScanType scanType) {
    JobStorage storage = null;
    SecHubConfiguration model = context.getConfiguration();
    boolean reuseSecHubStorage = reuseSecHubStorageProvider.isReusingSecHubStorage();
    if (!reuseSecHubStorage) {
        String projectId = model.getProjectId();
        UUID jobUUID = context.getSechubJobUUID();
        storage = storageService.getJobStorage(projectId, jobUUID);
    }
    return new PDSStorageContentProvider(storage, reuseSecHubStorage, scanType, modelSupport, model);
}
Also used : SecHubConfiguration(com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage) UUID(java.util.UUID)

Example 18 with JobStorage

use of com.mercedesbenz.sechub.storage.core.JobStorage in project sechub by mercedes-benz.

the class PDSFileUploadJobService method upload.

@UseCaseUserUploadsJobData(@PDSStep(name = "service call", description = "uploaded file is stored by storage service", number = 2))
public void upload(UUID jobUUID, String fileName, MultipartFile file, String checkSum) {
    notNull(jobUUID, "job uuid may not be null");
    notNull(file, "file may not be null");
    notNull(checkSum, "checkSum may not be null");
    validateFileName(fileName);
    PDSJob job = assertJobFound(jobUUID, repository);
    assertJobIsInState(job, PDSJobStatusState.CREATED);
    /*
         * fetch job storage without path - storage service decides location
         * automatically
         */
    JobStorage storage = storageService.getJobStorage(jobUUID);
    Path tmpFile = null;
    try {
        /* prepare a tmp file for validation */
        try {
            tmpFile = Files.createTempFile("pds_upload_tmp", null);
            file.transferTo(tmpFile);
        } catch (IOException e) {
            LOG.error("Was not able to create temp file of zipped sources!", e);
            throw new IllegalStateException("Was not able to create temp file");
        }
        /* validate */
        if (fileName.toLowerCase().endsWith(".zip")) {
            // we check for ZIP file correctness, so automated unzipping can be done
            // correctly
            assertValidZipFile(tmpFile);
        }
        assertCheckSumCorrect(checkSum, tmpFile);
        /* now store */
        try {
            LOG.info("Upload file {} for job {} to storage", fileName, jobUUID);
            storage.store(fileName, file.getInputStream());
            // we also store checksum
            storage.store(fileName + ".checksum", new StringInputStream(checkSum));
        } catch (IOException e) {
            LOG.error("Was not able to store {} for job {}, reason:", fileName, jobUUID, e.getMessage());
            throw new IllegalArgumentException("Cannot store given file", e);
        }
    } finally {
        if (tmpFile != null && Files.exists(tmpFile)) {
            try {
                Files.delete(tmpFile);
            } catch (IOException e) {
                LOG.error("Was not able delete former temp file for zipped sources! {}", jobUUID, e);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) StringInputStream(com.amazonaws.util.StringInputStream) IOException(java.io.IOException) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage) UseCaseUserUploadsJobData(com.mercedesbenz.sechub.pds.usecase.UseCaseUserUploadsJobData)

Example 19 with JobStorage

use of com.mercedesbenz.sechub.storage.core.JobStorage in project sechub by mercedes-benz.

the class SchedulerUploadService method storeUploadFileAndSha256Checksum.

private void storeUploadFileAndSha256Checksum(String projectId, UUID jobUUID, MultipartFile file, String checkSum, String traceLogID) {
    JobStorage jobStorage = storageService.getJobStorage(projectId, jobUUID);
    try (InputStream inputStream = file.getInputStream()) {
        jobStorage.store(SOURCECODE_ZIP, inputStream);
        // we also store given checksum - so can be reused by security product
        jobStorage.store(SOURCECODE_ZIP_CHECKSUM, new StringInputStream(checkSum));
    } catch (IOException e) {
        LOG.error("Was not able to store zipped sources! {}", traceLogID, e);
        throw new SecHubRuntimeException("Was not able to upload sources");
    }
}
Also used : StringInputStream(com.amazonaws.util.StringInputStream) StringInputStream(com.amazonaws.util.StringInputStream) InputStream(java.io.InputStream) SecHubRuntimeException(com.mercedesbenz.sechub.commons.model.SecHubRuntimeException) IOException(java.io.IOException) JobStorage(com.mercedesbenz.sechub.storage.core.JobStorage)

Aggregations

JobStorage (com.mercedesbenz.sechub.storage.core.JobStorage)19 InputStream (java.io.InputStream)11 StringInputStream (com.amazonaws.util.StringInputStream)8 UUID (java.util.UUID)8 IOException (java.io.IOException)5 AdapterMetaData (com.mercedesbenz.sechub.adapter.AdapterMetaData)3 ProductResult (com.mercedesbenz.sechub.domain.scan.product.ProductResult)3 MetaDataInspection (com.mercedesbenz.sechub.sharedkernel.metadata.MetaDataInspection)3 CheckmarxAdapterConfig (com.mercedesbenz.sechub.adapter.checkmarx.CheckmarxAdapterConfig)2 SecHubRuntimeException (com.mercedesbenz.sechub.commons.model.SecHubRuntimeException)2 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)2 MultiStorageService (com.mercedesbenz.sechub.sharedkernel.storage.MultiStorageService)2 S3Setup (com.mercedesbenz.sechub.storage.core.S3Setup)2 SharedVolumeSetup (com.mercedesbenz.sechub.storage.core.SharedVolumeSetup)2 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 MessageDigest (java.security.MessageDigest)2 FileItemIterator (org.apache.commons.fileupload.FileItemIterator)2 FileItemStream (org.apache.commons.fileupload.FileItemStream)2 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)2