mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-25 22:01:16 +00:00
change the communication protocol to RMQ
This commit is contained in:
@@ -8,11 +8,11 @@ namespace MalwareMultiScan.Api.Controllers
|
||||
[Route("download")]
|
||||
public class DownloadController : Controller
|
||||
{
|
||||
private readonly ScanResultsService _scanResultsService;
|
||||
private readonly ScanResultService _scanResultService;
|
||||
|
||||
public DownloadController(ScanResultsService scanResultsService)
|
||||
public DownloadController(ScanResultService scanResultService)
|
||||
{
|
||||
_scanResultsService = scanResultsService;
|
||||
_scanResultService = scanResultService;
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
@@ -20,7 +20,7 @@ namespace MalwareMultiScan.Api.Controllers
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> Index(string id)
|
||||
{
|
||||
var fileStream = await _scanResultsService.ObtainFile(id);
|
||||
var fileStream = await _scanResultService.ObtainFile(id);
|
||||
|
||||
if (fileStream == null)
|
||||
return NotFound();
|
||||
|
@@ -1,3 +1,10 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using MalwareMultiScan.Api.Services;
|
||||
using MalwareMultiScan.Shared.Attributes;
|
||||
using MalwareMultiScan.Shared.Data.Responses;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MalwareMultiScan.Api.Controllers
|
||||
@@ -7,9 +14,45 @@ namespace MalwareMultiScan.Api.Controllers
|
||||
[Produces("application/json")]
|
||||
public class QueueController : Controller
|
||||
{
|
||||
public IActionResult Index()
|
||||
private readonly ScanResultService _scanResultService;
|
||||
|
||||
public QueueController( ScanResultService scanResultService)
|
||||
{
|
||||
return Ok();
|
||||
_scanResultService = scanResultService;
|
||||
}
|
||||
|
||||
[HttpPost("file")]
|
||||
[ProducesResponseType(typeof(ResultResponse), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> ScanFile([FromForm] IFormFile file)
|
||||
{
|
||||
var result = await _scanResultService.CreateScanResult();
|
||||
|
||||
string storedFileId;
|
||||
|
||||
await using (var uploadFileStream = file.OpenReadStream())
|
||||
storedFileId = await _scanResultService.StoreFile(file.Name, uploadFileStream);
|
||||
|
||||
await _scanResultService.QueueUrlScan(result, Url.Action("Index", "Download", new {id = storedFileId},
|
||||
Request.Scheme, Request.Host.Value));
|
||||
|
||||
return Created(Url.Action("Index", "ScanResults", new {id = result.Id},
|
||||
Request.Scheme, Request.Host.Value), result);
|
||||
}
|
||||
|
||||
[HttpPost("url")]
|
||||
[ProducesResponseType(typeof(ResultResponse), StatusCodes.Status201Created)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
public async Task<IActionResult> ScanUrl([FromForm] [UrlValidation] Uri url)
|
||||
{
|
||||
var result = await _scanResultService.CreateScanResult();
|
||||
|
||||
var resultUrl = Url.Action("Index", "ScanResults", new {id = result.Id},
|
||||
Request.Scheme, Request.Host.Value);
|
||||
|
||||
await _scanResultService.QueueUrlScan(result, url.ToString());
|
||||
|
||||
return Created(resultUrl, result);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,41 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using MalwareMultiScan.Api.Data.Configuration;
|
||||
using MalwareMultiScan.Api.Data.Response;
|
||||
using MalwareMultiScan.Api.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MalwareMultiScan.Api.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("backends")]
|
||||
[Produces("application/json")]
|
||||
public class ScanBackendsController : Controller
|
||||
{
|
||||
private readonly ScanBackendService _scanBackendService;
|
||||
|
||||
public ScanBackendsController(ScanBackendService scanBackendService)
|
||||
{
|
||||
_scanBackendService = scanBackendService;
|
||||
}
|
||||
|
||||
private async Task<ScanBackendResponse> GetScanBackendResponse(ScanBackend backend)
|
||||
{
|
||||
return new ScanBackendResponse
|
||||
{
|
||||
Id = backend.Id,
|
||||
Name = backend.Name,
|
||||
Online = await _scanBackendService.Ping(backend)
|
||||
};
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[ProducesResponseType(typeof(ScanBackendResponse[]), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> Index()
|
||||
{
|
||||
return Ok(await Task.WhenAll(
|
||||
_scanBackendService.List.Select(GetScanBackendResponse).ToArray()));
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using MalwareMultiScan.Api.Data.Models;
|
||||
using MalwareMultiScan.Api.Services;
|
||||
using MalwareMultiScan.Shared.Data.Responses;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -11,21 +12,23 @@ namespace MalwareMultiScan.Api.Controllers
|
||||
[Produces("application/json")]
|
||||
public class ScanResultsController : Controller
|
||||
{
|
||||
private readonly ScanResultsService _scanResultsService;
|
||||
private readonly ScanResultService _scanResultService;
|
||||
|
||||
public ScanResultsController(ScanResultsService scanResultsService)
|
||||
public ScanResultsController(ScanResultService scanResultService)
|
||||
{
|
||||
_scanResultsService = scanResultsService;
|
||||
_scanResultService = scanResultService;
|
||||
}
|
||||
|
||||
[HttpPost("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public async Task<IActionResult> Index(string id, [FromBody] ResultResponse result)
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType(typeof(ScanResult), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> Index(string id)
|
||||
{
|
||||
await _scanResultsService.UpdateScanResultForBackend(
|
||||
id, result.Backend, true, result.Success, result.Threats);
|
||||
|
||||
return NoContent();
|
||||
var scanResult = await _scanResultService.GetScanResult(id);
|
||||
|
||||
if (scanResult == null)
|
||||
return NotFound();
|
||||
|
||||
return Ok(scanResult);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user