mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-25 14:01:13 +00:00
finished unit tests and docstrings
This commit is contained in:
@@ -9,6 +9,7 @@ using MongoDB.Driver.GridFS;
|
||||
|
||||
namespace MalwareMultiScan.Api.Services.Implementations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public class ScanResultService : IScanResultService
|
||||
{
|
||||
private const string CollectionName = "ScanResults";
|
||||
@@ -16,15 +17,22 @@ namespace MalwareMultiScan.Api.Services.Implementations
|
||||
private readonly IGridFSBucket _bucket;
|
||||
private readonly IMongoCollection<ScanResult> _collection;
|
||||
private readonly IScanBackendService _scanBackendService;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Initialize scan result service.
|
||||
/// </summary>
|
||||
/// <param name="db">Mongo database.</param>
|
||||
/// <param name="bucket">GridFS bucket.</param>
|
||||
/// <param name="scanBackendService">Scan backend service.</param>
|
||||
public ScanResultService(IMongoDatabase db, IGridFSBucket bucket, IScanBackendService scanBackendService)
|
||||
{
|
||||
_bucket = bucket;
|
||||
_scanBackendService = scanBackendService;
|
||||
|
||||
|
||||
_collection = db.GetCollection<ScanResult>(CollectionName);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<ScanResult> CreateScanResult()
|
||||
{
|
||||
var scanResult = new ScanResult
|
||||
@@ -38,7 +46,8 @@ namespace MalwareMultiScan.Api.Services.Implementations
|
||||
|
||||
return scanResult;
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<ScanResult> GetScanResult(string id)
|
||||
{
|
||||
var result = await _collection.FindAsync(
|
||||
@@ -46,7 +55,8 @@ namespace MalwareMultiScan.Api.Services.Implementations
|
||||
|
||||
return await result.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task UpdateScanResultForBackend(string resultId, string backendId, long duration,
|
||||
bool completed = false, bool succeeded = false, string[] threats = null)
|
||||
{
|
||||
@@ -60,13 +70,15 @@ namespace MalwareMultiScan.Api.Services.Implementations
|
||||
Threats = threats ?? new string[] { }
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task QueueUrlScan(ScanResult result, string fileUrl)
|
||||
{
|
||||
foreach (var backend in _scanBackendService.List.Where(b => b.Enabled))
|
||||
await _scanBackendService.QueueUrlScan(result, backend, fileUrl);
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<string> StoreFile(string fileName, Stream fileStream)
|
||||
{
|
||||
var objectId = await _bucket.UploadFromStreamAsync(
|
||||
@@ -74,7 +86,8 @@ namespace MalwareMultiScan.Api.Services.Implementations
|
||||
|
||||
return objectId.ToString();
|
||||
}
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public async Task<Stream> ObtainFile(string id)
|
||||
{
|
||||
if (!ObjectId.TryParse(id, out var objectId))
|
||||
|
Reference in New Issue
Block a user