mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-25 22:01:16 +00:00
basic skeleton for the API and queueing
This commit is contained in:
31
MalwareMultiScan.Api/Controllers/DownloadController.cs
Normal file
31
MalwareMultiScan.Api/Controllers/DownloadController.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Threading.Tasks;
|
||||
using MalwareMultiScan.Api.Services;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MalwareMultiScan.Api.Controllers
|
||||
{
|
||||
[Route("download")]
|
||||
public class DownloadController : Controller
|
||||
{
|
||||
private readonly ScanResultsService _scanResultsService;
|
||||
|
||||
public DownloadController(ScanResultsService scanResultsService)
|
||||
{
|
||||
_scanResultsService = scanResultsService;
|
||||
}
|
||||
|
||||
[HttpGet("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
public async Task<IActionResult> Index(string id)
|
||||
{
|
||||
var fileStream = await _scanResultsService.ObtainFile(id);
|
||||
|
||||
if (fileStream == null)
|
||||
return NotFound();
|
||||
|
||||
return File(fileStream, "application/octet-stream");
|
||||
}
|
||||
}
|
||||
}
|
15
MalwareMultiScan.Api/Controllers/QueueController.cs
Normal file
15
MalwareMultiScan.Api/Controllers/QueueController.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MalwareMultiScan.Api.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("queue")]
|
||||
[Produces("application/json")]
|
||||
public class QueueController : Controller
|
||||
{
|
||||
public IActionResult Index()
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
41
MalwareMultiScan.Api/Controllers/ScanBackendsController.cs
Normal file
41
MalwareMultiScan.Api/Controllers/ScanBackendsController.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
31
MalwareMultiScan.Api/Controllers/ScanResultsController.cs
Normal file
31
MalwareMultiScan.Api/Controllers/ScanResultsController.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Threading.Tasks;
|
||||
using MalwareMultiScan.Api.Services;
|
||||
using MalwareMultiScan.Shared.Data.Responses;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace MalwareMultiScan.Api.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("results")]
|
||||
[Produces("application/json")]
|
||||
public class ScanResultsController : Controller
|
||||
{
|
||||
private readonly ScanResultsService _scanResultsService;
|
||||
|
||||
public ScanResultsController(ScanResultsService scanResultsService)
|
||||
{
|
||||
_scanResultsService = scanResultsService;
|
||||
}
|
||||
|
||||
[HttpPost("{id}")]
|
||||
[ProducesResponseType(StatusCodes.Status204NoContent)]
|
||||
public async Task<IActionResult> Index(string id, [FromBody] ResultResponse result)
|
||||
{
|
||||
await _scanResultsService.UpdateScanResultForBackend(
|
||||
id, result.Backend, true, result.Success, result.Threats);
|
||||
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user