149 lines
4.5 KiB
C#
149 lines
4.5 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace StellaOps.Notify.WebService.Options;
|
|
|
|
/// <summary>
|
|
/// Strongly typed configuration for the Notify WebService host.
|
|
/// </summary>
|
|
public sealed class NotifyWebServiceOptions
|
|
{
|
|
public const string SectionName = "notify";
|
|
|
|
/// <summary>
|
|
/// Schema version that downstream consumers can use to detect breaking changes.
|
|
/// </summary>
|
|
public int SchemaVersion { get; set; } = 1;
|
|
|
|
/// <summary>
|
|
/// Authority / authentication configuration.
|
|
/// </summary>
|
|
public AuthorityOptions Authority { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// Mongo storage configuration for configuration state and audit logs.
|
|
/// </summary>
|
|
public StorageOptions Storage { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// Plug-in loader configuration.
|
|
/// </summary>
|
|
public PluginOptions Plugins { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// HTTP API behaviour.
|
|
/// </summary>
|
|
public ApiOptions Api { get; set; } = new();
|
|
|
|
/// <summary>
|
|
/// Telemetry configuration toggles.
|
|
/// </summary>
|
|
public TelemetryOptions Telemetry { get; set; } = new();
|
|
|
|
public sealed class AuthorityOptions
|
|
{
|
|
public bool Enabled { get; set; } = true;
|
|
|
|
public bool AllowAnonymousFallback { get; set; }
|
|
|
|
public string Issuer { get; set; } = "https://authority.local";
|
|
|
|
public string? MetadataAddress { get; set; }
|
|
|
|
public bool RequireHttpsMetadata { get; set; } = true;
|
|
|
|
public int BackchannelTimeoutSeconds { get; set; } = 30;
|
|
|
|
public int TokenClockSkewSeconds { get; set; } = 60;
|
|
|
|
public IList<string> Audiences { get; set; } = new List<string> { "notify" };
|
|
|
|
public string ReadScope { get; set; } = "notify.read";
|
|
|
|
public string AdminScope { get; set; } = "notify.admin";
|
|
|
|
/// <summary>
|
|
/// Optional development signing key for symmetric JWT validation when Authority is disabled.
|
|
/// </summary>
|
|
public string? DevelopmentSigningKey { get; set; }
|
|
}
|
|
|
|
public sealed class StorageOptions
|
|
{
|
|
public string Driver { get; set; } = "mongo";
|
|
|
|
public string ConnectionString { get; set; } = string.Empty;
|
|
|
|
public string Database { get; set; } = "notify";
|
|
|
|
public int CommandTimeoutSeconds { get; set; } = 30;
|
|
}
|
|
|
|
public sealed class PluginOptions
|
|
{
|
|
public string? BaseDirectory { get; set; }
|
|
|
|
public string? Directory { get; set; }
|
|
|
|
public IList<string> SearchPatterns { get; set; } = new List<string>();
|
|
|
|
public IList<string> OrderedPlugins { get; set; } = new List<string>();
|
|
}
|
|
|
|
public sealed class ApiOptions
|
|
{
|
|
public string BasePath { get; set; } = "/api/v1/notify";
|
|
|
|
public string InternalBasePath { get; set; } = "/internal/notify";
|
|
|
|
public string TenantHeader { get; set; } = "X-StellaOps-Tenant";
|
|
|
|
public RateLimitOptions RateLimits { get; set; } = new();
|
|
}
|
|
|
|
public sealed class RateLimitOptions
|
|
{
|
|
public RateLimitPolicyOptions DeliveryHistory { get; set; } = RateLimitPolicyOptions.CreateDefault(
|
|
tokenLimit: 60,
|
|
tokensPerPeriod: 30,
|
|
replenishmentPeriodSeconds: 60,
|
|
queueLimit: 20);
|
|
|
|
public RateLimitPolicyOptions TestSend { get; set; } = RateLimitPolicyOptions.CreateDefault(
|
|
tokenLimit: 5,
|
|
tokensPerPeriod: 5,
|
|
replenishmentPeriodSeconds: 60,
|
|
queueLimit: 2);
|
|
}
|
|
|
|
public sealed class RateLimitPolicyOptions
|
|
{
|
|
public bool Enabled { get; set; } = true;
|
|
|
|
public int TokenLimit { get; set; } = 10;
|
|
|
|
public int TokensPerPeriod { get; set; } = 10;
|
|
|
|
public int ReplenishmentPeriodSeconds { get; set; } = 60;
|
|
|
|
public int QueueLimit { get; set; } = 0;
|
|
|
|
public static RateLimitPolicyOptions CreateDefault(int tokenLimit, int tokensPerPeriod, int replenishmentPeriodSeconds, int queueLimit)
|
|
{
|
|
return new RateLimitPolicyOptions
|
|
{
|
|
TokenLimit = tokenLimit,
|
|
TokensPerPeriod = tokensPerPeriod,
|
|
ReplenishmentPeriodSeconds = replenishmentPeriodSeconds,
|
|
QueueLimit = queueLimit
|
|
};
|
|
}
|
|
}
|
|
|
|
public sealed class TelemetryOptions
|
|
{
|
|
public bool EnableRequestLogging { get; set; } = true;
|
|
|
|
public string MinimumLogLevel { get; set; } = "Information";
|
|
}
|
|
}
|