mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-23 21:12:22 +00:00
code cleanup
This commit is contained in:
parent
b4c5c1a507
commit
cfcfe92784
@ -57,7 +57,7 @@ namespace MalwareMultiScan.Api.Services
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
_backgroundJobClient.Create<IScanResultJob>(
|
_backgroundJobClient.Create<IScanResultJob>(
|
||||||
x => x.Notify(scanResult.CallbackUrl, resultId, backendId, result),
|
x => x.Notify(scanResult.CallbackUrl, resultId, backendId, result),
|
||||||
new EnqueuedState("default"));
|
new EnqueuedState("default"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +82,7 @@ namespace MalwareMultiScan.Api.Services
|
|||||||
cancellationTokenSource.Token);
|
cancellationTokenSource.Token);
|
||||||
|
|
||||||
response.EnsureSuccessStatusCode();
|
response.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
_logger.LogInformation($"Sent POST to callback URL {uri}");
|
_logger.LogInformation($"Sent POST to callback URL {uri}");
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
|
@ -29,10 +29,10 @@ namespace MalwareMultiScan.Api
|
|||||||
services.AddConsul(_configuration);
|
services.AddConsul(_configuration);
|
||||||
services.AddMongoDb(_configuration);
|
services.AddMongoDb(_configuration);
|
||||||
services.AddHangfire(_configuration);
|
services.AddHangfire(_configuration);
|
||||||
|
|
||||||
services.AddSingleton<IScanResultService, ScanResultService>();
|
services.AddSingleton<IScanResultService, ScanResultService>();
|
||||||
services.AddSingleton<IScanResultJob, ScanResultJob>();
|
services.AddSingleton<IScanResultJob, ScanResultJob>();
|
||||||
|
|
||||||
services.AddControllers();
|
services.AddControllers();
|
||||||
services.AddHttpClient();
|
services.AddHttpClient();
|
||||||
}
|
}
|
||||||
@ -41,9 +41,9 @@ namespace MalwareMultiScan.Api
|
|||||||
{
|
{
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
app.UseEndpoints(endpoints => endpoints.MapControllers());
|
app.UseEndpoints(endpoints => endpoints.MapControllers());
|
||||||
|
|
||||||
app.UseForwardedHeaders();
|
app.UseForwardedHeaders();
|
||||||
|
|
||||||
if (hostEnvironment.IsDevelopment())
|
if (hostEnvironment.IsDevelopment())
|
||||||
app.UseHangfireDashboard();
|
app.UseHangfireDashboard();
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ namespace MalwareMultiScan.Scanner
|
|||||||
services.AddConsul(context.Configuration);
|
services.AddConsul(context.Configuration);
|
||||||
services.AddScanBackend(context.Configuration);
|
services.AddScanBackend(context.Configuration);
|
||||||
|
|
||||||
services.AddHangfire(context.Configuration,
|
services.AddHangfire(context.Configuration,
|
||||||
context.Configuration.GetValue<string>("BACKEND_ID"));
|
context.Configuration.GetValue<string>("BACKEND_ID"));
|
||||||
|
|
||||||
services.AddSingleton<IProcessRunner, ProcessRunner>();
|
services.AddSingleton<IProcessRunner, ProcessRunner>();
|
||||||
|
@ -19,7 +19,7 @@ namespace MalwareMultiScan.Scanner.Services
|
|||||||
|
|
||||||
private readonly IConsulClient _consulClient;
|
private readonly IConsulClient _consulClient;
|
||||||
private readonly AgentServiceRegistration _registration;
|
private readonly AgentServiceRegistration _registration;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize consul hosted service.
|
/// Initialize consul hosted service.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -18,8 +18,8 @@ namespace MalwareMultiScan.Scanner.Services
|
|||||||
{
|
{
|
||||||
private readonly IScanBackend _backend;
|
private readonly IScanBackend _backend;
|
||||||
private readonly IConfiguration _configuration;
|
private readonly IConfiguration _configuration;
|
||||||
private readonly ILogger<ScanBackgroundJob> _logger;
|
|
||||||
private readonly IBackgroundJobClient _jobClient;
|
private readonly IBackgroundJobClient _jobClient;
|
||||||
|
private readonly ILogger<ScanBackgroundJob> _logger;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initialize scan background job.
|
/// Initialize scan background job.
|
||||||
@ -90,7 +90,7 @@ namespace MalwareMultiScan.Scanner.Services
|
|||||||
$"Sending scan results with status {result.Status}");
|
$"Sending scan results with status {result.Status}");
|
||||||
|
|
||||||
_jobClient.Create<IScanResultJob>(
|
_jobClient.Create<IScanResultJob>(
|
||||||
x => x.Report(message.Id, _backend.Id, result),
|
x => x.Report(message.Id, _backend.Id, result),
|
||||||
new EnqueuedState("default"));
|
new EnqueuedState("default"));
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
|
@ -9,12 +9,12 @@ namespace MalwareMultiScan.Shared.Enums
|
|||||||
/// Scan is queued.
|
/// Scan is queued.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Queued,
|
Queued,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Scan succeeded.
|
/// Scan succeeded.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Succeeded,
|
Succeeded,
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Scan failed.
|
/// Scan failed.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -26,30 +26,30 @@ namespace MalwareMultiScan.Shared.Extensions
|
|||||||
config.WaitTime = TimeSpan.FromSeconds(120);
|
config.WaitTime = TimeSpan.FromSeconds(120);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add Hangfire with Redis storage.
|
/// Add Hangfire with Redis storage.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="services">Service collection.</param>
|
/// <param name="services">Service collection.</param>
|
||||||
/// <param name="configuration">Configuration.</param>
|
/// <param name="configuration">Configuration.</param>
|
||||||
/// <param name="queues">Queue names.</param>
|
/// <param name="queues">Queue names.</param>
|
||||||
public static void AddHangfire(this IServiceCollection services,
|
public static void AddHangfire(this IServiceCollection services,
|
||||||
IConfiguration configuration, params string[] queues)
|
IConfiguration configuration, params string[] queues)
|
||||||
{
|
{
|
||||||
if (queues.Length == 0)
|
if (queues.Length == 0)
|
||||||
queues = new[] {"default"};
|
queues = new[] {"default"};
|
||||||
|
|
||||||
services.AddHangfire(options =>
|
services.AddHangfire(options =>
|
||||||
options.UseRedisStorage(configuration.GetValue<string>("REDIS_ADDRESS")));
|
options.UseRedisStorage(configuration.GetValue<string>("REDIS_ADDRESS")));
|
||||||
|
|
||||||
services.AddHangfireServer(options =>
|
services.AddHangfireServer(options =>
|
||||||
{
|
{
|
||||||
options.Queues = queues;
|
options.Queues = queues;
|
||||||
|
|
||||||
options.ServerTimeout = TimeSpan.FromSeconds(30);
|
options.ServerTimeout = TimeSpan.FromSeconds(30);
|
||||||
options.HeartbeatInterval = TimeSpan.FromSeconds(5);
|
options.HeartbeatInterval = TimeSpan.FromSeconds(5);
|
||||||
options.ServerCheckInterval = TimeSpan.FromSeconds(15);
|
options.ServerCheckInterval = TimeSpan.FromSeconds(15);
|
||||||
|
|
||||||
var workerCount = configuration.GetValue<int>("WORKER_COUNT");
|
var workerCount = configuration.GetValue<int>("WORKER_COUNT");
|
||||||
|
|
||||||
if (workerCount > 0)
|
if (workerCount > 0)
|
||||||
|
@ -11,7 +11,7 @@ namespace MalwareMultiScan.Shared.Message
|
|||||||
/// Scan result id.
|
/// Scan result id.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Id { get; set; }
|
public string Id { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Scan file URL.
|
/// Scan file URL.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -18,7 +18,7 @@ namespace MalwareMultiScan.Shared.Services.Interfaces
|
|||||||
/// <param name="result">Scan result.</param>
|
/// <param name="result">Scan result.</param>
|
||||||
[AutomaticRetry(Attempts = 0, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
|
[AutomaticRetry(Attempts = 0, OnAttemptsExceeded = AttemptsExceededAction.Delete)]
|
||||||
Task Report(string resultId, string backendId, ScanResultMessage result);
|
Task Report(string resultId, string backendId, ScanResultMessage result);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Notify remote URL on scan result.
|
/// Notify remote URL on scan result.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -28,10 +28,10 @@ namespace MalwareMultiScan.Tests.Api
|
|||||||
var connection = new MongoClient(_mongoDbRunner.ConnectionString);
|
var connection = new MongoClient(_mongoDbRunner.ConnectionString);
|
||||||
var database = connection.GetDatabase("Test");
|
var database = connection.GetDatabase("Test");
|
||||||
var gridFsBucket = new GridFSBucket(database);
|
var gridFsBucket = new GridFSBucket(database);
|
||||||
|
|
||||||
_resultService = new ScanResultService(
|
_resultService = new ScanResultService(
|
||||||
database, gridFsBucket,
|
database, gridFsBucket,
|
||||||
Mock.Of<IConsulClient>(),
|
Mock.Of<IConsulClient>(),
|
||||||
Mock.Of<IBackgroundJobClient>());
|
Mock.Of<IBackgroundJobClient>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ namespace MalwareMultiScan.Tests.Api
|
|||||||
{
|
{
|
||||||
Duration = 100,
|
Duration = 100,
|
||||||
Status = ScanResultStatus.Succeeded,
|
Status = ScanResultStatus.Succeeded,
|
||||||
Threats = new []{"Test"}
|
Threats = new[] {"Test"}
|
||||||
});
|
});
|
||||||
|
|
||||||
result = await _resultService.GetScanResult(result.Id);
|
result = await _resultService.GetScanResult(result.Id);
|
||||||
|
@ -80,9 +80,9 @@ I.e. when you define `callbackUrl=http://localhost:1234/scan-results`, the POST
|
|||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"Status":1,
|
"Status": 1,
|
||||||
"Duration":5,
|
"Duration": 5,
|
||||||
"Threats":["Malware.Dummy.Result"]
|
"Threats": ["Malware.Dummy.Result"]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -25,8 +25,6 @@ services:
|
|||||||
restart: on-failure
|
restart: on-failure
|
||||||
ports:
|
ports:
|
||||||
- "8888:8888"
|
- "8888:8888"
|
||||||
expose:
|
|
||||||
- "8888"
|
|
||||||
depends_on:
|
depends_on:
|
||||||
- api
|
- api
|
||||||
environment:
|
environment:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user