feat: session A — config binding via appsettings.json (67 stubs complete)
Add JSON attributes to ServerOptions, four custom JSON converters (NatsDurationJsonConverter, TlsVersionJsonConverter, NatsUrlJsonConverter, StorageSizeJsonConverter), ServerOptionsConfiguration for JSON file/string binding, and 15 tests covering config parsing, duration parsing, and size parsing. Mark 67 opts.go features complete in porting.db.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
|
||||
using System.Net.Security;
|
||||
using System.Security.Authentication;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading;
|
||||
using ZB.MOM.NatsNet.Server.Auth;
|
||||
|
||||
@@ -31,20 +32,28 @@ public sealed partial class ServerOptions
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public string ConfigFile { get; set; } = string.Empty;
|
||||
[JsonPropertyName("server_name")]
|
||||
public string ServerName { get; set; } = string.Empty;
|
||||
[JsonPropertyName("host")]
|
||||
public string Host { get; set; } = string.Empty;
|
||||
[JsonPropertyName("port")]
|
||||
public int Port { get; set; }
|
||||
public bool DontListen { get; set; }
|
||||
[JsonPropertyName("client_advertise")]
|
||||
public string ClientAdvertise { get; set; } = string.Empty;
|
||||
public bool CheckConfig { get; set; }
|
||||
[JsonPropertyName("pid_file")]
|
||||
public string PidFile { get; set; } = string.Empty;
|
||||
[JsonPropertyName("ports_file_dir")]
|
||||
public string PortsFileDir { get; set; } = string.Empty;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Logging & Debugging
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
[JsonPropertyName("trace")]
|
||||
public bool Trace { get; set; }
|
||||
[JsonPropertyName("debug")]
|
||||
public bool Debug { get; set; }
|
||||
public bool TraceVerbose { get; set; }
|
||||
public bool TraceHeaders { get; set; }
|
||||
@@ -52,7 +61,9 @@ public sealed partial class ServerOptions
|
||||
public bool NoSigs { get; set; }
|
||||
public bool Logtime { get; set; }
|
||||
public bool LogtimeUtc { get; set; }
|
||||
[JsonPropertyName("logfile")]
|
||||
public string LogFile { get; set; } = string.Empty;
|
||||
[JsonPropertyName("log_size_limit")]
|
||||
public long LogSizeLimit { get; set; }
|
||||
public long LogMaxFiles { get; set; }
|
||||
public bool Syslog { get; set; }
|
||||
@@ -65,11 +76,14 @@ public sealed partial class ServerOptions
|
||||
// Networking & Limits
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
[JsonPropertyName("max_connections")]
|
||||
public int MaxConn { get; set; }
|
||||
public int MaxSubs { get; set; }
|
||||
public byte MaxSubTokens { get; set; }
|
||||
public int MaxControlLine { get; set; }
|
||||
[JsonPropertyName("max_payload")]
|
||||
public int MaxPayload { get; set; }
|
||||
[JsonPropertyName("max_pending")]
|
||||
public long MaxPending { get; set; }
|
||||
public bool NoFastProducerStall { get; set; }
|
||||
public bool ProxyRequired { get; set; }
|
||||
@@ -80,11 +94,16 @@ public sealed partial class ServerOptions
|
||||
// Connectivity
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
[JsonPropertyName("ping_interval")]
|
||||
public TimeSpan PingInterval { get; set; }
|
||||
[JsonPropertyName("ping_max")]
|
||||
public int MaxPingsOut { get; set; }
|
||||
[JsonPropertyName("write_deadline")]
|
||||
public TimeSpan WriteDeadline { get; set; }
|
||||
public WriteTimeoutPolicy WriteTimeout { get; set; }
|
||||
[JsonPropertyName("lame_duck_duration")]
|
||||
public TimeSpan LameDuckDuration { get; set; }
|
||||
[JsonPropertyName("lame_duck_grace_period")]
|
||||
public TimeSpan LameDuckGracePeriod { get; set; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -92,23 +111,33 @@ public sealed partial class ServerOptions
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public string HttpHost { get; set; } = string.Empty;
|
||||
[JsonPropertyName("http_port")]
|
||||
public int HttpPort { get; set; }
|
||||
[JsonPropertyName("http_base_path")]
|
||||
public string HttpBasePath { get; set; } = string.Empty;
|
||||
[JsonPropertyName("https_port")]
|
||||
public int HttpsPort { get; set; }
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Authentication & Authorization
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
[JsonPropertyName("username")]
|
||||
public string Username { get; set; } = string.Empty;
|
||||
[JsonPropertyName("password")]
|
||||
public string Password { get; set; } = string.Empty;
|
||||
[JsonPropertyName("authorization")]
|
||||
public string Authorization { get; set; } = string.Empty;
|
||||
[JsonPropertyName("auth_timeout")]
|
||||
public double AuthTimeout { get; set; }
|
||||
[JsonPropertyName("no_auth_user")]
|
||||
public string NoAuthUser { get; set; } = string.Empty;
|
||||
public string DefaultSentinel { get; set; } = string.Empty;
|
||||
[JsonPropertyName("system_account")]
|
||||
public string SystemAccount { get; set; } = string.Empty;
|
||||
public bool NoSystemAccount { get; set; }
|
||||
/// <summary>Parsed account objects from config. Mirrors Go opts.Accounts.</summary>
|
||||
[JsonPropertyName("accounts")]
|
||||
public List<Account> Accounts { get; set; } = [];
|
||||
public AuthCalloutOpts? AuthCallout { get; set; }
|
||||
public bool AlwaysEnableNonce { get; set; }
|
||||
@@ -148,8 +177,11 @@ public sealed partial class ServerOptions
|
||||
// Cluster / Gateway / Leaf / WebSocket / MQTT
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
[JsonPropertyName("cluster")]
|
||||
public ClusterOpts Cluster { get; set; } = new();
|
||||
[JsonPropertyName("gateway")]
|
||||
public GatewayOpts Gateway { get; set; } = new();
|
||||
[JsonPropertyName("leafnodes")]
|
||||
public LeafNodeOpts LeafNode { get; set; } = new();
|
||||
public WebsocketOpts Websocket { get; set; } = new();
|
||||
public MqttOpts Mqtt { get; set; } = new();
|
||||
@@ -165,6 +197,7 @@ public sealed partial class ServerOptions
|
||||
// JetStream
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
[JsonPropertyName("jetstream")]
|
||||
public bool JetStream { get; set; }
|
||||
public bool NoJetStreamStrict { get; set; }
|
||||
public long JetStreamMaxMemory { get; set; }
|
||||
@@ -184,6 +217,7 @@ public sealed partial class ServerOptions
|
||||
public bool JetStreamMetaCompactSync { get; set; }
|
||||
public int StreamMaxBufferedMsgs { get; set; }
|
||||
public long StreamMaxBufferedSize { get; set; }
|
||||
[JsonPropertyName("store_dir")]
|
||||
public string StoreDir { get; set; } = string.Empty;
|
||||
public TimeSpan SyncInterval { get; set; }
|
||||
public bool SyncAlways { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user