More options conversions

This commit is contained in:
Jordan Dominion
2025-08-16 01:01:47 -04:00
parent a3a5d82904
commit 2e0d1f5422
7 changed files with 56 additions and 58 deletions
@@ -4,6 +4,7 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Prometheus;
@@ -28,9 +29,9 @@ namespace Tgstation.Server.Host.Components.Watchdog
sealed class PosixWatchdog : AdvancedWatchdog
{
/// <summary>
/// The <see cref="GeneralConfiguration"/> for the <see cref="PosixWatchdog"/>.
/// The <see cref="IOptionsMonitor{TOptions}"/> of <see cref="GeneralConfiguration"/> for the <see cref="PosixWatchdog"/>.
/// </summary>
readonly GeneralConfiguration generalConfiguration;
readonly IOptionsMonitor<GeneralConfiguration> generalConfigurationOptions;
/// <summary>
/// Initializes a new instance of the <see cref="PosixWatchdog"/> class.
@@ -48,10 +49,10 @@ namespace Tgstation.Server.Host.Components.Watchdog
/// <param name="metricFactory">The <see cref="IMetricFactory"/> for the <see cref="WatchdogBase"/>.</param>
/// <param name="gameIOManager">The <see cref="IIOManager"/> pointing to the game directory for the <see cref="AdvancedWatchdog"/>..</param>
/// <param name="linkFactory">The <see cref="IFilesystemLinkFactory"/> for the <see cref="AdvancedWatchdog"/>.</param>
/// <param name="generalConfigurationOptions">The value of <see cref="generalConfigurationOptions"/>.</param>
/// <param name="logger">The <see cref="ILogger"/> for the <see cref="WatchdogBase"/>.</param>
/// <param name="initialLaunchParameters">The <see cref="DreamDaemonLaunchParameters"/> for the <see cref="WatchdogBase"/>.</param>
/// <param name="instance">The <see cref="Api.Models.Instance"/> for the <see cref="WatchdogBase"/>.</param>
/// <param name="generalConfiguration">The value of <see cref="GeneralConfiguration"/>.</param>
/// <param name="autoStart">The autostart value for the <see cref="WatchdogBase"/>.</param>
public PosixWatchdog(
IChatManager chat,
@@ -67,10 +68,10 @@ namespace Tgstation.Server.Host.Components.Watchdog
IMetricFactory metricFactory,
IIOManager gameIOManager,
IFilesystemLinkFactory linkFactory,
IOptionsMonitor<GeneralConfiguration> generalConfigurationOptions,
ILogger<PosixWatchdog> logger,
DreamDaemonLaunchParameters initialLaunchParameters,
Api.Models.Instance instance,
GeneralConfiguration generalConfiguration,
bool autoStart)
: base(
chat,
@@ -91,7 +92,7 @@ namespace Tgstation.Server.Host.Components.Watchdog
instance,
autoStart)
{
this.generalConfiguration = generalConfiguration ?? throw new ArgumentNullException(nameof(generalConfiguration));
this.generalConfigurationOptions = generalConfigurationOptions ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
}
/// <inheritdoc />
@@ -100,6 +101,12 @@ namespace Tgstation.Server.Host.Components.Watchdog
/// <inheritdoc />
protected override SwappableDmbProvider CreateSwappableDmbProvider(IDmbProvider dmbProvider)
=> new HardLinkDmbProvider(dmbProvider, GameIOManager, LinkFactory, Logger, generalConfiguration, ActiveLaunchParameters.SecurityLevel!.Value);
=> new HardLinkDmbProvider(
dmbProvider,
GameIOManager,
LinkFactory,
Logger,
generalConfigurationOptions.CurrentValue,
ActiveLaunchParameters.SecurityLevel!.Value);
}
}
@@ -34,14 +34,14 @@ namespace Tgstation.Server.Host.Components.Watchdog
/// <param name="jobManager">The <see cref="IJobManager"/> for the <see cref="WatchdogFactory"/>.</param>
/// <param name="asyncDelayer">The <see cref="IAsyncDelayer"/> for the <see cref="WatchdogFactory"/>.</param>
/// <param name="linkFactory">The <see cref="IFilesystemLinkFactory"/> for the <see cref="WindowsWatchdogFactory"/>.</param>
/// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> for <see cref="GeneralConfiguration"/> for the <see cref="WatchdogFactory"/>.</param>
/// <param name="generalConfigurationOptions">The <see cref="IOptionsMonitor{TOptions}"/> of <see cref="GeneralConfiguration"/> for the <see cref="WatchdogFactory"/>.</param>
public PosixWatchdogFactory(
IServerControl serverControl,
ILoggerFactory loggerFactory,
IJobManager jobManager,
IAsyncDelayer asyncDelayer,
IFilesystemLinkFactory linkFactory,
IOptions<GeneralConfiguration> generalConfigurationOptions)
IOptionsMonitor<GeneralConfiguration> generalConfigurationOptions)
: base(
serverControl,
loggerFactory,
@@ -79,10 +79,10 @@ namespace Tgstation.Server.Host.Components.Watchdog
metricFactory,
gameIOManager,
LinkFactory,
GeneralConfigurationOptions,
LoggerFactory.CreateLogger<PosixWatchdog>(),
settings,
instance,
GeneralConfiguration,
settings.AutoStart ?? throw new ArgumentNullException(nameof(settings)));
}
}
@@ -43,9 +43,9 @@ namespace Tgstation.Server.Host.Components.Watchdog
protected IAsyncDelayer AsyncDelayer { get; }
/// <summary>
/// The <see cref="Configuration.GeneralConfiguration"/> for the <see cref="WatchdogFactory"/>.
/// The <see cref="IOptionsMonitor{TOptions}"/> of <see cref="GeneralConfiguration"/> for the <see cref="WatchdogFactory"/>.
/// </summary>
protected GeneralConfiguration GeneralConfiguration { get; }
protected IOptionsMonitor<GeneralConfiguration> GeneralConfigurationOptions { get; }
/// <summary>
/// Initializes a new instance of the <see cref="WatchdogFactory"/> class.
@@ -54,19 +54,19 @@ namespace Tgstation.Server.Host.Components.Watchdog
/// <param name="loggerFactory">The value of <see cref="LoggerFactory"/>.</param>
/// <param name="jobManager">The value of <see cref="JobManager"/>.</param>
/// <param name="asyncDelayer">The value of <see cref="AsyncDelayer"/>.</param>
/// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="GeneralConfiguration"/>.</param>
/// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="GeneralConfigurationOptions"/>.</param>
public WatchdogFactory(
IServerControl serverControl,
ILoggerFactory loggerFactory,
IJobManager jobManager,
IAsyncDelayer asyncDelayer,
IOptions<GeneralConfiguration> generalConfigurationOptions)
IOptionsMonitor<GeneralConfiguration> generalConfigurationOptions)
{
ServerControl = serverControl ?? throw new ArgumentNullException(nameof(serverControl));
LoggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
JobManager = jobManager ?? throw new ArgumentNullException(nameof(jobManager));
AsyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer));
GeneralConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
GeneralConfigurationOptions = generalConfigurationOptions ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
}
/// <inheritdoc />
@@ -37,14 +37,14 @@ namespace Tgstation.Server.Host.Components.Watchdog
/// <param name="jobManager">The <see cref="IJobManager"/> for the <see cref="WatchdogFactory"/>.</param>
/// <param name="asyncDelayer">The <see cref="IAsyncDelayer"/> for the <see cref="WatchdogFactory"/>.</param>
/// <param name="symlinkFactory">The value of <see cref="LinkFactory"/>.</param>
/// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> for <see cref="GeneralConfiguration"/> for the <see cref="WatchdogFactory"/>.</param>
/// <param name="generalConfigurationOptions">The <see cref="IOptionsMonitor{TOptions}"/> for <see cref="GeneralConfiguration"/> for the <see cref="WatchdogFactory"/>.</param>
public WindowsWatchdogFactory(
IServerControl serverControl,
ILoggerFactory loggerFactory,
IJobManager jobManager,
IAsyncDelayer asyncDelayer,
IFilesystemLinkFactory symlinkFactory,
IOptions<GeneralConfiguration> generalConfigurationOptions)
IOptionsMonitor<GeneralConfiguration> generalConfigurationOptions)
: base(
serverControl,
loggerFactory,
@@ -21,7 +21,6 @@ using Tgstation.Server.Host.Database;
using Tgstation.Server.Host.IO;
using Tgstation.Server.Host.Security;
using Tgstation.Server.Host.System;
using Tgstation.Server.Host.Transfer;
using Tgstation.Server.Host.Utils;
namespace Tgstation.Server.Host.Controllers
@@ -54,14 +53,9 @@ namespace Tgstation.Server.Host.Controllers
readonly IPlatformIdentifier platformIdentifier;
/// <summary>
/// The <see cref="IFileTransferTicketProvider"/> for the <see cref="AdministrationController"/>.
/// The <see cref="IOptions{TOptions}"/> <see cref="FileLoggingConfiguration"/> for the <see cref="AdministrationController"/>.
/// </summary>
readonly IFileTransferTicketProvider fileTransferService;
/// <summary>
/// The <see cref="FileLoggingConfiguration"/> for the <see cref="AdministrationController"/>.
/// </summary>
readonly FileLoggingConfiguration fileLoggingConfiguration;
readonly IOptions<FileLoggingConfiguration> fileLoggingConfigurationOptions;
/// <summary>
/// Initializes a new instance of the <see cref="AdministrationController"/> class.
@@ -74,8 +68,7 @@ namespace Tgstation.Server.Host.Controllers
/// <param name="assemblyInformationProvider">The value of <see cref="assemblyInformationProvider"/>.</param>
/// <param name="ioManager">The value of <see cref="ioManager"/>.</param>
/// <param name="platformIdentifier">The value of <see cref="platformIdentifier"/>.</param>
/// <param name="fileTransferService">The value of <see cref="fileTransferService"/>.</param>
/// <param name="fileLoggingConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing value of <see cref="fileLoggingConfiguration"/>.</param>
/// <param name="fileLoggingConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing value of <see cref="fileLoggingConfigurationOptions"/>.</param>
public AdministrationController(
IDatabaseContext databaseContext,
IAuthenticationContext authenticationContext,
@@ -85,7 +78,6 @@ namespace Tgstation.Server.Host.Controllers
IAssemblyInformationProvider assemblyInformationProvider,
IIOManager ioManager,
IPlatformIdentifier platformIdentifier,
IFileTransferTicketProvider fileTransferService,
IOptions<FileLoggingConfiguration> fileLoggingConfigurationOptions)
: base(
databaseContext,
@@ -98,8 +90,7 @@ namespace Tgstation.Server.Host.Controllers
this.assemblyInformationProvider = assemblyInformationProvider ?? throw new ArgumentNullException(nameof(assemblyInformationProvider));
this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
this.platformIdentifier = platformIdentifier ?? throw new ArgumentNullException(nameof(platformIdentifier));
this.fileTransferService = fileTransferService ?? throw new ArgumentNullException(nameof(fileTransferService));
fileLoggingConfiguration = fileLoggingConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(fileLoggingConfigurationOptions));
this.fileLoggingConfigurationOptions = fileLoggingConfigurationOptions ?? throw new ArgumentNullException(nameof(fileLoggingConfigurationOptions));
}
/// <summary>
@@ -185,7 +176,7 @@ namespace Tgstation.Server.Host.Controllers
=> Paginated(
async () =>
{
var path = fileLoggingConfiguration.GetFullLogDirectory(ioManager, assemblyInformationProvider, platformIdentifier);
var path = fileLoggingConfigurationOptions.Value.GetFullLogDirectory(ioManager, assemblyInformationProvider, platformIdentifier);
try
{
var files = await ioManager.GetFiles(path, cancellationToken);
@@ -65,14 +65,14 @@ namespace Tgstation.Server.Host.Controllers
readonly IRestAuthorityInvoker<ILoginAuthority> loginAuthority;
/// <summary>
/// The <see cref="GeneralConfiguration"/> for the <see cref="ApiRootController"/>.
/// The <see cref="IOptionsSnapshot{TOptions}"/> of <see cref="GeneralConfiguration"/> for the <see cref="ApiRootController"/>.
/// </summary>
readonly GeneralConfiguration generalConfiguration;
readonly IOptionsSnapshot<GeneralConfiguration> generalConfigurationOptions;
/// <summary>
/// The <see cref="SecurityConfiguration"/> for the <see cref="ApiRootController"/>.
/// The <see cref="IOptionsSnapshot{TOptions}"/> of <see cref="SecurityConfiguration"/> for the <see cref="ApiRootController"/>.
/// </summary>
readonly SecurityConfiguration securityConfiguration;
readonly IOptionsSnapshot<SecurityConfiguration> securityConfigurationOptions;
/// <summary>
/// Initializes a new instance of the <see cref="ApiRootController"/> class.
@@ -84,8 +84,8 @@ namespace Tgstation.Server.Host.Controllers
/// <param name="platformIdentifier">The value of <see cref="platformIdentifier"/>.</param>
/// <param name="swarmService">The value of <see cref="swarmService"/>.</param>
/// <param name="serverControl">The value of <see cref="serverControl"/>.</param>
/// <param name="generalConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="generalConfiguration"/>.</param>
/// <param name="securityConfigurationOptions">The <see cref="IOptionsSnapshot{TOptions}"/> containing the value of <see cref="securityConfiguration"/>.</param>
/// <param name="generalConfigurationOptions">The value of <see cref="generalConfigurationOptions"/>.</param>
/// <param name="securityConfigurationOptions">The value of <see cref="securityConfigurationOptions"/>.</param>
/// <param name="logger">The <see cref="ILogger"/> for the <see cref="ApiController"/>.</param>
/// <param name="apiHeadersProvider">The <see cref="IApiHeadersProvider"/> for the <see cref="ApiController"/>.</param>
/// <param name="loginAuthority">The value of <see cref="loginAuthority"/>.</param>
@@ -97,7 +97,7 @@ namespace Tgstation.Server.Host.Controllers
IPlatformIdentifier platformIdentifier,
ISwarmService swarmService,
IServerControl serverControl,
IOptions<GeneralConfiguration> generalConfigurationOptions,
IOptionsSnapshot<GeneralConfiguration> generalConfigurationOptions,
IOptionsSnapshot<SecurityConfiguration> securityConfigurationOptions,
ILogger<ApiRootController> logger,
IApiHeadersProvider apiHeadersProvider,
@@ -114,8 +114,8 @@ namespace Tgstation.Server.Host.Controllers
this.oAuthProviders = oAuthProviders ?? throw new ArgumentNullException(nameof(oAuthProviders));
this.swarmService = swarmService ?? throw new ArgumentNullException(nameof(swarmService));
this.serverControl = serverControl ?? throw new ArgumentNullException(nameof(serverControl));
generalConfiguration = generalConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
securityConfiguration = securityConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(securityConfigurationOptions));
this.generalConfigurationOptions = generalConfigurationOptions ?? throw new ArgumentNullException(nameof(generalConfigurationOptions));
this.securityConfigurationOptions = securityConfigurationOptions ?? throw new ArgumentNullException(nameof(securityConfigurationOptions));
this.loginAuthority = loginAuthority ?? throw new ArgumentNullException(nameof(loginAuthority));
}
@@ -157,20 +157,20 @@ namespace Tgstation.Server.Host.Controllers
Version = assemblyInformationProvider.Version,
ApiVersion = ApiHeaders.Version,
DMApiVersion = DMApiConstants.InteropVersion,
MinimumPasswordLength = generalConfiguration.MinimumPasswordLength,
InstanceLimit = generalConfiguration.InstanceLimit,
UserLimit = generalConfiguration.UserLimit,
UserGroupLimit = generalConfiguration.UserGroupLimit,
ValidInstancePaths = generalConfiguration.ValidInstancePaths,
MinimumPasswordLength = generalConfigurationOptions.Value.MinimumPasswordLength,
InstanceLimit = generalConfigurationOptions.Value.InstanceLimit,
UserLimit = generalConfigurationOptions.Value.UserLimit,
UserGroupLimit = generalConfigurationOptions.Value.UserGroupLimit,
ValidInstancePaths = generalConfigurationOptions.Value.ValidInstancePaths,
WindowsHost = platformIdentifier.IsWindows,
SwarmServers = swarmService
.GetSwarmServers()
?.Select(swarmServerInfo => new SwarmServerResponse(swarmServerInfo))
.ToList(),
OAuthProviderInfos = oAuthProviders.ProviderInfos(),
OidcProviderInfos = securityConfiguration.OidcProviderInfos().ToList(),
OidcProviderInfos = securityConfigurationOptions.Value.OidcProviderInfos().ToList(),
UpdateInProgress = serverControl.UpdateInProgress,
OidcStrictMode = securityConfiguration.OidcStrictMode,
OidcStrictMode = securityConfigurationOptions.Value.OidcStrictMode,
});
}
@@ -45,29 +45,29 @@ namespace Tgstation.Server.Host.Controllers
/// </summary>
readonly IWebHostEnvironment hostEnvironment;
/// <summary>
/// The <see cref="ControlPanelConfiguration"/> for the <see cref="ControlPanelController"/>.
/// </summary>
readonly IOptionsSnapshot<ControlPanelConfiguration> controlPanelConfigurationOptions;
/// <summary>
/// The <see cref="ILogger"/> for the <see cref="ControlPanelController"/>.
/// </summary>
readonly ILogger<ControlPanelController> logger;
/// <summary>
/// The <see cref="ControlPanelConfiguration"/> for the <see cref="ControlPanelController"/>.
/// </summary>
readonly ControlPanelConfiguration controlPanelConfiguration;
/// <summary>
/// Initializes a new instance of the <see cref="ControlPanelController"/> class.
/// </summary>
/// <param name="hostEnvironment">The value of <see cref="hostEnvironment"/>.</param>
/// <param name="controlPanelConfigurationOptions">The <see cref="IOptions{TOptions}"/> containing the value of <see cref="controlPanelConfiguration"/>.</param>
/// <param name="controlPanelConfigurationOptions">The value of <see cref="controlPanelConfigurationOptions"/>.</param>
/// <param name="logger">The value of <see cref="logger"/>.</param>
public ControlPanelController(
IWebHostEnvironment hostEnvironment,
IOptions<ControlPanelConfiguration> controlPanelConfigurationOptions,
IOptionsSnapshot<ControlPanelConfiguration> controlPanelConfigurationOptions,
ILogger<ControlPanelController> logger)
{
this.hostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment));
controlPanelConfiguration = controlPanelConfigurationOptions?.Value ?? throw new ArgumentNullException(nameof(controlPanelConfigurationOptions));
this.controlPanelConfigurationOptions = controlPanelConfigurationOptions ?? throw new ArgumentNullException(nameof(controlPanelConfigurationOptions));
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
}
@@ -79,13 +79,13 @@ namespace Tgstation.Server.Host.Controllers
[HttpGet]
public IActionResult GetChannelJson()
{
if (!controlPanelConfiguration.Enable)
if (!controlPanelConfigurationOptions.Value.Enable)
{
logger.LogDebug("Not serving channel.json as control panel is disabled.");
return NotFound();
}
var controlPanelChannel = controlPanelConfiguration.Channel;
var controlPanelChannel = controlPanelConfigurationOptions.Value.Channel;
logger.LogTrace("Generating channel.json for channel \"{channel}\"...", controlPanelChannel);
if (controlPanelChannel == "local")
@@ -102,7 +102,7 @@ namespace Tgstation.Server.Host.Controllers
{
FormatVersion = 1,
Channel = controlPanelChannel,
controlPanelConfiguration.PublicPath,
controlPanelConfigurationOptions.Value.PublicPath,
});
}
@@ -132,7 +132,7 @@ namespace Tgstation.Server.Host.Controllers
[HttpGet]
public IActionResult Get([FromRoute] string appRoute)
{
if (!controlPanelConfiguration.Enable)
if (!controlPanelConfigurationOptions.Value.Enable)
{
logger.LogDebug("Not serving static files as control panel is disabled.");
return NotFound();