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