@@ -3,6 +3,7 @@ using System.Reflection;
using System.Threading.RateLimiting ;
using Microsoft.AspNetCore.Authentication ;
using Microsoft.AspNetCore.Authentication.OpenIdConnect ;
using Microsoft.AspNetCore.DataProtection ;
using Microsoft.AspNetCore.HttpOverrides ;
using Microsoft.AspNetCore.Mvc.ApplicationParts ;
using Microsoft.Identity.Web ;
@@ -41,12 +42,19 @@ var timeLimit = int.TryParse(configuration["TIME_LIMIT"], out var parsedTimeLimi
#endregion
#region Р а б о т а с п а п к о й д а н н ы х
// с оздать папку data если не существует
// С оздать папку data если не существует
var dataDirectory = Path . Combine ( AppContext . BaseDirectory , "data" ) ;
if ( ! Directory . Exists ( dataDirectory ) ) Directory . CreateDirectory ( dataDirectory ) ;
GlobalConsts . JwtFilePath = Path . Combine ( dataDirectory , "jwt.txt" ) ;
// Создать подкаталог для плагинов
var pluginsPath = Path . Combine ( dataDirectory , "Plugins" ) ;
if ( ! Directory . Exists ( pluginsPath ) ) Directory . CreateDirectory ( pluginsPath ) ;
// Создать подкаталог для ключей Data Protection
var dataProtectionKeysDirectory = Path . Combine ( dataDirectory , "keys" ) ;
if ( ! Directory . Exists ( dataProtectionKeysDirectory ) ) Directory . CreateDirectory ( dataProtectionKeysDirectory ) ;
#endregion
#region Р а б о т а с л о г и р о в а н и е м
@@ -79,7 +87,7 @@ builder.Services.AddHttpClient("modeus", client =>
client . BaseAddress = new Uri ( configuration [ "MODEUS_URL" ] ! ) ;
} ) ;
builder . Services . AddSingleton < ModeusHttpClient > ( ) ;
builder . Services . AddScoped < ModeusService > ( ) ;
builder . Services . AddSingleton < ModeusService > ( ) ;
builder . Services . AddHttpClient ( "authClient" ) ;
builder . Services . AddAuthentication ( )
@@ -229,6 +237,10 @@ builder.Services.Configure<ForwardedHeadersOptions>(options =>
options . KnownNetworks . Add ( new IPNetwork ( IPAddress . Parse ( "172.16.0.0" ) , 12 ) ) ; // 172.16.x.x - 172.31.x.x
} ) ;
// Хранение ключей Data Protection в папке data
builder . Services . AddDataProtection ( )
. PersistKeysToFileSystem ( new DirectoryInfo ( dataProtectionKeysDirectory ) ) ;
var app = builder . Build ( ) ;
var logger = app . Services . GetRequiredService < ILogger < Program > > ( ) ;