SUPPORT-8836:refactor
This commit is contained in:
parent
4fdc195b91
commit
384a97d629
3 changed files with 7 additions and 44 deletions
|
|
@ -9,7 +9,6 @@ import org.springframework.web.bind.annotation.RequestPart;
|
|||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import ru.micord.av.service.model.ScanResult;
|
||||
import ru.micord.av.service.service.FileScanService;
|
||||
|
||||
/**
|
||||
|
|
@ -32,11 +31,10 @@ public class FileScanController {
|
|||
return ResponseEntity.badRequest().build();
|
||||
}
|
||||
try {
|
||||
ScanResult result = fileScanService.scanFile(file);
|
||||
LOGGER.info("Scan result for file {}: status - {}, verdicts - {}",
|
||||
int result = fileScanService.scanFile(file);
|
||||
LOGGER.info("Scan result for file {}: exitCode - {}",
|
||||
file.getOriginalFilename(),
|
||||
result.status(),
|
||||
String.join(", ", result.verdicts()));
|
||||
result);
|
||||
return ResponseEntity.ok(result);
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
package ru.micord.av.service.model;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Adel Kalimullin
|
||||
*/
|
||||
public record ScanResult(String completed, String created, Integer progress,
|
||||
Map<String, Scan> scan_result, String status, String[] verdicts) {
|
||||
public record Scan(String started, String stopped, Threat[] threats, String verdict) {
|
||||
public static final String VERDICT_CLEAN = "clean";
|
||||
public static final String VERDICT_INFECTED = "infected";
|
||||
|
||||
public record Threat(String name, String object) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -12,7 +12,6 @@ import org.springframework.beans.factory.annotation.Value;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import ru.micord.av.service.exception.AvException;
|
||||
import ru.micord.av.service.model.ScanResult;
|
||||
|
||||
/**
|
||||
* @author Adel Kalimullin
|
||||
|
|
@ -25,7 +24,7 @@ public class FileScanService {
|
|||
@Value("${file.upload.directory}")
|
||||
private String uploadDirectory;
|
||||
|
||||
public ScanResult scanFile(MultipartFile file) {
|
||||
public int scanFile(MultipartFile file) {
|
||||
File tempFile = null;
|
||||
try {
|
||||
tempFile = saveFile(file);
|
||||
|
|
@ -56,32 +55,15 @@ public class FileScanService {
|
|||
return tempFile.toFile();
|
||||
}
|
||||
|
||||
private ScanResult runKeslScan(File file) throws IOException, InterruptedException {
|
||||
private int runKeslScan(File file) throws IOException, InterruptedException {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(KESL_CONTROL, KESL_SCAN,
|
||||
file.getAbsolutePath()
|
||||
);
|
||||
processBuilder.redirectErrorStream(true);
|
||||
Process process = processBuilder.start();
|
||||
int exitCode = process.waitFor();
|
||||
if (exitCode == 0) {
|
||||
return new ScanResult(
|
||||
null,
|
||||
null,
|
||||
100,
|
||||
null,
|
||||
"completed",
|
||||
new String[] {ScanResult.Scan.VERDICT_CLEAN}
|
||||
);
|
||||
}
|
||||
else if (exitCode == 72) {
|
||||
return new ScanResult(
|
||||
null,
|
||||
null,
|
||||
100,
|
||||
null,
|
||||
"completed",
|
||||
new String[] {ScanResult.Scan.VERDICT_INFECTED}
|
||||
);
|
||||
if (exitCode == 0 || exitCode == 72) {
|
||||
return exitCode;
|
||||
}
|
||||
else {
|
||||
throw new AvException("KESL error, exit code: " + exitCode);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue