2020-10-26 16:20:47 +02:00
|
|
|
using EasyNetQ;
|
2020-10-23 11:11:19 +03:00
|
|
|
using MalwareMultiScan.Api.Services;
|
2020-10-22 22:20:21 +03:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2020-10-26 16:20:47 +02:00
|
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
2020-10-22 22:20:21 +03:00
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-10-26 16:20:47 +02:00
|
|
|
using Microsoft.OpenApi.Models;
|
2020-10-23 11:11:19 +03:00
|
|
|
using MongoDB.Driver;
|
2020-10-22 22:20:21 +03:00
|
|
|
|
|
|
|
namespace MalwareMultiScan.Api
|
|
|
|
{
|
|
|
|
public class Startup
|
|
|
|
{
|
2020-10-23 11:11:19 +03:00
|
|
|
private readonly IConfiguration _configuration;
|
|
|
|
|
2020-10-22 22:20:21 +03:00
|
|
|
public Startup(IConfiguration configuration)
|
|
|
|
{
|
2020-10-23 11:11:19 +03:00
|
|
|
_configuration = configuration;
|
2020-10-22 22:20:21 +03:00
|
|
|
}
|
2020-10-26 17:06:29 +02:00
|
|
|
|
2020-10-22 22:20:21 +03:00
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
{
|
2020-10-26 16:20:47 +02:00
|
|
|
services.AddSingleton(x =>
|
|
|
|
RabbitHutch.CreateBus(_configuration.GetConnectionString("RabbitMQ")));
|
|
|
|
|
2020-10-25 16:11:36 +02:00
|
|
|
services.AddSingleton<ScanBackendService>();
|
2020-10-26 16:20:47 +02:00
|
|
|
services.AddSingleton<ScanResultService>();
|
2020-10-26 17:06:29 +02:00
|
|
|
|
2020-10-23 11:11:19 +03:00
|
|
|
services.AddSingleton(
|
|
|
|
serviceProvider =>
|
|
|
|
{
|
|
|
|
var db = new MongoClient(_configuration.GetConnectionString("Mongo"));
|
|
|
|
|
|
|
|
return db.GetDatabase(
|
|
|
|
_configuration.GetValue<string>("DatabaseName"));
|
|
|
|
});
|
2020-10-26 17:06:29 +02:00
|
|
|
|
2020-10-22 22:20:21 +03:00
|
|
|
services.AddControllers();
|
2020-10-23 11:11:19 +03:00
|
|
|
services.AddHttpClient();
|
2020-10-26 16:20:47 +02:00
|
|
|
|
|
|
|
services.AddSwaggerGen(options =>
|
|
|
|
{
|
|
|
|
options.SwaggerDoc("MalwareMultiScan",
|
|
|
|
new OpenApiInfo
|
|
|
|
{
|
|
|
|
Title = "MalwareMultiScan",
|
|
|
|
Version = "1.0.0"
|
|
|
|
});
|
|
|
|
});
|
2020-10-26 17:06:29 +02:00
|
|
|
|
2020-10-26 16:20:47 +02:00
|
|
|
services.AddHostedService<ReceiverHostedService>();
|
2020-10-22 22:20:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
|
{
|
|
|
|
app.UseRouting();
|
2020-10-26 17:06:29 +02:00
|
|
|
|
2020-10-26 16:20:47 +02:00
|
|
|
var forwardingOptions = new ForwardedHeadersOptions
|
|
|
|
{
|
|
|
|
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
|
|
|
};
|
|
|
|
|
|
|
|
forwardingOptions.KnownNetworks.Clear();
|
|
|
|
forwardingOptions.KnownProxies.Clear();
|
|
|
|
|
|
|
|
app.UseForwardedHeaders(forwardingOptions);
|
|
|
|
|
|
|
|
app.UseEndpoints(endpoints => endpoints.MapControllers());
|
2020-10-26 17:06:29 +02:00
|
|
|
|
2020-10-26 16:20:47 +02:00
|
|
|
app.UseSwagger();
|
2020-10-22 22:20:21 +03:00
|
|
|
|
2020-10-26 16:20:47 +02:00
|
|
|
app.UseSwaggerUI(options =>
|
|
|
|
{
|
|
|
|
options.DocumentTitle = "MalwareMultiScan";
|
2020-10-26 17:06:29 +02:00
|
|
|
|
2020-10-26 16:20:47 +02:00
|
|
|
options.SwaggerEndpoint(
|
|
|
|
$"/swagger/{options.DocumentTitle}/swagger.json", options.DocumentTitle);
|
|
|
|
});
|
2020-10-22 22:20:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|