mirror of
https://github.com/volodymyrsmirnov/MalwareMultiScan.git
synced 2025-08-24 05:22:22 +00:00
43 lines
1.7 KiB
C#
43 lines
1.7 KiB
C#
using System.Diagnostics.CodeAnalysis;
|
|
using System.Net;
|
|
using EasyNetQ;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using MongoDB.Driver;
|
|
using MongoDB.Driver.GridFS;
|
|
|
|
namespace MalwareMultiScan.Api.Extensions
|
|
{
|
|
[ExcludeFromCodeCoverage]
|
|
internal static class ServiceCollectionExtensions
|
|
{
|
|
internal static void AddMongoDb(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
var client = new MongoClient(configuration.GetConnectionString("Mongo"));
|
|
var db = client.GetDatabase(configuration.GetValue<string>("DatabaseName"));
|
|
|
|
services.AddSingleton(client);
|
|
services.AddSingleton(db);
|
|
services.AddSingleton<IGridFSBucket>(new GridFSBucket(db));
|
|
}
|
|
|
|
internal static void AddRabbitMq(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
services.AddSingleton(x =>
|
|
RabbitHutch.CreateBus(configuration.GetConnectionString("RabbitMQ")));
|
|
}
|
|
|
|
internal static void AddDockerForwardedHeadersOptions(this IServiceCollection services)
|
|
{
|
|
services.Configure<ForwardedHeadersOptions>(options =>
|
|
{
|
|
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
|
|
options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("::ffff:10.0.0.0"), 104));
|
|
options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("::ffff:192.168.0.0"), 112));
|
|
options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("::ffff:172.16.0.0"), 108));
|
|
});
|
|
}
|
|
}
|
|
} |