2020-10-29 12:17:09 +02:00
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2020-10-26 21:24:40 +02:00
|
|
|
using System.Net;
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using MongoDB.Driver;
|
2020-10-29 12:17:09 +02:00
|
|
|
using MongoDB.Driver.GridFS;
|
2020-10-26 21:24:40 +02:00
|
|
|
|
|
|
|
namespace MalwareMultiScan.Api.Extensions
|
|
|
|
{
|
2020-10-29 12:17:09 +02:00
|
|
|
[ExcludeFromCodeCoverage]
|
2020-10-26 21:24:40 +02:00
|
|
|
internal static class ServiceCollectionExtensions
|
|
|
|
{
|
2020-10-29 12:17:09 +02:00
|
|
|
internal static void AddMongoDb(this IServiceCollection services, IConfiguration configuration)
|
2020-10-26 21:24:40 +02:00
|
|
|
{
|
2020-11-01 22:25:48 +02:00
|
|
|
var client = new MongoClient(configuration.GetValue<string>("MONGO_ADDRESS"));
|
|
|
|
var db = client.GetDatabase(configuration.GetValue<string>("MONGO_DATABASE"));
|
2020-10-26 21:24:40 +02:00
|
|
|
|
2020-10-29 12:17:09 +02:00
|
|
|
services.AddSingleton(client);
|
|
|
|
services.AddSingleton(db);
|
|
|
|
services.AddSingleton<IGridFSBucket>(new GridFSBucket(db));
|
2020-10-26 21:24:40 +02:00
|
|
|
}
|
|
|
|
|
2020-10-29 12:17:09 +02:00
|
|
|
internal static void AddDockerForwardedHeadersOptions(this IServiceCollection services)
|
2020-10-26 21:24:40 +02:00
|
|
|
{
|
|
|
|
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));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|