mirror of
https://github.com/Caraxi/mare.server.git
synced 2025-12-12 16:57:22 +01:00
some refactoring
This commit is contained in:
parent
880676de09
commit
dc33858626
48 changed files with 448 additions and 112 deletions
|
|
@ -1,3 +1,3 @@
|
||||||
namespace MareSynchronosServer.Authentication;
|
namespace MareSynchronosAuthService.Authentication;
|
||||||
|
|
||||||
public record SecretKeyAuthReply(bool Success, string Uid, string PrimaryUid, string Alias, bool TempBan, bool Permaban);
|
public record SecretKeyAuthReply(bool Success, string Uid, string PrimaryUid, string Alias, bool TempBan, bool Permaban);
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace MareSynchronosServer.Authentication;
|
namespace MareSynchronosAuthService.Authentication;
|
||||||
|
|
||||||
internal record SecretKeyFailedAuthorization
|
internal record SecretKeyFailedAuthorization
|
||||||
{
|
{
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
using MareSynchronos.API.Routes;
|
using MareSynchronos.API.Routes;
|
||||||
using MareSynchronosServer.Authentication;
|
using MareSynchronosAuthService.Services;
|
||||||
using MareSynchronosServer.Services;
|
|
||||||
using MareSynchronosShared;
|
using MareSynchronosShared;
|
||||||
using MareSynchronosShared.Data;
|
using MareSynchronosShared.Data;
|
||||||
using MareSynchronosShared.Models;
|
using MareSynchronosShared.Models;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
@ -16,7 +16,7 @@ using System.IdentityModel.Tokens.Jwt;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace MareSynchronosServer.Controllers;
|
namespace MareSynchronosAuthService.Controllers;
|
||||||
|
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[Route(MareAuth.Auth)]
|
[Route(MareAuth.Auth)]
|
||||||
|
|
@ -24,7 +24,7 @@ public class JwtController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger<JwtController> _logger;
|
private readonly ILogger<JwtController> _logger;
|
||||||
private readonly IHttpContextAccessor _accessor;
|
private readonly IHttpContextAccessor _accessor;
|
||||||
private readonly IConfigurationService<MareConfigurationAuthBase> _configuration;
|
private readonly IConfigurationService<AuthServiceConfiguration> _configuration;
|
||||||
private readonly MareDbContext _mareDbContext;
|
private readonly MareDbContext _mareDbContext;
|
||||||
private readonly IRedisDatabase _redis;
|
private readonly IRedisDatabase _redis;
|
||||||
private readonly GeoIPService _geoIPProvider;
|
private readonly GeoIPService _geoIPProvider;
|
||||||
|
|
@ -33,7 +33,7 @@ public class JwtController : Controller
|
||||||
public JwtController(ILogger<JwtController> logger,
|
public JwtController(ILogger<JwtController> logger,
|
||||||
IHttpContextAccessor accessor, MareDbContext mareDbContext,
|
IHttpContextAccessor accessor, MareDbContext mareDbContext,
|
||||||
SecretKeyAuthenticatorService secretKeyAuthenticatorService,
|
SecretKeyAuthenticatorService secretKeyAuthenticatorService,
|
||||||
IConfigurationService<MareConfigurationAuthBase> configuration,
|
IConfigurationService<AuthServiceConfiguration> configuration,
|
||||||
IRedisDatabase redisDb, GeoIPService geoIPProvider)
|
IRedisDatabase redisDb, GeoIPService geoIPProvider)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
@ -138,7 +138,7 @@ public class JwtController : Controller
|
||||||
|
|
||||||
private JwtSecurityToken CreateJwt(IEnumerable<Claim> authClaims)
|
private JwtSecurityToken CreateJwt(IEnumerable<Claim> authClaims)
|
||||||
{
|
{
|
||||||
var authSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_configuration.GetValue<string>(nameof(MareConfigurationAuthBase.Jwt))));
|
var authSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(_configuration.GetValue<string>(nameof(MareConfigurationBase.Jwt))));
|
||||||
|
|
||||||
var token = new SecurityTokenDescriptor()
|
var token = new SecurityTokenDescriptor()
|
||||||
{
|
{
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MaxMind.GeoIP2" Version="5.2.0" />
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="8.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\MareSynchronosShared\MareSynchronosShared.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
41
MareSynchronosServer/MareSynchronosAuthService/Program.cs
Normal file
41
MareSynchronosServer/MareSynchronosAuthService/Program.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
namespace MareSynchronosAuthService;
|
||||||
|
|
||||||
|
public class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
var hostBuilder = CreateHostBuilder(args);
|
||||||
|
using var host = hostBuilder.Build();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
host.Run();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IHostBuilder CreateHostBuilder(string[] args)
|
||||||
|
{
|
||||||
|
using var loggerFactory = LoggerFactory.Create(builder =>
|
||||||
|
{
|
||||||
|
builder.ClearProviders();
|
||||||
|
builder.AddConsole();
|
||||||
|
});
|
||||||
|
var logger = loggerFactory.CreateLogger<Startup>();
|
||||||
|
return Host.CreateDefaultBuilder(args)
|
||||||
|
.UseSystemd()
|
||||||
|
.UseConsoleLifetime()
|
||||||
|
.ConfigureWebHostDefaults(webBuilder =>
|
||||||
|
{
|
||||||
|
webBuilder.UseContentRoot(AppContext.BaseDirectory);
|
||||||
|
webBuilder.ConfigureLogging((ctx, builder) =>
|
||||||
|
{
|
||||||
|
builder.AddConfiguration(ctx.Configuration.GetSection("Logging"));
|
||||||
|
builder.AddFile(o => o.RootPath = AppContext.BaseDirectory);
|
||||||
|
});
|
||||||
|
webBuilder.UseStartup(ctx => new Startup(ctx.Configuration, logger));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"$schema": "http://json.schemastore.org/launchsettings.json",
|
||||||
|
"iisSettings": {
|
||||||
|
"windowsAuthentication": false,
|
||||||
|
"anonymousAuthentication": true,
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:37726",
|
||||||
|
"sslPort": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"profiles": {
|
||||||
|
"http": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"launchBrowser": true,
|
||||||
|
"applicationUrl": "http://localhost:5056",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"IIS Express": {
|
||||||
|
"commandName": "IISExpress",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
using MareSynchronosShared;
|
using MareSynchronosShared;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using MaxMind.GeoIP2;
|
using MaxMind.GeoIP2;
|
||||||
|
|
||||||
namespace MareSynchronosServer.Services;
|
namespace MareSynchronosAuthService.Services;
|
||||||
|
|
||||||
public class GeoIPService : IHostedService
|
public class GeoIPService : IHostedService
|
||||||
{
|
{
|
||||||
private readonly ILogger<GeoIPService> _logger;
|
private readonly ILogger<GeoIPService> _logger;
|
||||||
private readonly IConfigurationService<ServerConfiguration> _mareConfiguration;
|
private readonly IConfigurationService<AuthServiceConfiguration> _mareConfiguration;
|
||||||
private bool _useGeoIP = false;
|
private bool _useGeoIP = false;
|
||||||
private string _cityFile = string.Empty;
|
private string _cityFile = string.Empty;
|
||||||
private DatabaseReader? _dbReader;
|
private DatabaseReader? _dbReader;
|
||||||
|
|
@ -17,7 +17,7 @@ public class GeoIPService : IHostedService
|
||||||
private bool _processingReload = false;
|
private bool _processingReload = false;
|
||||||
|
|
||||||
public GeoIPService(ILogger<GeoIPService> logger,
|
public GeoIPService(ILogger<GeoIPService> logger,
|
||||||
IConfigurationService<ServerConfiguration> mareConfiguration)
|
IConfigurationService<AuthServiceConfiguration> mareConfiguration)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_mareConfiguration = mareConfiguration;
|
_mareConfiguration = mareConfiguration;
|
||||||
|
|
@ -38,11 +38,12 @@ public class GeoIPService : IHostedService
|
||||||
waitCts.CancelAfter(TimeSpan.FromSeconds(5));
|
waitCts.CancelAfter(TimeSpan.FromSeconds(5));
|
||||||
while (_processingReload) await Task.Delay(100, waitCts.Token).ConfigureAwait(false);
|
while (_processingReload) await Task.Delay(100, waitCts.Token).ConfigureAwait(false);
|
||||||
|
|
||||||
if (_dbReader.TryCity(ip, out var response))
|
if (_dbReader!.TryCity(ip, out var response))
|
||||||
{
|
{
|
||||||
var continent = response.Continent.Code;
|
string? continent = response?.Continent.Code;
|
||||||
if (string.Equals(continent, "NA", StringComparison.Ordinal)
|
if (!string.IsNullOrEmpty(continent) &&
|
||||||
&& response.Location.Longitude != null)
|
string.Equals(continent, "NA", StringComparison.Ordinal)
|
||||||
|
&& response?.Location.Longitude != null)
|
||||||
{
|
{
|
||||||
if (response.Location.Longitude < -102)
|
if (response.Location.Longitude < -102)
|
||||||
{
|
{
|
||||||
|
|
@ -84,8 +85,8 @@ public class GeoIPService : IHostedService
|
||||||
{
|
{
|
||||||
_processingReload = true;
|
_processingReload = true;
|
||||||
|
|
||||||
var useGeoIP = _mareConfiguration.GetValueOrDefault(nameof(ServerConfiguration.UseGeoIP), false);
|
var useGeoIP = _mareConfiguration.GetValueOrDefault(nameof(AuthServiceConfiguration.UseGeoIP), false);
|
||||||
var cityFile = _mareConfiguration.GetValueOrDefault(nameof(ServerConfiguration.GeoIPDbCityFile), string.Empty);
|
var cityFile = _mareConfiguration.GetValueOrDefault(nameof(AuthServiceConfiguration.GeoIPDbCityFile), string.Empty);
|
||||||
var lastWriteTime = new FileInfo(cityFile).LastWriteTimeUtc;
|
var lastWriteTime = new FileInfo(cityFile).LastWriteTimeUtc;
|
||||||
if (useGeoIP && (!string.Equals(cityFile, _cityFile, StringComparison.OrdinalIgnoreCase) || lastWriteTime != _dbLastWriteTime))
|
if (useGeoIP && (!string.Equals(cityFile, _cityFile, StringComparison.OrdinalIgnoreCase) || lastWriteTime != _dbLastWriteTime))
|
||||||
{
|
{
|
||||||
|
|
@ -131,7 +132,7 @@ public class GeoIPService : IHostedService
|
||||||
{
|
{
|
||||||
_fileWriteTimeCheckCts.Cancel();
|
_fileWriteTimeCheckCts.Cancel();
|
||||||
_fileWriteTimeCheckCts.Dispose();
|
_fileWriteTimeCheckCts.Dispose();
|
||||||
_dbReader.Dispose();
|
_dbReader?.Dispose();
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,22 +1,23 @@
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
|
using MareSynchronosAuthService.Authentication;
|
||||||
using MareSynchronosShared.Data;
|
using MareSynchronosShared.Data;
|
||||||
using MareSynchronosShared.Metrics;
|
using MareSynchronosShared.Metrics;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace MareSynchronosServer.Authentication;
|
namespace MareSynchronosAuthService.Services;
|
||||||
|
|
||||||
public class SecretKeyAuthenticatorService
|
public class SecretKeyAuthenticatorService
|
||||||
{
|
{
|
||||||
private readonly MareMetrics _metrics;
|
private readonly MareMetrics _metrics;
|
||||||
private readonly IDbContextFactory<MareDbContext> _dbContextFactory;
|
private readonly IDbContextFactory<MareDbContext> _dbContextFactory;
|
||||||
private readonly IConfigurationService<MareConfigurationAuthBase> _configurationService;
|
private readonly IConfigurationService<AuthServiceConfiguration> _configurationService;
|
||||||
private readonly ILogger<SecretKeyAuthenticatorService> _logger;
|
private readonly ILogger<SecretKeyAuthenticatorService> _logger;
|
||||||
private readonly ConcurrentDictionary<string, SecretKeyFailedAuthorization> _failedAuthorizations = new(StringComparer.Ordinal);
|
private readonly ConcurrentDictionary<string, SecretKeyFailedAuthorization> _failedAuthorizations = new(StringComparer.Ordinal);
|
||||||
|
|
||||||
public SecretKeyAuthenticatorService(MareMetrics metrics, IDbContextFactory<MareDbContext> dbContextFactory,
|
public SecretKeyAuthenticatorService(MareMetrics metrics, IDbContextFactory<MareDbContext> dbContextFactory,
|
||||||
IConfigurationService<MareConfigurationAuthBase> configuration, ILogger<SecretKeyAuthenticatorService> logger)
|
IConfigurationService<AuthServiceConfiguration> configuration, ILogger<SecretKeyAuthenticatorService> logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_configurationService = configuration;
|
_configurationService = configuration;
|
||||||
|
|
@ -29,7 +30,7 @@ public class SecretKeyAuthenticatorService
|
||||||
_metrics.IncCounter(MetricsAPI.CounterAuthenticationRequests);
|
_metrics.IncCounter(MetricsAPI.CounterAuthenticationRequests);
|
||||||
|
|
||||||
if (_failedAuthorizations.TryGetValue(ip, out var existingFailedAuthorization)
|
if (_failedAuthorizations.TryGetValue(ip, out var existingFailedAuthorization)
|
||||||
&& existingFailedAuthorization.FailedAttempts > _configurationService.GetValueOrDefault(nameof(MareConfigurationAuthBase.FailedAuthForTempBan), 5))
|
&& existingFailedAuthorization.FailedAttempts > _configurationService.GetValueOrDefault(nameof(AuthServiceConfiguration.FailedAuthForTempBan), 5))
|
||||||
{
|
{
|
||||||
if (existingFailedAuthorization.ResetTask == null)
|
if (existingFailedAuthorization.ResetTask == null)
|
||||||
{
|
{
|
||||||
|
|
@ -37,7 +38,7 @@ public class SecretKeyAuthenticatorService
|
||||||
|
|
||||||
existingFailedAuthorization.ResetTask = Task.Run(async () =>
|
existingFailedAuthorization.ResetTask = Task.Run(async () =>
|
||||||
{
|
{
|
||||||
await Task.Delay(TimeSpan.FromMinutes(_configurationService.GetValueOrDefault(nameof(MareConfigurationAuthBase.TempBanDurationInMinutes), 5))).ConfigureAwait(false);
|
await Task.Delay(TimeSpan.FromMinutes(_configurationService.GetValueOrDefault(nameof(AuthServiceConfiguration.TempBanDurationInMinutes), 5))).ConfigureAwait(false);
|
||||||
|
|
||||||
}).ContinueWith((t) =>
|
}).ContinueWith((t) =>
|
||||||
{
|
{
|
||||||
|
|
@ -80,7 +81,7 @@ public class SecretKeyAuthenticatorService
|
||||||
_metrics.IncCounter(MetricsAPI.CounterAuthenticationFailures);
|
_metrics.IncCounter(MetricsAPI.CounterAuthenticationFailures);
|
||||||
|
|
||||||
_logger.LogWarning("Failed authorization from {ip}", ip);
|
_logger.LogWarning("Failed authorization from {ip}", ip);
|
||||||
var whitelisted = _configurationService.GetValueOrDefault(nameof(MareConfigurationAuthBase.WhitelistedIps), new List<string>());
|
var whitelisted = _configurationService.GetValueOrDefault(nameof(AuthServiceConfiguration.WhitelistedIps), new List<string>());
|
||||||
if (!whitelisted.Exists(w => ip.Contains(w, StringComparison.OrdinalIgnoreCase)))
|
if (!whitelisted.Exists(w => ip.Contains(w, StringComparison.OrdinalIgnoreCase)))
|
||||||
{
|
{
|
||||||
if (_failedAuthorizations.TryGetValue(ip, out var auth))
|
if (_failedAuthorizations.TryGetValue(ip, out var auth))
|
||||||
226
MareSynchronosServer/MareSynchronosAuthService/Startup.cs
Normal file
226
MareSynchronosServer/MareSynchronosAuthService/Startup.cs
Normal file
|
|
@ -0,0 +1,226 @@
|
||||||
|
using MareSynchronosAuthService.Controllers;
|
||||||
|
using MareSynchronosShared.Metrics;
|
||||||
|
using MareSynchronosShared.Services;
|
||||||
|
using MareSynchronosShared.Utils;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||||
|
using StackExchange.Redis.Extensions.Core.Configuration;
|
||||||
|
using StackExchange.Redis.Extensions.System.Text.Json;
|
||||||
|
using StackExchange.Redis;
|
||||||
|
using System.Net;
|
||||||
|
using MareSynchronosAuthService.Services;
|
||||||
|
using MareSynchronosShared.RequirementHandlers;
|
||||||
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
|
using Microsoft.IdentityModel.Tokens;
|
||||||
|
using System.Text;
|
||||||
|
using MareSynchronosShared.Data;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Prometheus;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
|
namespace MareSynchronosAuthService;
|
||||||
|
|
||||||
|
public class Startup
|
||||||
|
{
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
private ILogger<Startup> _logger;
|
||||||
|
|
||||||
|
public Startup(IConfiguration configuration, ILogger<Startup> logger)
|
||||||
|
{
|
||||||
|
_configuration = configuration;
|
||||||
|
_logger = logger;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<Startup> logger)
|
||||||
|
{
|
||||||
|
var config = app.ApplicationServices.GetRequiredService<IConfigurationService<MareConfigurationBase>>();
|
||||||
|
|
||||||
|
app.UseRouting();
|
||||||
|
|
||||||
|
app.UseHttpMetrics();
|
||||||
|
|
||||||
|
app.UseAuthentication();
|
||||||
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
KestrelMetricServer metricServer = new KestrelMetricServer(config.GetValueOrDefault<int>(nameof(MareConfigurationBase.MetricsPort), 4985));
|
||||||
|
metricServer.Start();
|
||||||
|
|
||||||
|
app.UseEndpoints(endpoints =>
|
||||||
|
{
|
||||||
|
endpoints.MapControllers();
|
||||||
|
|
||||||
|
foreach (var source in endpoints.DataSources.SelectMany(e => e.Endpoints).Cast<RouteEndpoint>())
|
||||||
|
{
|
||||||
|
if (source == null) continue;
|
||||||
|
_logger.LogInformation("Endpoint: {url} ", source.RoutePattern.RawText);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ConfigureServices(IServiceCollection services)
|
||||||
|
{
|
||||||
|
var mareConfig = _configuration.GetRequiredSection("MareSynchronos");
|
||||||
|
|
||||||
|
ConfigureRedis(services, mareConfig);
|
||||||
|
|
||||||
|
services.AddSingleton<SecretKeyAuthenticatorService>();
|
||||||
|
services.AddSingleton<GeoIPService>();
|
||||||
|
|
||||||
|
services.AddHostedService(provider => provider.GetRequiredService<GeoIPService>());
|
||||||
|
|
||||||
|
services.Configure<AuthServiceConfiguration>(_configuration.GetRequiredSection("MareSynchronos"));
|
||||||
|
services.Configure<MareConfigurationBase>(_configuration.GetRequiredSection("MareSynchronos"));
|
||||||
|
|
||||||
|
services.AddSingleton<ServerTokenGenerator>();
|
||||||
|
|
||||||
|
ConfigureAuthorization(services);
|
||||||
|
|
||||||
|
ConfigureDatabase(services, mareConfig);
|
||||||
|
|
||||||
|
ConfigureConfigServices(services);
|
||||||
|
|
||||||
|
services.AddHealthChecks();
|
||||||
|
services.AddControllers().ConfigureApplicationPartManager(a =>
|
||||||
|
{
|
||||||
|
a.FeatureProviders.Remove(a.FeatureProviders.OfType<ControllerFeatureProvider>().First());
|
||||||
|
a.FeatureProviders.Add(new AllowedControllersFeatureProvider(typeof(JwtController)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ConfigureAuthorization(IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddTransient<IAuthorizationHandler, UserRequirementHandler>();
|
||||||
|
services.AddTransient<IAuthorizationHandler, ValidTokenRequirementHandler>();
|
||||||
|
|
||||||
|
services.AddOptions<JwtBearerOptions>(JwtBearerDefaults.AuthenticationScheme)
|
||||||
|
.Configure<IConfigurationService<MareConfigurationBase>>((options, config) =>
|
||||||
|
{
|
||||||
|
options.TokenValidationParameters = new()
|
||||||
|
{
|
||||||
|
ValidateIssuer = false,
|
||||||
|
ValidateLifetime = true,
|
||||||
|
ValidateAudience = false,
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(config.GetValue<string>(nameof(MareConfigurationBase.Jwt)))),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
services.AddAuthentication(o =>
|
||||||
|
{
|
||||||
|
o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
|
o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
|
o.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
|
||||||
|
}).AddJwtBearer();
|
||||||
|
|
||||||
|
services.AddAuthorization(options =>
|
||||||
|
{
|
||||||
|
options.DefaultPolicy = new AuthorizationPolicyBuilder()
|
||||||
|
.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
|
||||||
|
.RequireAuthenticatedUser().Build();
|
||||||
|
options.AddPolicy("Authenticated", policy =>
|
||||||
|
{
|
||||||
|
policy.AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme);
|
||||||
|
policy.RequireAuthenticatedUser();
|
||||||
|
policy.AddRequirements(new ValidTokenRequirement());
|
||||||
|
});
|
||||||
|
options.AddPolicy("Identified", policy =>
|
||||||
|
{
|
||||||
|
policy.AddRequirements(new UserRequirement(UserRequirements.Identified));
|
||||||
|
policy.AddRequirements(new ValidTokenRequirement());
|
||||||
|
|
||||||
|
});
|
||||||
|
options.AddPolicy("Admin", policy =>
|
||||||
|
{
|
||||||
|
policy.AddRequirements(new UserRequirement(UserRequirements.Identified | UserRequirements.Administrator));
|
||||||
|
policy.AddRequirements(new ValidTokenRequirement());
|
||||||
|
|
||||||
|
});
|
||||||
|
options.AddPolicy("Moderator", policy =>
|
||||||
|
{
|
||||||
|
policy.AddRequirements(new UserRequirement(UserRequirements.Identified | UserRequirements.Moderator | UserRequirements.Administrator));
|
||||||
|
policy.AddRequirements(new ValidTokenRequirement());
|
||||||
|
});
|
||||||
|
options.AddPolicy("Internal", new AuthorizationPolicyBuilder().RequireClaim(MareClaimTypes.Internal, "true").Build());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ConfigureMetrics(IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddSingleton<MareMetrics>(m => new MareMetrics(m.GetService<ILogger<MareMetrics>>(), new List<string>
|
||||||
|
{
|
||||||
|
MetricsAPI.CounterAuthenticationCacheHits,
|
||||||
|
MetricsAPI.CounterAuthenticationFailures,
|
||||||
|
MetricsAPI.CounterAuthenticationRequests,
|
||||||
|
MetricsAPI.CounterAuthenticationSuccesses,
|
||||||
|
}, new List<string>
|
||||||
|
{
|
||||||
|
MetricsAPI.GaugeAuthenticationCacheEntries,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ConfigureRedis(IServiceCollection services, IConfigurationSection mareConfig)
|
||||||
|
{
|
||||||
|
// configure redis for SignalR
|
||||||
|
var redisConnection = mareConfig.GetValue(nameof(ServerConfiguration.RedisConnectionString), string.Empty);
|
||||||
|
|
||||||
|
var options = ConfigurationOptions.Parse(redisConnection);
|
||||||
|
|
||||||
|
var endpoint = options.EndPoints[0];
|
||||||
|
string address = "";
|
||||||
|
int port = 0;
|
||||||
|
if (endpoint is DnsEndPoint dnsEndPoint) { address = dnsEndPoint.Host; port = dnsEndPoint.Port; }
|
||||||
|
if (endpoint is IPEndPoint ipEndPoint) { address = ipEndPoint.Address.ToString(); port = ipEndPoint.Port; }
|
||||||
|
var redisConfiguration = new RedisConfiguration()
|
||||||
|
{
|
||||||
|
AbortOnConnectFail = true,
|
||||||
|
KeyPrefix = "",
|
||||||
|
Hosts = new RedisHost[]
|
||||||
|
{
|
||||||
|
new RedisHost(){ Host = address, Port = port },
|
||||||
|
},
|
||||||
|
AllowAdmin = true,
|
||||||
|
ConnectTimeout = options.ConnectTimeout,
|
||||||
|
Database = 0,
|
||||||
|
Ssl = false,
|
||||||
|
Password = options.Password,
|
||||||
|
ServerEnumerationStrategy = new ServerEnumerationStrategy()
|
||||||
|
{
|
||||||
|
Mode = ServerEnumerationStrategy.ModeOptions.All,
|
||||||
|
TargetRole = ServerEnumerationStrategy.TargetRoleOptions.Any,
|
||||||
|
UnreachableServerAction = ServerEnumerationStrategy.UnreachableServerActionOptions.Throw,
|
||||||
|
},
|
||||||
|
MaxValueLength = 1024,
|
||||||
|
PoolSize = mareConfig.GetValue(nameof(ServerConfiguration.RedisPool), 50),
|
||||||
|
SyncTimeout = options.SyncTimeout,
|
||||||
|
};
|
||||||
|
|
||||||
|
services.AddStackExchangeRedisExtensions<SystemTextJsonSerializer>(redisConfiguration);
|
||||||
|
}
|
||||||
|
private void ConfigureConfigServices(IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddSingleton<IConfigurationService<AuthServiceConfiguration>, MareConfigurationServiceServer<AuthServiceConfiguration>>();
|
||||||
|
services.AddSingleton<IConfigurationService<MareConfigurationBase>, MareConfigurationServiceServer<MareConfigurationBase>>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ConfigureDatabase(IServiceCollection services, IConfigurationSection mareConfig)
|
||||||
|
{
|
||||||
|
services.AddDbContextPool<MareDbContext>(options =>
|
||||||
|
{
|
||||||
|
options.UseNpgsql(_configuration.GetConnectionString("DefaultConnection"), builder =>
|
||||||
|
{
|
||||||
|
builder.MigrationsHistoryTable("_efmigrationshistory", "public");
|
||||||
|
builder.MigrationsAssembly("MareSynchronosShared");
|
||||||
|
}).UseSnakeCaseNamingConvention();
|
||||||
|
options.EnableThreadSafetyChecks(false);
|
||||||
|
}, mareConfig.GetValue(nameof(MareConfigurationBase.DbContextPoolSize), 1024));
|
||||||
|
services.AddDbContextFactory<MareDbContext>(options =>
|
||||||
|
{
|
||||||
|
options.UseNpgsql(_configuration.GetConnectionString("DefaultConnection"), builder =>
|
||||||
|
{
|
||||||
|
builder.MigrationsHistoryTable("_efmigrationshistory", "public");
|
||||||
|
builder.MigrationsAssembly("MareSynchronosShared");
|
||||||
|
}).UseSnakeCaseNamingConvention();
|
||||||
|
options.EnableThreadSafetyChecks(false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*"
|
||||||
|
}
|
||||||
|
|
@ -20,6 +20,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
|
||||||
.editorconfig = .editorconfig
|
.editorconfig = .editorconfig
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MareSynchronosAuthService", "MareSynchronosAuthService\MareSynchronosAuthService.csproj", "{D7D4041C-DCD9-4B7A-B423-0F458DFFF3D6}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
|
@ -50,6 +52,10 @@ Global
|
||||||
{E29C8677-AB44-4950-9EB1-D8E70B710A56}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{E29C8677-AB44-4950-9EB1-D8E70B710A56}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{E29C8677-AB44-4950-9EB1-D8E70B710A56}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{E29C8677-AB44-4950-9EB1-D8E70B710A56}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{E29C8677-AB44-4950-9EB1-D8E70B710A56}.Release|Any CPU.Build.0 = Release|Any CPU
|
{E29C8677-AB44-4950-9EB1-D8E70B710A56}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{D7D4041C-DCD9-4B7A-B423-0F458DFFF3D6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{D7D4041C-DCD9-4B7A-B423-0F458DFFF3D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{D7D4041C-DCD9-4B7A-B423-0F458DFFF3D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{D7D4041C-DCD9-4B7A-B423-0F458DFFF3D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ using MareSynchronosShared.Data;
|
||||||
using MareSynchronosShared.Metrics;
|
using MareSynchronosShared.Metrics;
|
||||||
using MareSynchronosShared.Models;
|
using MareSynchronosShared.Models;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="lz4net" Version="1.0.15.93" />
|
<PackageReference Include="lz4net" Version="1.0.15.93" />
|
||||||
<PackageReference Include="MaxMind.GeoIP2" Version="5.2.0" />
|
|
||||||
<PackageReference Include="Meziantou.Analyzer" Version="2.0.149">
|
<PackageReference Include="Meziantou.Analyzer" Version="2.0.149">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ using Microsoft.EntityFrameworkCore;
|
||||||
using MareSynchronosShared.Data;
|
using MareSynchronosShared.Data;
|
||||||
using MareSynchronosShared.Metrics;
|
using MareSynchronosShared.Metrics;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
namespace MareSynchronosServer;
|
namespace MareSynchronosServer;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ using MareSynchronosServer.Hubs;
|
||||||
using MareSynchronosShared.Data;
|
using MareSynchronosShared.Data;
|
||||||
using MareSynchronosShared.Metrics;
|
using MareSynchronosShared.Metrics;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using StackExchange.Redis.Extensions.Core.Abstractions;
|
using StackExchange.Redis.Extensions.Core.Abstractions;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using MareSynchronosShared.Metrics;
|
||||||
using MareSynchronosShared.Models;
|
using MareSynchronosShared.Models;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace MareSynchronosServer.Services;
|
namespace MareSynchronosServer.Services;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ using Prometheus;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using MareSynchronosServer.Authentication;
|
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
using StackExchange.Redis.Extensions.Core.Configuration;
|
using StackExchange.Redis.Extensions.Core.Configuration;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
|
@ -24,6 +23,7 @@ using MessagePack.Resolvers;
|
||||||
using Microsoft.AspNetCore.Mvc.Controllers;
|
using Microsoft.AspNetCore.Mvc.Controllers;
|
||||||
using MareSynchronosServer.Controllers;
|
using MareSynchronosServer.Controllers;
|
||||||
using MareSynchronosShared.RequirementHandlers;
|
using MareSynchronosShared.RequirementHandlers;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
namespace MareSynchronosServer;
|
namespace MareSynchronosServer;
|
||||||
|
|
||||||
|
|
@ -71,7 +71,7 @@ public class Startup
|
||||||
a.FeatureProviders.Remove(a.FeatureProviders.OfType<ControllerFeatureProvider>().First());
|
a.FeatureProviders.Remove(a.FeatureProviders.OfType<ControllerFeatureProvider>().First());
|
||||||
if (mareConfig.GetValue<Uri>(nameof(ServerConfiguration.MainServerAddress), defaultValue: null) == null)
|
if (mareConfig.GetValue<Uri>(nameof(ServerConfiguration.MainServerAddress), defaultValue: null) == null)
|
||||||
{
|
{
|
||||||
a.FeatureProviders.Add(new AllowedControllersFeatureProvider(typeof(MareServerConfigurationController), typeof(MareAuthBaseConfigurationController), typeof(JwtController), typeof(ClientMessageController)));
|
a.FeatureProviders.Add(new AllowedControllersFeatureProvider(typeof(MareServerConfigurationController), typeof(MareAuthBaseConfigurationController), typeof(ClientMessageController)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -86,7 +86,6 @@ public class Startup
|
||||||
|
|
||||||
services.Configure<ServerConfiguration>(Configuration.GetRequiredSection("MareSynchronos"));
|
services.Configure<ServerConfiguration>(Configuration.GetRequiredSection("MareSynchronos"));
|
||||||
services.Configure<MareConfigurationBase>(Configuration.GetRequiredSection("MareSynchronos"));
|
services.Configure<MareConfigurationBase>(Configuration.GetRequiredSection("MareSynchronos"));
|
||||||
services.Configure<MareConfigurationAuthBase>(Configuration.GetRequiredSection("MareSynchronos"));
|
|
||||||
|
|
||||||
services.AddSingleton<ServerTokenGenerator>();
|
services.AddSingleton<ServerTokenGenerator>();
|
||||||
services.AddSingleton<SystemInfoService>();
|
services.AddSingleton<SystemInfoService>();
|
||||||
|
|
@ -100,10 +99,8 @@ public class Startup
|
||||||
|
|
||||||
if (isMainServer)
|
if (isMainServer)
|
||||||
{
|
{
|
||||||
services.AddSingleton<GeoIPService>();
|
|
||||||
services.AddSingleton<UserCleanupService>();
|
services.AddSingleton<UserCleanupService>();
|
||||||
services.AddHostedService(provider => provider.GetService<UserCleanupService>());
|
services.AddHostedService(provider => provider.GetService<UserCleanupService>());
|
||||||
services.AddHostedService(provider => provider.GetService<GeoIPService>());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -188,13 +185,12 @@ public class Startup
|
||||||
|
|
||||||
private static void ConfigureAuthorization(IServiceCollection services)
|
private static void ConfigureAuthorization(IServiceCollection services)
|
||||||
{
|
{
|
||||||
services.AddSingleton<SecretKeyAuthenticatorService>();
|
|
||||||
services.AddTransient<IAuthorizationHandler, UserRequirementHandler>();
|
services.AddTransient<IAuthorizationHandler, UserRequirementHandler>();
|
||||||
services.AddTransient<IAuthorizationHandler, ValidTokenRequirementHandler>();
|
services.AddTransient<IAuthorizationHandler, ValidTokenRequirementHandler>();
|
||||||
services.AddTransient<IAuthorizationHandler, ValidTokenHubRequirementHandler>();
|
services.AddTransient<IAuthorizationHandler, ValidTokenHubRequirementHandler>();
|
||||||
|
|
||||||
services.AddOptions<JwtBearerOptions>(JwtBearerDefaults.AuthenticationScheme)
|
services.AddOptions<JwtBearerOptions>(JwtBearerDefaults.AuthenticationScheme)
|
||||||
.Configure<IConfigurationService<MareConfigurationAuthBase>>((options, config) =>
|
.Configure<IConfigurationService<MareConfigurationBase>>((options, config) =>
|
||||||
{
|
{
|
||||||
options.TokenValidationParameters = new()
|
options.TokenValidationParameters = new()
|
||||||
{
|
{
|
||||||
|
|
@ -202,7 +198,7 @@ public class Startup
|
||||||
ValidateLifetime = true,
|
ValidateLifetime = true,
|
||||||
ValidateAudience = false,
|
ValidateAudience = false,
|
||||||
ValidateIssuerSigningKey = true,
|
ValidateIssuerSigningKey = true,
|
||||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(config.GetValue<string>(nameof(MareConfigurationAuthBase.Jwt)))),
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(config.GetValue<string>(nameof(MareConfigurationBase.Jwt)))),
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -305,15 +301,15 @@ public class Startup
|
||||||
if (!isMainServer)
|
if (!isMainServer)
|
||||||
{
|
{
|
||||||
services.AddSingleton<IConfigurationService<ServerConfiguration>, MareConfigurationServiceClient<ServerConfiguration>>();
|
services.AddSingleton<IConfigurationService<ServerConfiguration>, MareConfigurationServiceClient<ServerConfiguration>>();
|
||||||
services.AddSingleton<IConfigurationService<MareConfigurationAuthBase>, MareConfigurationServiceClient<MareConfigurationAuthBase>>();
|
services.AddSingleton<IConfigurationService<MareConfigurationBase>, MareConfigurationServiceClient<MareConfigurationBase>>();
|
||||||
|
|
||||||
services.AddHostedService(p => (MareConfigurationServiceClient<ServerConfiguration>)p.GetService<IConfigurationService<ServerConfiguration>>());
|
services.AddHostedService(p => (MareConfigurationServiceClient<ServerConfiguration>)p.GetService<IConfigurationService<ServerConfiguration>>());
|
||||||
services.AddHostedService(p => (MareConfigurationServiceClient<MareConfigurationAuthBase>)p.GetService<IConfigurationService<MareConfigurationAuthBase>>());
|
services.AddHostedService(p => (MareConfigurationServiceClient<MareConfigurationBase>)p.GetService<IConfigurationService<MareConfigurationBase>>());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
services.AddSingleton<IConfigurationService<ServerConfiguration>, MareConfigurationServiceServer<ServerConfiguration>>();
|
services.AddSingleton<IConfigurationService<ServerConfiguration>, MareConfigurationServiceServer<ServerConfiguration>>();
|
||||||
services.AddSingleton<IConfigurationService<MareConfigurationAuthBase>, MareConfigurationServiceServer<MareConfigurationAuthBase>>();
|
services.AddSingleton<IConfigurationService<MareConfigurationBase>, MareConfigurationServiceServer<MareConfigurationBase>>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -321,7 +317,7 @@ public class Startup
|
||||||
{
|
{
|
||||||
logger.LogInformation("Running Configure");
|
logger.LogInformation("Running Configure");
|
||||||
|
|
||||||
var config = app.ApplicationServices.GetRequiredService<IConfigurationService<MareConfigurationAuthBase>>();
|
var config = app.ApplicationServices.GetRequiredService<IConfigurationService<MareConfigurationBase>>();
|
||||||
|
|
||||||
app.UseIpRateLimiting();
|
app.UseIpRateLimiting();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ using MareSynchronos.API.SignalR;
|
||||||
using MareSynchronosServer.Hubs;
|
using MareSynchronosServer.Hubs;
|
||||||
using MareSynchronosShared.Data;
|
using MareSynchronosShared.Data;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using MareSynchronosShared.Utils;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
using MareSynchronos.API.Data.Enum;
|
using MareSynchronos.API.Data.Enum;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
namespace MareSynchronosServices.Discord;
|
namespace MareSynchronosServices.Discord;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using Discord;
|
using Discord;
|
||||||
using Discord.Interactions;
|
using Discord.Interactions;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace MareSynchronosServices.Discord;
|
namespace MareSynchronosServices.Discord;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
using Discord;
|
using Discord;
|
||||||
using MareSynchronosShared.Data;
|
using MareSynchronosShared.Data;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
namespace MareSynchronosServices.Discord;
|
namespace MareSynchronosServices.Discord;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using MareSynchronosShared.Data;
|
||||||
using MareSynchronosShared.Models;
|
using MareSynchronosShared.Models;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
using MareSynchronosServices;
|
using MareSynchronosServices;
|
||||||
using MareSynchronosShared.Data;
|
using MareSynchronosShared.Data;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using MareSynchronosShared.Services;
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
using MessagePack.Resolvers;
|
using MessagePack.Resolvers;
|
||||||
using MessagePack;
|
using MessagePack;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
namespace MareSynchronosServices;
|
namespace MareSynchronosServices;
|
||||||
|
|
||||||
|
|
@ -22,7 +23,7 @@ public class Startup
|
||||||
|
|
||||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
{
|
{
|
||||||
var config = app.ApplicationServices.GetRequiredService<IConfigurationService<MareConfigurationAuthBase>>();
|
var config = app.ApplicationServices.GetRequiredService<IConfigurationService<MareConfigurationBase>>();
|
||||||
|
|
||||||
var metricServer = new KestrelMetricServer(config.GetValueOrDefault<int>(nameof(MareConfigurationBase.MetricsPort), 4982));
|
var metricServer = new KestrelMetricServer(config.GetValueOrDefault<int>(nameof(MareConfigurationBase.MetricsPort), 4982));
|
||||||
metricServer.Start();
|
metricServer.Start();
|
||||||
|
|
@ -88,16 +89,16 @@ public class Startup
|
||||||
|
|
||||||
services.Configure<ServicesConfiguration>(Configuration.GetRequiredSection("MareSynchronos"));
|
services.Configure<ServicesConfiguration>(Configuration.GetRequiredSection("MareSynchronos"));
|
||||||
services.Configure<ServerConfiguration>(Configuration.GetRequiredSection("MareSynchronos"));
|
services.Configure<ServerConfiguration>(Configuration.GetRequiredSection("MareSynchronos"));
|
||||||
services.Configure<MareConfigurationAuthBase>(Configuration.GetRequiredSection("MareSynchronos"));
|
services.Configure<MareConfigurationBase>(Configuration.GetRequiredSection("MareSynchronos"));
|
||||||
services.AddSingleton(Configuration);
|
services.AddSingleton(Configuration);
|
||||||
services.AddSingleton<ServerTokenGenerator>();
|
services.AddSingleton<ServerTokenGenerator>();
|
||||||
services.AddSingleton<DiscordBotServices>();
|
services.AddSingleton<DiscordBotServices>();
|
||||||
services.AddHostedService<DiscordBot>();
|
services.AddHostedService<DiscordBot>();
|
||||||
services.AddSingleton<IConfigurationService<ServicesConfiguration>, MareConfigurationServiceServer<ServicesConfiguration>>();
|
services.AddSingleton<IConfigurationService<ServicesConfiguration>, MareConfigurationServiceServer<ServicesConfiguration>>();
|
||||||
services.AddSingleton<IConfigurationService<ServerConfiguration>, MareConfigurationServiceClient<ServerConfiguration>>();
|
services.AddSingleton<IConfigurationService<ServerConfiguration>, MareConfigurationServiceClient<ServerConfiguration>>();
|
||||||
services.AddSingleton<IConfigurationService<MareConfigurationAuthBase>, MareConfigurationServiceClient<MareConfigurationAuthBase>>();
|
services.AddSingleton<IConfigurationService<MareConfigurationBase>, MareConfigurationServiceClient<MareConfigurationBase>>();
|
||||||
|
|
||||||
services.AddHostedService(p => (MareConfigurationServiceClient<MareConfigurationAuthBase>)p.GetService<IConfigurationService<MareConfigurationAuthBase>>());
|
services.AddHostedService(p => (MareConfigurationServiceClient<MareConfigurationBase>)p.GetService<IConfigurationService<MareConfigurationBase>>());
|
||||||
services.AddHostedService(p => (MareConfigurationServiceClient<ServerConfiguration>)p.GetService<IConfigurationService<ServerConfiguration>>());
|
services.AddHostedService(p => (MareConfigurationServiceClient<ServerConfiguration>)p.GetService<IConfigurationService<ServerConfiguration>>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
namespace MareSynchronosShared.Services;
|
namespace MareSynchronosShared.Services;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using MareSynchronosStaticFilesServer;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils;
|
||||||
using MareSynchronosStaticFilesServer;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
|
|
@ -27,8 +27,8 @@ public class MareConfigurationServiceClient<T> : IHostedService, IConfigurationS
|
||||||
{
|
{
|
||||||
if (_config.CurrentValue.GetType() == typeof(ServerConfiguration))
|
if (_config.CurrentValue.GetType() == typeof(ServerConfiguration))
|
||||||
return new Uri((_config.CurrentValue as ServerConfiguration).MainServerAddress, $"configuration/MareServerConfiguration/{nameof(MareServerConfigurationController.GetConfigurationEntry)}?key={key}&defaultValue={value}");
|
return new Uri((_config.CurrentValue as ServerConfiguration).MainServerAddress, $"configuration/MareServerConfiguration/{nameof(MareServerConfigurationController.GetConfigurationEntry)}?key={key}&defaultValue={value}");
|
||||||
if (_config.CurrentValue.GetType() == typeof(MareConfigurationAuthBase))
|
if (_config.CurrentValue.GetType() == typeof(MareConfigurationBase))
|
||||||
return new Uri((_config.CurrentValue as MareConfigurationAuthBase).MainServerAddress, $"configuration/MareAuthBaseConfiguration/{nameof(MareAuthBaseConfigurationController.GetConfigurationEntry)}?key={key}&defaultValue={value}");
|
return new Uri((_config.CurrentValue as MareConfigurationBase).MainServerAddress, $"configuration/MareAuthBaseConfiguration/{nameof(MareAuthBaseConfigurationController.GetConfigurationEntry)}?key={key}&defaultValue={value}");
|
||||||
if (_config.CurrentValue.GetType() == typeof(ServicesConfiguration))
|
if (_config.CurrentValue.GetType() == typeof(ServicesConfiguration))
|
||||||
return new Uri((_config.CurrentValue as ServicesConfiguration).MainServerAddress, $"configuration/MareServicesConfiguration/{nameof(MareServicesConfigurationController.GetConfigurationEntry)}?key={key}&defaultValue={value}");
|
return new Uri((_config.CurrentValue as ServicesConfiguration).MainServerAddress, $"configuration/MareServicesConfiguration/{nameof(MareServicesConfigurationController.GetConfigurationEntry)}?key={key}&defaultValue={value}");
|
||||||
if (_config.CurrentValue.GetType() == typeof(StaticFilesServerConfiguration))
|
if (_config.CurrentValue.GetType() == typeof(StaticFilesServerConfiguration))
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
|
public class AuthServiceConfiguration : MareConfigurationBase
|
||||||
|
{
|
||||||
|
public string GeoIPDbCityFile { get; set; } = string.Empty;
|
||||||
|
public bool UseGeoIP { get; set; } = false;
|
||||||
|
public int FailedAuthForTempBan { get; set; } = 5;
|
||||||
|
public int TempBanDurationInMinutes { get; set; } = 5;
|
||||||
|
public List<string> WhitelistedIps { get; set; } = new();
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
StringBuilder sb = new();
|
||||||
|
sb.AppendLine(base.ToString());
|
||||||
|
sb.AppendLine($"{nameof(RedisPool)} => {RedisPool}");
|
||||||
|
sb.AppendLine($"{nameof(GeoIPDbCityFile)} => {GeoIPDbCityFile}");
|
||||||
|
sb.AppendLine($"{nameof(UseGeoIP)} => {UseGeoIP}");
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace MareSynchronosShared.Utils;
|
namespace MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
public class CdnShardConfiguration
|
public class CdnShardConfiguration
|
||||||
{
|
{
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
namespace MareSynchronosShared.Utils;
|
namespace MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
public interface IMareConfiguration
|
public interface IMareConfiguration
|
||||||
{
|
{
|
||||||
|
|
@ -2,13 +2,14 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
namespace MareSynchronosShared.Utils;
|
namespace MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
public class MareConfigurationBase : IMareConfiguration
|
public class MareConfigurationBase : IMareConfiguration
|
||||||
{
|
{
|
||||||
public int DbContextPoolSize { get; set; } = 100;
|
public int DbContextPoolSize { get; set; } = 100;
|
||||||
public string Jwt { get; set; } = string.Empty;
|
public string Jwt { get; set; } = string.Empty;
|
||||||
public Uri MainServerAddress { get; set; }
|
public Uri MainServerAddress { get; set; }
|
||||||
|
public int RedisPool { get; set; } = 50;
|
||||||
public int MetricsPort { get; set; }
|
public int MetricsPort { get; set; }
|
||||||
public string RedisConnectionString { get; set; } = string.Empty;
|
public string RedisConnectionString { get; set; } = string.Empty;
|
||||||
public string ShardName { get; set; } = string.Empty;
|
public string ShardName { get; set; } = string.Empty;
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace MareSynchronosShared.Utils;
|
namespace MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
public class ServerConfiguration : MareConfigurationAuthBase
|
public class ServerConfiguration : MareConfigurationBase
|
||||||
{
|
{
|
||||||
[RemoteConfiguration]
|
[RemoteConfiguration]
|
||||||
public Uri CdnFullUrl { get; set; } = null;
|
public Uri CdnFullUrl { get; set; } = null;
|
||||||
|
|
@ -26,15 +26,12 @@ public class ServerConfiguration : MareConfigurationAuthBase
|
||||||
public int PurgeUnusedAccountsPeriodInDays { get; set; } = 14;
|
public int PurgeUnusedAccountsPeriodInDays { get; set; } = 14;
|
||||||
public string GeoIPDbCityFile { get; set; } = string.Empty;
|
public string GeoIPDbCityFile { get; set; } = string.Empty;
|
||||||
|
|
||||||
public int RedisPool { get; set; } = 50;
|
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
StringBuilder sb = new();
|
StringBuilder sb = new();
|
||||||
sb.AppendLine(base.ToString());
|
sb.AppendLine(base.ToString());
|
||||||
sb.AppendLine($"{nameof(CdnFullUrl)} => {CdnFullUrl}");
|
sb.AppendLine($"{nameof(CdnFullUrl)} => {CdnFullUrl}");
|
||||||
sb.AppendLine($"{nameof(RedisConnectionString)} => {RedisConnectionString}");
|
sb.AppendLine($"{nameof(RedisConnectionString)} => {RedisConnectionString}");
|
||||||
sb.AppendLine($"{nameof(RedisPool)} => {RedisPool}");
|
|
||||||
sb.AppendLine($"{nameof(ExpectedClientVersion)} => {ExpectedClientVersion}");
|
sb.AppendLine($"{nameof(ExpectedClientVersion)} => {ExpectedClientVersion}");
|
||||||
sb.AppendLine($"{nameof(MaxExistingGroupsByUser)} => {MaxExistingGroupsByUser}");
|
sb.AppendLine($"{nameof(MaxExistingGroupsByUser)} => {MaxExistingGroupsByUser}");
|
||||||
sb.AppendLine($"{nameof(MaxJoinedGroupsByUser)} => {MaxJoinedGroupsByUser}");
|
sb.AppendLine($"{nameof(MaxJoinedGroupsByUser)} => {MaxJoinedGroupsByUser}");
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace MareSynchronosShared.Utils;
|
namespace MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
public class ServicesConfiguration : MareConfigurationBase
|
public class ServicesConfiguration : MareConfigurationBase
|
||||||
{
|
{
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace MareSynchronosStaticFilesServer;
|
namespace MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
public class StaticFilesServerConfiguration : MareConfigurationBase
|
public class StaticFilesServerConfiguration : MareConfigurationBase
|
||||||
{
|
{
|
||||||
public bool IsDistributionNode { get; set; } = false;
|
public bool IsDistributionNode { get; set; } = false;
|
||||||
public Uri? MainFileServerAddress { get; set; } = null;
|
public Uri MainFileServerAddress { get; set; } = null;
|
||||||
public Uri? DistributionFileServerAddress { get; set; } = null;
|
public Uri DistributionFileServerAddress { get; set; } = null;
|
||||||
public int ForcedDeletionOfFilesAfterHours { get; set; } = -1;
|
public int ForcedDeletionOfFilesAfterHours { get; set; } = -1;
|
||||||
public double CacheSizeHardLimitInGiB { get; set; } = -1;
|
public double CacheSizeHardLimitInGiB { get; set; } = -1;
|
||||||
public int UnusedFileRetentionPeriodInDays { get; set; } = 14;
|
public int UnusedFileRetentionPeriodInDays { get; set; } = 14;
|
||||||
|
|
@ -18,7 +18,7 @@ public class StaticFilesServerConfiguration : MareConfigurationBase
|
||||||
public int DownloadQueueClearLimit { get; set; } = 15000;
|
public int DownloadQueueClearLimit { get; set; } = 15000;
|
||||||
public int CleanupCheckInMinutes { get; set; } = 15;
|
public int CleanupCheckInMinutes { get; set; } = 15;
|
||||||
public bool UseColdStorage { get; set; } = false;
|
public bool UseColdStorage { get; set; } = false;
|
||||||
public string? ColdStorageDirectory { get; set; } = null;
|
public string ColdStorageDirectory { get; set; } = null;
|
||||||
public double ColdStorageSizeHardLimitInGiB { get; set; } = -1;
|
public double ColdStorageSizeHardLimitInGiB { get; set; } = -1;
|
||||||
public int ColdStorageUnusedFileRetentionPeriodInDays { get; set; } = 30;
|
public int ColdStorageUnusedFileRetentionPeriodInDays { get; set; } = 30;
|
||||||
[RemoteConfiguration]
|
[RemoteConfiguration]
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
namespace MareSynchronosShared.Utils;
|
|
||||||
|
|
||||||
public class MareConfigurationAuthBase : MareConfigurationBase
|
|
||||||
{
|
|
||||||
[RemoteConfiguration]
|
|
||||||
public int FailedAuthForTempBan { get; set; } = 5;
|
|
||||||
[RemoteConfiguration]
|
|
||||||
public int TempBanDurationInMinutes { get; set; } = 5;
|
|
||||||
[RemoteConfiguration]
|
|
||||||
public List<string> WhitelistedIps { get; set; } = new();
|
|
||||||
[RemoteConfiguration]
|
|
||||||
public bool UseGeoIP { get; set; } = false;
|
|
||||||
|
|
||||||
public override string ToString()
|
|
||||||
{
|
|
||||||
StringBuilder sb = new();
|
|
||||||
sb.AppendLine(base.ToString());
|
|
||||||
sb.AppendLine($"{nameof(FailedAuthForTempBan)} => {FailedAuthForTempBan}");
|
|
||||||
sb.AppendLine($"{nameof(TempBanDurationInMinutes)} => {TempBanDurationInMinutes}");
|
|
||||||
sb.AppendLine($"{nameof(Jwt)} => {Jwt}");
|
|
||||||
sb.AppendLine($"{nameof(WhitelistedIps)} => {string.Join(", ", WhitelistedIps)}");
|
|
||||||
sb.AppendLine($"{nameof(UseGeoIP)} => {UseGeoIP}");
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Microsoft.Extensions.Logging;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Microsoft.IdentityModel.Tokens;
|
using Microsoft.IdentityModel.Tokens;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
|
@ -10,7 +11,7 @@ namespace MareSynchronosShared.Utils;
|
||||||
|
|
||||||
public class ServerTokenGenerator
|
public class ServerTokenGenerator
|
||||||
{
|
{
|
||||||
private readonly IOptionsMonitor<MareConfigurationAuthBase> _configuration;
|
private readonly IOptionsMonitor<MareConfigurationBase> _configuration;
|
||||||
private readonly ILogger<ServerTokenGenerator> _logger;
|
private readonly ILogger<ServerTokenGenerator> _logger;
|
||||||
|
|
||||||
private Dictionary<string, string> _tokenDictionary { get; set; } = new(StringComparer.Ordinal);
|
private Dictionary<string, string> _tokenDictionary { get; set; } = new(StringComparer.Ordinal);
|
||||||
|
|
@ -28,7 +29,7 @@ public class ServerTokenGenerator
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ServerTokenGenerator(IOptionsMonitor<MareConfigurationAuthBase> configuration, ILogger<ServerTokenGenerator> logger)
|
public ServerTokenGenerator(IOptionsMonitor<MareConfigurationBase> configuration, ILogger<ServerTokenGenerator> logger)
|
||||||
{
|
{
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,12 @@ using MareSynchronosShared.Data;
|
||||||
using MareSynchronosShared.Metrics;
|
using MareSynchronosShared.Metrics;
|
||||||
using MareSynchronosShared.Models;
|
using MareSynchronosShared.Models;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using MareSynchronosStaticFilesServer.Services;
|
using MareSynchronosStaticFilesServer.Services;
|
||||||
using MareSynchronosStaticFilesServer.Utils;
|
using MareSynchronosStaticFilesServer.Utils;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.AspNetCore.SignalR;
|
using Microsoft.AspNetCore.SignalR;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
namespace MareSynchronosStaticFilesServer;
|
namespace MareSynchronosStaticFilesServer;
|
||||||
|
|
||||||
|
|
@ -13,7 +13,7 @@ public class Program
|
||||||
using (var scope = host.Services.CreateScope())
|
using (var scope = host.Services.CreateScope())
|
||||||
{
|
{
|
||||||
var options = host.Services.GetService<IConfigurationService<StaticFilesServerConfiguration>>();
|
var options = host.Services.GetService<IConfigurationService<StaticFilesServerConfiguration>>();
|
||||||
var optionsServer = host.Services.GetService<IConfigurationService<MareConfigurationAuthBase>>();
|
var optionsServer = host.Services.GetService<IConfigurationService<MareConfigurationBase>>();
|
||||||
var logger = host.Services.GetService<ILogger<Program>>();
|
var logger = host.Services.GetService<ILogger<Program>>();
|
||||||
logger.LogInformation("Loaded MareSynchronos Static Files Server Configuration (IsMain: {isMain})", options.IsMain);
|
logger.LogInformation("Loaded MareSynchronos Static Files Server Configuration (IsMain: {isMain})", options.IsMain);
|
||||||
logger.LogInformation(options.ToString());
|
logger.LogInformation(options.ToString());
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using System.Collections.Concurrent;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils;
|
||||||
using MareSynchronos.API.Routes;
|
using MareSynchronos.API.Routes;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
namespace MareSynchronosStaticFilesServer.Services;
|
namespace MareSynchronosStaticFilesServer.Services;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using MareSynchronosShared.Data;
|
||||||
using MareSynchronosShared.Metrics;
|
using MareSynchronosShared.Metrics;
|
||||||
using MareSynchronosShared.Models;
|
using MareSynchronosShared.Models;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using MareSynchronosStaticFilesServer.Utils;
|
using MareSynchronosStaticFilesServer.Utils;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
using MareSynchronosShared.Metrics;
|
using MareSynchronosShared.Metrics;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using MareSynchronosStaticFilesServer.Utils;
|
using MareSynchronosStaticFilesServer.Utils;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Linq;
|
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
|
|
||||||
namespace MareSynchronosStaticFilesServer.Services;
|
namespace MareSynchronosStaticFilesServer.Services;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using MareSynchronos.API.Routes;
|
using MareSynchronos.API.Routes;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
using MareSynchronosShared.Utils;
|
using MareSynchronosShared.Utils;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
|
|
||||||
namespace MareSynchronosStaticFilesServer.Services;
|
namespace MareSynchronosStaticFilesServer.Services;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using ByteSizeLib;
|
using ByteSizeLib;
|
||||||
using MareSynchronosShared.Metrics;
|
using MareSynchronosShared.Metrics;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace MareSynchronosStaticFilesServer.Services;
|
namespace MareSynchronosStaticFilesServer.Services;
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ using StackExchange.Redis.Extensions.System.Text.Json;
|
||||||
using StackExchange.Redis;
|
using StackExchange.Redis;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
|
|
||||||
namespace MareSynchronosStaticFilesServer;
|
namespace MareSynchronosStaticFilesServer;
|
||||||
|
|
||||||
|
|
@ -47,7 +48,7 @@ public class Startup
|
||||||
services.AddLogging();
|
services.AddLogging();
|
||||||
|
|
||||||
services.Configure<StaticFilesServerConfiguration>(Configuration.GetRequiredSection("MareSynchronos"));
|
services.Configure<StaticFilesServerConfiguration>(Configuration.GetRequiredSection("MareSynchronos"));
|
||||||
services.Configure<MareConfigurationAuthBase>(Configuration.GetRequiredSection("MareSynchronos"));
|
services.Configure<MareConfigurationBase>(Configuration.GetRequiredSection("MareSynchronos"));
|
||||||
services.Configure<KestrelServerOptions>(Configuration.GetSection("Kestrel"));
|
services.Configure<KestrelServerOptions>(Configuration.GetSection("Kestrel"));
|
||||||
services.AddSingleton(Configuration);
|
services.AddSingleton(Configuration);
|
||||||
|
|
||||||
|
|
@ -88,8 +89,8 @@ public class Startup
|
||||||
services.AddSingleton<RequestQueueService>();
|
services.AddSingleton<RequestQueueService>();
|
||||||
services.AddHostedService(p => p.GetService<RequestQueueService>());
|
services.AddHostedService(p => p.GetService<RequestQueueService>());
|
||||||
services.AddHostedService(m => m.GetService<FileStatisticsService>());
|
services.AddHostedService(m => m.GetService<FileStatisticsService>());
|
||||||
services.AddSingleton<IConfigurationService<MareConfigurationAuthBase>, MareConfigurationServiceClient<MareConfigurationAuthBase>>();
|
services.AddSingleton<IConfigurationService<MareConfigurationBase>, MareConfigurationServiceClient<MareConfigurationBase>>();
|
||||||
services.AddHostedService(p => (MareConfigurationServiceClient<MareConfigurationAuthBase>)p.GetService<IConfigurationService<MareConfigurationAuthBase>>());
|
services.AddHostedService(p => (MareConfigurationServiceClient<MareConfigurationBase>)p.GetService<IConfigurationService<MareConfigurationBase>>());
|
||||||
|
|
||||||
// specific services
|
// specific services
|
||||||
if (_isMain)
|
if (_isMain)
|
||||||
|
|
@ -198,7 +199,7 @@ public class Startup
|
||||||
|
|
||||||
// authentication and authorization
|
// authentication and authorization
|
||||||
services.AddOptions<JwtBearerOptions>(JwtBearerDefaults.AuthenticationScheme)
|
services.AddOptions<JwtBearerOptions>(JwtBearerDefaults.AuthenticationScheme)
|
||||||
.Configure<IConfigurationService<MareConfigurationAuthBase>>((o, s) =>
|
.Configure<IConfigurationService<MareConfigurationBase>>((o, s) =>
|
||||||
{
|
{
|
||||||
o.TokenValidationParameters = new()
|
o.TokenValidationParameters = new()
|
||||||
{
|
{
|
||||||
|
|
@ -206,7 +207,7 @@ public class Startup
|
||||||
ValidateLifetime = true,
|
ValidateLifetime = true,
|
||||||
ValidateAudience = false,
|
ValidateAudience = false,
|
||||||
ValidateIssuerSigningKey = true,
|
ValidateIssuerSigningKey = true,
|
||||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(s.GetValue<string>(nameof(MareConfigurationAuthBase.Jwt))))
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(s.GetValue<string>(nameof(MareConfigurationBase.Jwt))))
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
services.AddAuthentication(o =>
|
services.AddAuthentication(o =>
|
||||||
|
|
@ -232,7 +233,7 @@ public class Startup
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
var config = app.ApplicationServices.GetRequiredService<IConfigurationService<MareConfigurationAuthBase>>();
|
var config = app.ApplicationServices.GetRequiredService<IConfigurationService<MareConfigurationBase>>();
|
||||||
|
|
||||||
var metricServer = new KestrelMetricServer(config.GetValueOrDefault<int>(nameof(MareConfigurationBase.MetricsPort), 4981));
|
var metricServer = new KestrelMetricServer(config.GetValueOrDefault<int>(nameof(MareConfigurationBase.MetricsPort), 4981));
|
||||||
metricServer.Start();
|
metricServer.Start();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
using System.Text.RegularExpressions;
|
namespace MareSynchronosStaticFilesServer.Utils;
|
||||||
|
|
||||||
namespace MareSynchronosStaticFilesServer.Utils;
|
|
||||||
|
|
||||||
public static partial class FilePathUtil
|
public static partial class FilePathUtil
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using MareSynchronosShared.Metrics;
|
using MareSynchronosShared.Metrics;
|
||||||
using MareSynchronosShared.Services;
|
using MareSynchronosShared.Services;
|
||||||
|
using MareSynchronosShared.Utils.Configuration;
|
||||||
using MareSynchronosStaticFilesServer.Services;
|
using MareSynchronosStaticFilesServer.Services;
|
||||||
|
|
||||||
namespace MareSynchronosStaticFilesServer.Utils;
|
namespace MareSynchronosStaticFilesServer.Utils;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue