Split AuthService/Server
some refactoring fix some stuff add http context accessor configure metrics as well commit 713d054ccb965f7adb8eafa6e3fb52853a1e6dd2 (partial, Docker only)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using MareSynchronosShared.Utils;
|
||||
using MareSynchronosShared.Utils.Configuration;
|
||||
|
||||
namespace MareSynchronosShared.Services;
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using MareSynchronosShared.Utils;
|
||||
using MareSynchronosStaticFilesServer;
|
||||
using MareSynchronosShared.Utils.Configuration;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
@@ -38,9 +37,9 @@ public class MareStaticFilesServerConfigurationController : MareConfigurationCon
|
||||
}
|
||||
}
|
||||
|
||||
public class MareAuthBaseConfigurationController : MareConfigurationController<MareConfigurationAuthBase>
|
||||
public class MareBaseConfigurationController : MareConfigurationController<MareConfigurationBase>
|
||||
{
|
||||
public MareAuthBaseConfigurationController(IOptionsMonitor<MareConfigurationAuthBase> config, ILogger<MareAuthBaseConfigurationController> logger) : base(config, logger)
|
||||
public MareBaseConfigurationController(IOptionsMonitor<MareConfigurationBase> config, ILogger<MareBaseConfigurationController> logger) : base(config, logger)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using MareSynchronosShared.Utils;
|
||||
using MareSynchronosStaticFilesServer;
|
||||
using MareSynchronosShared.Utils.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
@@ -27,8 +27,8 @@ public class MareConfigurationServiceClient<T> : IHostedService, IConfigurationS
|
||||
{
|
||||
if (_config.CurrentValue.GetType() == typeof(ServerConfiguration))
|
||||
return new Uri((_config.CurrentValue as ServerConfiguration).MainServerAddress, $"configuration/MareServerConfiguration/{nameof(MareServerConfigurationController.GetConfigurationEntry)}?key={key}&defaultValue={value}");
|
||||
if (_config.CurrentValue.GetType() == typeof(MareConfigurationAuthBase))
|
||||
return new Uri((_config.CurrentValue as MareConfigurationAuthBase).MainServerAddress, $"configuration/MareAuthBaseConfiguration/{nameof(MareAuthBaseConfigurationController.GetConfigurationEntry)}?key={key}&defaultValue={value}");
|
||||
if (_config.CurrentValue.GetType() == typeof(MareConfigurationBase))
|
||||
return new Uri((_config.CurrentValue as MareConfigurationBase).MainServerAddress, $"configuration/MareBaseConfiguration/{nameof(MareBaseConfigurationController.GetConfigurationEntry)}?key={key}&defaultValue={value}");
|
||||
if (_config.CurrentValue.GetType() == typeof(ServicesConfiguration))
|
||||
return new Uri((_config.CurrentValue as ServicesConfiguration).MainServerAddress, $"configuration/MareServicesConfiguration/{nameof(MareServicesConfigurationController.GetConfigurationEntry)}?key={key}&defaultValue={value}");
|
||||
if (_config.CurrentValue.GetType() == typeof(StaticFilesServerConfiguration))
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MareSynchronosShared.Utils;
|
||||
using MareSynchronosShared.Utils.Configuration;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.Collections;
|
||||
using System.Text;
|
||||
|
||||
@@ -1,33 +1,26 @@
|
||||
using System.Text;
|
||||
|
||||
namespace MareSynchronosShared.Utils;
|
||||
namespace MareSynchronosShared.Utils.Configuration;
|
||||
|
||||
public class MareConfigurationAuthBase : MareConfigurationBase
|
||||
public class AuthServiceConfiguration : MareConfigurationBase
|
||||
{
|
||||
[RemoteConfiguration]
|
||||
public int FailedAuthForTempBan { get; set; } = 5;
|
||||
[RemoteConfiguration]
|
||||
public int TempBanDurationInMinutes { get; set; } = 5;
|
||||
[RemoteConfiguration]
|
||||
public int RegisterIpLimit { get; set; } = 3;
|
||||
[RemoteConfiguration]
|
||||
public int RegisterIpDurationInMinutes { get; set; } = 10;
|
||||
[RemoteConfiguration]
|
||||
public List<string> WhitelistedIps { get; set; } = new();
|
||||
[RemoteConfiguration]
|
||||
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 int RegisterIpLimit { get; set; } = 3;
|
||||
public int RegisterIpDurationInMinutes { get; set; } = 10;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
sb.AppendLine(base.ToString());
|
||||
sb.AppendLine($"{nameof(FailedAuthForTempBan)} => {FailedAuthForTempBan}");
|
||||
sb.AppendLine($"{nameof(TempBanDurationInMinutes)} => {TempBanDurationInMinutes}");
|
||||
sb.AppendLine($"{nameof(GeoIPDbCityFile)} => {GeoIPDbCityFile}");
|
||||
sb.AppendLine($"{nameof(UseGeoIP)} => {UseGeoIP}");
|
||||
sb.AppendLine($"{nameof(RegisterIpLimit)} => {RegisterIpLimit}");
|
||||
sb.AppendLine($"{nameof(RegisterIpDurationInMinutes)} => {RegisterIpDurationInMinutes}");
|
||||
sb.AppendLine($"{nameof(Jwt)} => {Jwt}");
|
||||
sb.AppendLine($"{nameof(WhitelistedIps)} => {string.Join(", ", WhitelistedIps)}");
|
||||
sb.AppendLine($"{nameof(UseGeoIP)} => {UseGeoIP}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace MareSynchronosShared.Utils;
|
||||
namespace MareSynchronosShared.Utils.Configuration;
|
||||
|
||||
public class CdnShardConfiguration
|
||||
{
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace MareSynchronosShared.Utils;
|
||||
namespace MareSynchronosShared.Utils.Configuration;
|
||||
|
||||
public interface IMareConfiguration
|
||||
{
|
||||
@@ -2,13 +2,14 @@
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace MareSynchronosShared.Utils;
|
||||
namespace MareSynchronosShared.Utils.Configuration;
|
||||
|
||||
public class MareConfigurationBase : IMareConfiguration
|
||||
{
|
||||
public int DbContextPoolSize { get; set; } = 100;
|
||||
public string Jwt { get; set; } = string.Empty;
|
||||
public Uri MainServerAddress { get; set; }
|
||||
public int RedisPool { get; set; } = 50;
|
||||
public int MetricsPort { get; set; }
|
||||
public string RedisConnectionString { get; set; } = string.Empty;
|
||||
public string ShardName { get; set; } = string.Empty;
|
||||
@@ -1,8 +1,8 @@
|
||||
using System.Text;
|
||||
|
||||
namespace MareSynchronosShared.Utils;
|
||||
namespace MareSynchronosShared.Utils.Configuration;
|
||||
|
||||
public class ServerConfiguration : MareConfigurationAuthBase
|
||||
public class ServerConfiguration : MareConfigurationBase
|
||||
{
|
||||
[RemoteConfiguration]
|
||||
public Uri CdnFullUrl { get; set; } = null;
|
||||
@@ -24,9 +24,6 @@ public class ServerConfiguration : MareConfigurationAuthBase
|
||||
|
||||
[RemoteConfiguration]
|
||||
public int PurgeUnusedAccountsPeriodInDays { get; set; } = 14;
|
||||
public string GeoIPDbCityFile { get; set; } = string.Empty;
|
||||
|
||||
public int RedisPool { get; set; } = 50;
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
@@ -34,14 +31,12 @@ public class ServerConfiguration : MareConfigurationAuthBase
|
||||
sb.AppendLine(base.ToString());
|
||||
sb.AppendLine($"{nameof(CdnFullUrl)} => {CdnFullUrl}");
|
||||
sb.AppendLine($"{nameof(RedisConnectionString)} => {RedisConnectionString}");
|
||||
sb.AppendLine($"{nameof(RedisPool)} => {RedisPool}");
|
||||
sb.AppendLine($"{nameof(ExpectedClientVersion)} => {ExpectedClientVersion}");
|
||||
sb.AppendLine($"{nameof(MaxExistingGroupsByUser)} => {MaxExistingGroupsByUser}");
|
||||
sb.AppendLine($"{nameof(MaxJoinedGroupsByUser)} => {MaxJoinedGroupsByUser}");
|
||||
sb.AppendLine($"{nameof(MaxGroupUserCount)} => {MaxGroupUserCount}");
|
||||
sb.AppendLine($"{nameof(PurgeUnusedAccounts)} => {PurgeUnusedAccounts}");
|
||||
sb.AppendLine($"{nameof(PurgeUnusedAccountsPeriodInDays)} => {PurgeUnusedAccountsPeriodInDays}");
|
||||
sb.AppendLine($"{nameof(GeoIPDbCityFile)} => {GeoIPDbCityFile}");
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
using System.Text;
|
||||
|
||||
namespace MareSynchronosShared.Utils;
|
||||
namespace MareSynchronosShared.Utils.Configuration;
|
||||
|
||||
public class ServicesConfiguration : MareConfigurationBase
|
||||
{
|
||||
@@ -1,14 +1,14 @@
|
||||
using MareSynchronosShared.Utils;
|
||||
using System.Text;
|
||||
|
||||
namespace MareSynchronosStaticFilesServer;
|
||||
namespace MareSynchronosShared.Utils.Configuration;
|
||||
|
||||
public class StaticFilesServerConfiguration : MareConfigurationBase
|
||||
{
|
||||
public bool IsDistributionNode { get; set; } = false;
|
||||
public bool NotifyMainServerDirectly { get; set; } = false;
|
||||
public Uri? MainFileServerAddress { get; set; } = null;
|
||||
public Uri? DistributionFileServerAddress { get; set; } = null;
|
||||
public Uri MainFileServerAddress { get; set; } = null;
|
||||
public Uri DistributionFileServerAddress { get; set; } = null;
|
||||
public bool DistributionFileServerForceHTTP2 { get; set; } = false;
|
||||
public int ForcedDeletionOfFilesAfterHours { get; set; } = -1;
|
||||
public double CacheSizeHardLimitInGiB { get; set; } = -1;
|
||||
@@ -21,7 +21,7 @@ public class StaticFilesServerConfiguration : MareConfigurationBase
|
||||
public int DownloadQueueClearLimit { get; set; } = 15000;
|
||||
public int CleanupCheckInMinutes { get; set; } = 15;
|
||||
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 int ColdStorageMinimumFileRetentionPeriodInDays { get; set; } = 30;
|
||||
public int ColdStorageUnusedFileRetentionPeriodInDays { get; set; } = 30;
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MareSynchronosShared.Utils.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
@@ -9,7 +10,7 @@ namespace MareSynchronosShared.Utils;
|
||||
|
||||
public class ServerTokenGenerator
|
||||
{
|
||||
private readonly IOptionsMonitor<MareConfigurationAuthBase> _configuration;
|
||||
private readonly IOptionsMonitor<MareConfigurationBase> _configuration;
|
||||
private readonly ILogger<ServerTokenGenerator> _logger;
|
||||
|
||||
private Dictionary<string, string> _tokenDictionary { get; set; } = new(StringComparer.Ordinal);
|
||||
@@ -27,7 +28,7 @@ public class ServerTokenGenerator
|
||||
}
|
||||
}
|
||||
|
||||
public ServerTokenGenerator(IOptionsMonitor<MareConfigurationAuthBase> configuration, ILogger<ServerTokenGenerator> logger)
|
||||
public ServerTokenGenerator(IOptionsMonitor<MareConfigurationBase> configuration, ILogger<ServerTokenGenerator> logger)
|
||||
{
|
||||
_configuration = configuration;
|
||||
_logger = logger;
|
||||
|
||||
Reference in New Issue
Block a user