From e8e3a4aa80fbcca9cf8c841c94ff73396c662352 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 27 Jan 2026 19:48:55 -0600 Subject: wip --- src/slskd/Program.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index d6873dc0..16cfe6c9 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -244,6 +244,7 @@ namespace slskd private static ILogger Log { get; set; } = new ConsoleWriteLineLogger(); private static Mutex Mutex { get; set; } private static IDisposable DotNetRuntimeStats { get; set; } + private static VolatileOverlayConfigurationSource VolatileOverlayConfigurationSource { get; set; } = new VolatileOverlayConfigurationSource(); [Argument('g', "generate-cert", "generate X509 certificate and password for HTTPs")] private static bool GenerateCertificate { get; set; } @@ -269,6 +270,8 @@ namespace slskd /// An optional exit code. public static void Exit(int code = 1) => Environment.Exit(code); + public static void ApplyConfigurationOverlay(OptionsOverlay overlay) => VolatileOverlayConfigurationSource.Apply(overlay); + /// /// Entrypoint. /// @@ -1281,7 +1284,8 @@ namespace slskd .AddCommandLine( targetType: typeof(Options), multiValuedArguments, - commandLine: Environment.CommandLine); + commandLine: Environment.CommandLine) + .Add(VolatileOverlayConfigurationSource); } private static IServiceCollection AddDbContext(this IServiceCollection services, string connectionString) -- cgit v1.2.3 From 94c6943c23e6b3c6cb6efb8a8ca45055b9153d58 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 29 Jan 2026 08:03:42 -0600 Subject: more docs --- src/slskd/Program.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 16cfe6c9..143cd460 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -270,6 +270,10 @@ namespace slskd /// An optional exit code. public static void Exit(int code = 1) => Environment.Exit(code); + /// + /// Apply an instance of on top of the existing application configuration. + /// + /// The overlay containing the property values to be overlaid. public static void ApplyConfigurationOverlay(OptionsOverlay overlay) => VolatileOverlayConfigurationSource.Apply(overlay); /// @@ -1285,7 +1289,7 @@ namespace slskd targetType: typeof(Options), multiValuedArguments, commandLine: Environment.CommandLine) - .Add(VolatileOverlayConfigurationSource); + .Add(VolatileOverlayConfigurationSource); // this must come last in order to supersede all other sources } private static IServiceCollection AddDbContext(this IServiceCollection services, string connectionString) -- cgit v1.2.3 From a631b5fbeaaf4e21c0a0a3c266d94d710eb4ffd7 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 29 Jan 2026 18:31:09 -0600 Subject: use /overlay endpoints --- .../Core/API/Controllers/OptionsController.cs | 33 ++++++++++++++-------- src/slskd/Program.cs | 5 ++++ 2 files changed, 26 insertions(+), 12 deletions(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Core/API/Controllers/OptionsController.cs b/src/slskd/Core/API/Controllers/OptionsController.cs index 291ae561..bfbb2dd7 100644 --- a/src/slskd/Core/API/Controllers/OptionsController.cs +++ b/src/slskd/Core/API/Controllers/OptionsController.cs @@ -42,18 +42,15 @@ namespace slskd.Core.API public class OptionsController : ControllerBase { public OptionsController( - IApplication application, OptionsAtStartup optionsAtStartup, IOptionsSnapshot optionsSnapshot, IStateMutator stateMutator) { - Application = application; OptionsAtStartup = optionsAtStartup; OptionsSnapshot = optionsSnapshot; StateMutator = stateMutator; } - private IApplication Application { get; } private IOptionsSnapshot OptionsSnapshot { get; } private OptionsAtStartup OptionsAtStartup { get; } private IStateMutator StateMutator { get; } @@ -72,21 +69,21 @@ namespace slskd.Core.API } /// - /// Patch the application options with new values. + /// Overlay the application options with new values. /// - /// The patch to apply. + /// The overlay to apply. /// - [HttpPatch] + [HttpPut("overlay")] [Authorize(Policy = AuthPolicy.Any)] [ProducesResponseType(typeof(Options), 200)] - public IActionResult Patch([FromBody] OptionsOverlay patch) + public IActionResult ApplyOverlay([FromBody] OptionsOverlay overlay) { - if (patch is null) + if (overlay is null) { return NoContent(); } - if (!patch.TryValidate(out var result)) + if (!overlay.TryValidate(out var result)) { var error = Regex.Replace(result.GetResultView().ToString(), @"\s+", " ").Trim(); Logger.Warning("Options patch validation failed: {Message}", error); @@ -95,15 +92,14 @@ namespace slskd.Core.API try { - Program.ApplyConfigurationOverlay(patch); + Program.ApplyConfigurationOverlay(overlay); + return Ok(OptionsSnapshot.Value.Redact()); } catch (Exception ex) { Logger.Error(ex, "Failed to apply options patch: {Message}", ex.Message); return StatusCode(500, $"Failed to apply options patch: {ex.Message}"); } - - return Ok(OptionsSnapshot.Value.Redact()); } /// @@ -119,6 +115,19 @@ namespace slskd.Core.API return Ok(OptionsAtStartup.Redact()); } + /// + /// Gets the current application option overlay, if one has been applied. + /// + /// + [HttpGet] + [Route("overlay")] + [Authorize(Policy = AuthPolicy.Any)] + [ProducesResponseType(typeof(OptionsOverlay), 200)] + public IActionResult GetOverlay() + { + return Ok(Program.ConfigurationOverlay?.Redact()); + } + /// /// Gets the debug view of the current application options. /// diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 143cd460..3b4cdb73 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -189,6 +189,11 @@ namespace slskd [EnvironmentVariable("CONFIG")] public static string ConfigurationFile { get; private set; } = null; + /// + /// Gets the current configuration overlay, if one has been applied. + /// + public static OptionsOverlay ConfigurationOverlay { get; private set; } = VolatileOverlayConfigurationSource?.CurrentValue; + /// /// Gets the path where persistent data is saved. /// -- cgit v1.2.3 From 3989f893139b078227caec8677de095435191a61 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Thu, 29 Jan 2026 19:37:13 -0600 Subject: oops --- src/slskd/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 3b4cdb73..75c51355 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -192,7 +192,7 @@ namespace slskd /// /// Gets the current configuration overlay, if one has been applied. /// - public static OptionsOverlay ConfigurationOverlay { get; private set; } = VolatileOverlayConfigurationSource?.CurrentValue; + public static OptionsOverlay ConfigurationOverlay => VolatileOverlayConfigurationSource?.CurrentValue; /// /// Gets the path where persistent data is saved. -- cgit v1.2.3