feat(options): eager startup validation for edge/management options (InboundAPI, ESG, Notification, ManagementService) (arch-review 08 §1.5)

Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
This commit is contained in:
Joseph Doherty
2026-07-10 06:52:59 -04:00
parent 8b775f4ae1
commit fc918d4679
16 changed files with 404 additions and 4 deletions
@@ -0,0 +1,31 @@
using ZB.MOM.WW.Configuration;
namespace ZB.MOM.WW.ScadaBridge.InboundAPI;
/// <summary>
/// Validates <see cref="InboundApiOptions"/> at startup. <see cref="InboundApiOptions.DefaultMethodTimeout"/>
/// bounds each inbound-API method execution and <see cref="InboundApiOptions.MaxRequestBodyBytes"/> caps the
/// accepted <c>POST /api/{methodName}</c> body before it is buffered — a zero/negative timeout would cancel
/// every request immediately (or never), and a non-positive body cap would reject every request with HTTP 413.
/// Registered with <c>ValidateOnStart()</c> so a bad <c>ScadaBridge:InboundApi</c> section fails fast at boot
/// with a clear, key-naming message rather than degrading the endpoint at runtime.
/// <para>
/// <see cref="InboundApiOptions.ApiKeyPepper"/> is intentionally NOT validated here: an empty pepper is a
/// legitimate dev default, and production pepper strength is owned by the shared auth-key library / startup
/// validator, not by this options validator.
/// </para>
/// </summary>
public sealed class InboundApiOptionsValidator : OptionsValidatorBase<InboundApiOptions>
{
/// <inheritdoc />
protected override void Validate(ValidationBuilder builder, InboundApiOptions options)
{
builder.RequireThat(options.DefaultMethodTimeout > TimeSpan.Zero,
$"ScadaBridge:InboundApi:DefaultMethodTimeout must be a positive duration " +
$"(was {options.DefaultMethodTimeout}); it bounds each inbound-API method execution.");
builder.RequireThat(options.MaxRequestBodyBytes > 0,
$"ScadaBridge:InboundApi:MaxRequestBodyBytes must be greater than zero " +
$"(was {options.MaxRequestBodyBytes}); it caps the accepted request body before buffering.");
}
}
@@ -32,6 +32,7 @@
AddZbApiKeyAuth (DI helper) lives in this package and brings the
Abstractions contracts (IApiKeyVerifier / ApiKeyOptions) transitively. -->
<PackageReference Include="ZB.MOM.WW.Auth.ApiKeys" />
<PackageReference Include="ZB.MOM.WW.Configuration" />
</ItemGroup>
</Project>