diff --git a/src/Tgstation.Server.Host/Authority/LoginAuthority.cs b/src/Tgstation.Server.Host/Authority/LoginAuthority.cs index b3025d24ed..f0286767e4 100644 --- a/src/Tgstation.Server.Host/Authority/LoginAuthority.cs +++ b/src/Tgstation.Server.Host/Authority/LoginAuthority.cs @@ -62,9 +62,9 @@ namespace Tgstation.Server.Host.Authority readonly ISessionInvalidationTracker sessionInvalidationTracker; /// - /// The for the . + /// The containing the for the . /// - readonly SecurityConfiguration securityConfiguration; + readonly IOptionsSnapshot securityConfigurationOptions; /// /// Generate an for a given . @@ -113,7 +113,7 @@ namespace Tgstation.Server.Host.Authority /// The value of . /// The value of . /// The value of . - /// The containing the value of . + /// The value of . public LoginAuthority( IDatabaseContext databaseContext, ILogger logger, @@ -124,7 +124,7 @@ namespace Tgstation.Server.Host.Authority ICryptographySuite cryptographySuite, IIdentityCache identityCache, ISessionInvalidationTracker sessionInvalidationTracker, - IOptions securityConfigurationOptions) + IOptionsSnapshot securityConfigurationOptions) : base( databaseContext, logger) @@ -136,7 +136,7 @@ namespace Tgstation.Server.Host.Authority this.cryptographySuite = cryptographySuite ?? throw new ArgumentNullException(nameof(cryptographySuite)); this.identityCache = identityCache ?? throw new ArgumentNullException(nameof(identityCache)); this.sessionInvalidationTracker = sessionInvalidationTracker ?? throw new ArgumentNullException(nameof(sessionInvalidationTracker)); - securityConfiguration = securityConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(securityConfigurationOptions)); + this.securityConfigurationOptions = securityConfigurationOptions ?? throw new ArgumentNullException(nameof(securityConfigurationOptions)); } /// @@ -181,7 +181,7 @@ namespace Tgstation.Server.Host.Authority private async ValueTask> AttemptLoginImpl(CancellationToken cancellationToken) { // password and oauth logins disabled - if (securityConfiguration.OidcStrictMode) + if (securityConfigurationOptions.Value.OidcStrictMode) return Unauthorized(); var headers = apiHeadersProvider.ApiHeaders; diff --git a/src/Tgstation.Server.Host/Authority/UserAuthority.cs b/src/Tgstation.Server.Host/Authority/UserAuthority.cs index 5e36e4c87b..1022e79e28 100644 --- a/src/Tgstation.Server.Host/Authority/UserAuthority.cs +++ b/src/Tgstation.Server.Host/Authority/UserAuthority.cs @@ -85,9 +85,9 @@ namespace Tgstation.Server.Host.Authority readonly IOptionsSnapshot generalConfigurationOptions; /// - /// The of for the . + /// The of for the . /// - readonly IOptions securityConfigurationOptions; + readonly IOptionsSnapshot securityConfigurationOptions; /// /// Implements the . @@ -218,7 +218,7 @@ namespace Tgstation.Server.Host.Authority ITopicEventSender topicEventSender, IClaimsPrincipalAccessor claimsPrincipalAccessor, IOptionsSnapshot generalConfigurationOptions, - IOptions securityConfigurationOptions) + IOptionsSnapshot securityConfigurationOptions) : base( databaseContext, logger) diff --git a/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs b/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs index d2fa5724f2..dd6f87b6a3 100644 --- a/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs +++ b/src/Tgstation.Server.Host/Components/Deployment/DreamMaker.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Prometheus; @@ -92,16 +93,16 @@ namespace Tgstation.Server.Host.Components.Deployment /// readonly IAsyncDelayer asyncDelayer; + /// + /// The of for . + /// + readonly IOptionsMonitor sessionConfigurationOptions; + /// /// The for . /// readonly ILogger logger; - /// - /// The for . - /// - readonly SessionConfiguration sessionConfiguration; - /// /// The belongs to. /// @@ -167,8 +168,8 @@ namespace Tgstation.Server.Host.Components.Deployment /// The value of . /// The value of . /// The to use. + /// The value of . /// The value of . - /// The value of . /// The value of . public DreamMaker( IEngineManager engineManager, @@ -183,8 +184,8 @@ namespace Tgstation.Server.Host.Components.Deployment IRemoteDeploymentManagerFactory remoteDeploymentManagerFactory, IAsyncDelayer asyncDelayer, IMetricFactory metricFactory, + IOptionsMonitor sessionConfigurationOptions, ILogger logger, - SessionConfiguration sessionConfiguration, Api.Models.Instance metadata) { this.engineManager = engineManager ?? throw new ArgumentNullException(nameof(engineManager)); @@ -199,8 +200,8 @@ namespace Tgstation.Server.Host.Components.Deployment this.remoteDeploymentManagerFactory = remoteDeploymentManagerFactory ?? throw new ArgumentNullException(nameof(remoteDeploymentManagerFactory)); this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer)); ArgumentNullException.ThrowIfNull(metricFactory); + this.sessionConfigurationOptions = sessionConfigurationOptions ?? throw new ArgumentNullException(nameof(sessionConfigurationOptions)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); - this.sessionConfiguration = sessionConfiguration ?? throw new ArgumentNullException(nameof(sessionConfiguration)); this.metadata = metadata ?? throw new ArgumentNullException(nameof(metadata)); successfulDeployments = metricFactory.CreateCounter("tgs_successful_deployments", "The number of deployments that have completed successfully"); @@ -922,7 +923,7 @@ namespace Tgstation.Server.Host.Components.Deployment readStandardHandles: true, noShellExecute: true); - if (sessionConfiguration.LowPriorityDeploymentProcesses) + if (sessionConfigurationOptions.CurrentValue.LowPriorityDeploymentProcesses) dm.AdjustPriority(false); int exitCode; @@ -1013,7 +1014,7 @@ namespace Tgstation.Server.Host.Components.Deployment { async ValueTask CleanDir() { - if (sessionConfiguration.DelayCleaningFailedDeployments) + if (sessionConfigurationOptions.CurrentValue.DelayCleaningFailedDeployments) { logger.LogDebug("Not cleaning up errored deployment directory {guid} due to config.", job.DirectoryName); return; diff --git a/src/Tgstation.Server.Host/Components/Engine/OpenDreamInstaller.cs b/src/Tgstation.Server.Host/Components/Engine/OpenDreamInstaller.cs index 0491ffab3d..d19af1b58e 100644 --- a/src/Tgstation.Server.Host/Components/Engine/OpenDreamInstaller.cs +++ b/src/Tgstation.Server.Host/Components/Engine/OpenDreamInstaller.cs @@ -91,8 +91,8 @@ namespace Tgstation.Server.Host.Components.Engine /// The value of . /// The value of . /// The value of . - /// The containing value of . - /// The containing value of . + /// The containing value of . + /// The containing value of . public OpenDreamInstaller( IIOManager ioManager, ILogger logger, diff --git a/src/Tgstation.Server.Host/Components/InstanceFactory.cs b/src/Tgstation.Server.Host/Components/InstanceFactory.cs index 67e2b53a52..5118ab5f3e 100644 --- a/src/Tgstation.Server.Host/Components/InstanceFactory.cs +++ b/src/Tgstation.Server.Host/Components/InstanceFactory.cs @@ -150,14 +150,14 @@ namespace Tgstation.Server.Host.Components readonly IMetricFactory metricFactory; /// - /// The for the . + /// The of for the . /// - readonly GeneralConfiguration generalConfiguration; + readonly IOptionsMonitor generalConfigurationOptions; /// - /// The for the . + /// The of for the . /// - readonly SessionConfiguration sessionConfiguration; + readonly IOptionsMonitor sessionConfigurationOptions; /// /// Create the pointing to the "Game" directory of a given . @@ -193,8 +193,8 @@ namespace Tgstation.Server.Host.Components /// The value of . /// The value of . /// The value of . - /// The containing the value of . - /// The containing the value of . + /// The value of . + /// The value of . public InstanceFactory( IIOManager ioManager, IDatabaseContextFactory databaseContextFactory, @@ -219,8 +219,8 @@ namespace Tgstation.Server.Host.Components IAsyncDelayer asyncDelayer, IDotnetDumpService dotnetDumpService, IMetricFactory metricFactory, - IOptions generalConfigurationOptions, - IOptions sessionConfigurationOptions) + IOptionsMonitor generalConfigurationOptions, + IOptionsMonitor sessionConfigurationOptions) { this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager)); this.databaseContextFactory = databaseContextFactory ?? throw new ArgumentNullException(nameof(databaseContextFactory)); @@ -245,8 +245,8 @@ namespace Tgstation.Server.Host.Components this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer)); this.dotnetDumpService = dotnetDumpService ?? throw new ArgumentNullException(nameof(dotnetDumpService)); this.metricFactory = metricFactory ?? throw new ArgumentNullException(nameof(metricFactory)); - generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); - sessionConfiguration = sessionConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(sessionConfigurationOptions)); + this.generalConfigurationOptions = generalConfigurationOptions ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); + this.sessionConfigurationOptions = sessionConfigurationOptions ?? throw new ArgumentNullException(nameof(sessionConfigurationOptions)); } #pragma warning restore CA1502 @@ -291,10 +291,10 @@ namespace Tgstation.Server.Host.Components postWriteHandler, platformIdentifier, fileTransferService, + generalConfigurationOptions, + sessionConfigurationOptions, loggerFactory.CreateLogger(), - metadata, - generalConfiguration, - sessionConfiguration); + metadata); var eventConsumer = new EventConsumer(configuration); var repoManager = repositoryManagerFactory.CreateRepositoryManager(repoIoManager, eventConsumer); try @@ -347,8 +347,8 @@ namespace Tgstation.Server.Host.Components dotnetDumpService, metricFactory, loggerFactory, + sessionConfigurationOptions, loggerFactory.CreateLogger(), - sessionConfiguration, metadata); var watchdog = watchdogFactory.CreateWatchdog( @@ -382,8 +382,8 @@ namespace Tgstation.Server.Host.Components remoteDeploymentManagerFactory, asyncDelayer, metricFactory, + sessionConfigurationOptions, loggerFactory.CreateLogger(), - sessionConfiguration, metadata); instance = new Instance( diff --git a/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs b/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs index 8f10370945..70b66b9798 100644 --- a/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs +++ b/src/Tgstation.Server.Host/Components/Session/SessionControllerFactory.cs @@ -8,6 +8,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Prometheus; @@ -119,16 +120,16 @@ namespace Tgstation.Server.Host.Components.Session /// readonly ILoggerFactory loggerFactory; + /// + /// The of for the . + /// + readonly IOptionsMonitor sessionConfigurationOptions; + /// /// The for the . /// readonly ILogger logger; - /// - /// The for the . - /// - readonly SessionConfiguration sessionConfiguration; - /// /// The number of sessions launched. /// @@ -198,9 +199,9 @@ namespace Tgstation.Server.Host.Components.Session /// The value of . /// The value of . /// The used to create metrics. + /// The value of . /// The value of . /// The value of . - /// The value of . public SessionControllerFactory( IProcessExecutor processExecutor, IEngineManager engineManager, @@ -219,8 +220,8 @@ namespace Tgstation.Server.Host.Components.Session IDotnetDumpService dotnetDumpService, IMetricFactory metricFactory, ILoggerFactory loggerFactory, + IOptionsMonitor sessionConfigurationOptions, ILogger logger, - SessionConfiguration sessionConfiguration, Api.Models.Instance instance) { this.processExecutor = processExecutor ?? throw new ArgumentNullException(nameof(processExecutor)); @@ -239,9 +240,9 @@ namespace Tgstation.Server.Host.Components.Session this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer)); this.dotnetDumpService = dotnetDumpService ?? throw new ArgumentNullException(nameof(dotnetDumpService)); ArgumentNullException.ThrowIfNull(metricFactory); + this.sessionConfigurationOptions = sessionConfigurationOptions ?? throw new ArgumentNullException(nameof(sessionConfigurationOptions)); this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); - this.sessionConfiguration = sessionConfiguration ?? throw new ArgumentNullException(nameof(sessionConfiguration)); this.instance = instance ?? throw new ArgumentNullException(nameof(instance)); sessionsLaunched = metricFactory.CreateCounter("tgs_sessions_launched", "The number of game server processes created"); @@ -567,6 +568,7 @@ namespace Tgstation.Server.Host.Components.Session try { + var sessionConfiguration = sessionConfigurationOptions.CurrentValue; if (!apiValidate) { if (sessionConfiguration.HighPriorityLiveDreamDaemon) diff --git a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs index 6dbfc3cc9c..46a1ca3d92 100644 --- a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs +++ b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs @@ -9,6 +9,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Tgstation.Server.Api.Models; using Tgstation.Server.Api.Models.Response; @@ -119,6 +120,16 @@ namespace Tgstation.Server.Host.Components.StaticFiles /// > readonly IFileTransferTicketProvider fileTransferService; + /// + /// The of for . + /// + readonly IOptionsMonitor generalConfigurationOptions; + + /// + /// The of for . + /// + readonly IOptionsMonitor sessionConfigurationOptions; + /// /// The for . /// @@ -129,16 +140,6 @@ namespace Tgstation.Server.Host.Components.StaticFiles /// readonly Models.Instance metadata; - /// - /// The for . - /// - readonly GeneralConfiguration generalConfiguration; - - /// - /// The for . - /// - readonly SessionConfiguration sessionConfiguration; - /// /// The for . Also used as a . /// @@ -166,8 +167,8 @@ namespace Tgstation.Server.Host.Components.StaticFiles /// The value of . /// The value of . /// The value of . - /// The value of . - /// The value of . + /// The value of . + /// The value of . public Configuration( IIOManager ioManager, ISynchronousIOManager synchronousIOManager, @@ -176,10 +177,10 @@ namespace Tgstation.Server.Host.Components.StaticFiles IPostWriteHandler postWriteHandler, IPlatformIdentifier platformIdentifier, IFileTransferTicketProvider fileTransferService, + IOptionsMonitor generalConfigurationOptions, + IOptionsMonitor sessionConfigurationOptions, ILogger logger, - Models.Instance metadata, - GeneralConfiguration generalConfiguration, - SessionConfiguration sessionConfiguration) + Models.Instance metadata) { this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager)); this.synchronousIOManager = synchronousIOManager ?? throw new ArgumentNullException(nameof(synchronousIOManager)); @@ -188,10 +189,10 @@ namespace Tgstation.Server.Host.Components.StaticFiles this.postWriteHandler = postWriteHandler ?? throw new ArgumentNullException(nameof(postWriteHandler)); this.platformIdentifier = platformIdentifier ?? throw new ArgumentNullException(nameof(platformIdentifier)); this.fileTransferService = fileTransferService ?? throw new ArgumentNullException(nameof(fileTransferService)); + this.generalConfigurationOptions = generalConfigurationOptions ?? throw new ArgumentNullException(nameof(generalConfigurationOptions)); + this.sessionConfigurationOptions = sessionConfigurationOptions ?? throw new ArgumentNullException(nameof(sessionConfigurationOptions)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.metadata = metadata ?? throw new ArgumentNullException(nameof(metadata)); - this.generalConfiguration = generalConfiguration ?? throw new ArgumentNullException(nameof(generalConfiguration)); - this.sessionConfiguration = sessionConfiguration ?? throw new ArgumentNullException(nameof(sessionConfiguration)); semaphore = new SemaphoreSlim(1, 1); stoppingCts = new CancellationTokenSource(); @@ -223,7 +224,7 @@ namespace Tgstation.Server.Host.Components.StaticFiles null, CodeModificationsSubdirectory, destination, - generalConfiguration.GetCopyDirectoryTaskThrottle(), + generalConfigurationOptions.CurrentValue.GetCopyDirectoryTaskThrottle(), cancellationToken); await Task.WhenAll(dmeExistsTask, headFileExistsTask, tailFileExistsTask, copyTask.AsTask()); @@ -795,7 +796,8 @@ namespace Tgstation.Server.Host.Components.StaticFiles // always execute in serial using (await SemaphoreSlimContext.Lock(semaphore, cancellationToken, logger)) { - var directories = generalConfiguration.AdditionalEventScriptsDirectories?.ToList() ?? new List(); + var sessionConfiguration = sessionConfigurationOptions.CurrentValue; + var directories = generalConfigurationOptions.CurrentValue.AdditionalEventScriptsDirectories?.ToList() ?? new List(); directories.Add(EventScriptsSubdirectory); var allScripts = new List(); diff --git a/tests/Tgstation.Server.Host.Tests/Components/StaticFiles/TestConfiguration.cs b/tests/Tgstation.Server.Host.Tests/Components/StaticFiles/TestConfiguration.cs index 7314b0783a..1eeb0bdb30 100644 --- a/tests/Tgstation.Server.Host.Tests/Components/StaticFiles/TestConfiguration.cs +++ b/tests/Tgstation.Server.Host.Tests/Components/StaticFiles/TestConfiguration.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; @@ -56,13 +57,13 @@ namespace Tgstation.Server.Host.Components.StaticFiles.Tests Mock.Of(), Mock.Of(), Mock.Of(), + Mock.Of>(), + Mock.Of>(), loggerFactory.CreateLogger(), new Models.Instance { Path = "Some path", - }, - new GeneralConfiguration(), - new SessionConfiguration()); + }); await configuration.StartAsync(CancellationToken.None);