ddad573b75
- Resolve 14 conflicts from popping local stash on top of origin'seed1e88+8d3352fdoc-comment additions (11 mechanical, plus version.rs, DashboardAuthenticatorTests.cs, DashboardGalaxyProjector.cs) - Fix 4 test files that used AGENTS.md as the repo-root sentinel (now use CLAUDE.md, since AGENTS.md was removed in4731ab5) - Redirect 10 doc citations from AGENTS.md to the matching gateway.md sections (Value Model, Status Model, Security, STA Worker Thread Model, gRPC Layer rule, cancellation rule) Verified: solution build clean, x86 worker build clean, 266/266 gateway tests passing, 121/121 worker tests passing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
131 lines
4.1 KiB
C#
131 lines
4.1 KiB
C#
using Microsoft.Extensions.Logging;
|
|
|
|
namespace MxGateway.Client;
|
|
|
|
/// <summary>
|
|
/// Configures the gRPC channel used by the .NET MXAccess Gateway client.
|
|
/// </summary>
|
|
public sealed class MxGatewayClientOptions
|
|
{
|
|
/// <summary>
|
|
/// Gets the gateway endpoint URI (required).
|
|
/// </summary>
|
|
public required Uri Endpoint { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the API key for gateway authentication (required).
|
|
/// </summary>
|
|
public required string ApiKey { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether to use TLS for the gateway connection.
|
|
/// </summary>
|
|
public bool UseTls { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the path to a CA certificate file for custom certificate validation.
|
|
/// </summary>
|
|
public string? CaCertificatePath { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the server name override for SNI during TLS handshake.
|
|
/// </summary>
|
|
public string? ServerNameOverride { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the timeout for establishing connection to the gateway.
|
|
/// </summary>
|
|
public TimeSpan ConnectTimeout { get; init; } = TimeSpan.FromSeconds(10);
|
|
|
|
/// <summary>
|
|
/// Gets the default timeout for unary gRPC calls.
|
|
/// </summary>
|
|
public TimeSpan DefaultCallTimeout { get; init; } = TimeSpan.FromSeconds(30);
|
|
|
|
/// <summary>
|
|
/// Gets the optional timeout for streaming gRPC calls.
|
|
/// </summary>
|
|
public TimeSpan? StreamTimeout { get; init; }
|
|
|
|
public int MaxGrpcMessageBytes { get; init; } = 16 * 1024 * 1024;
|
|
|
|
/// <summary>
|
|
/// Gets the retry configuration for safe unary calls.
|
|
/// </summary>
|
|
public MxGatewayClientRetryOptions Retry { get; init; } = new();
|
|
|
|
/// <summary>
|
|
/// Gets the logger factory for diagnostic logging.
|
|
/// </summary>
|
|
public ILoggerFactory? LoggerFactory { get; init; }
|
|
|
|
/// <summary>
|
|
/// Validates the client options for consistency and correctness.
|
|
/// </summary>
|
|
/// <exception cref="ArgumentNullException">Endpoint is null.</exception>
|
|
/// <exception cref="ArgumentException">Options are invalid or inconsistent.</exception>
|
|
/// <exception cref="ArgumentOutOfRangeException">Timeout values are not greater than zero.</exception>
|
|
public void Validate()
|
|
{
|
|
ArgumentNullException.ThrowIfNull(Endpoint);
|
|
|
|
if (!Endpoint.IsAbsoluteUri)
|
|
{
|
|
throw new ArgumentException(
|
|
"The gateway endpoint must be an absolute URI.",
|
|
nameof(Endpoint));
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(ApiKey))
|
|
{
|
|
throw new ArgumentException(
|
|
"The gateway API key must not be empty.",
|
|
nameof(ApiKey));
|
|
}
|
|
|
|
if (ConnectTimeout <= TimeSpan.Zero)
|
|
{
|
|
throw new ArgumentOutOfRangeException(
|
|
nameof(ConnectTimeout),
|
|
"The connect timeout must be greater than zero.");
|
|
}
|
|
|
|
if (DefaultCallTimeout <= TimeSpan.Zero)
|
|
{
|
|
throw new ArgumentOutOfRangeException(
|
|
nameof(DefaultCallTimeout),
|
|
"The default call timeout must be greater than zero.");
|
|
}
|
|
|
|
if (StreamTimeout is not null && StreamTimeout <= TimeSpan.Zero)
|
|
{
|
|
throw new ArgumentOutOfRangeException(
|
|
nameof(StreamTimeout),
|
|
"The stream timeout must be greater than zero when configured.");
|
|
}
|
|
|
|
if (MaxGrpcMessageBytes <= 0)
|
|
{
|
|
throw new ArgumentOutOfRangeException(
|
|
nameof(MaxGrpcMessageBytes),
|
|
"The maximum gRPC message size must be greater than zero.");
|
|
}
|
|
|
|
if (UseTls && Endpoint.Scheme != Uri.UriSchemeHttps)
|
|
{
|
|
throw new ArgumentException(
|
|
"UseTls requires an https gateway endpoint.",
|
|
nameof(Endpoint));
|
|
}
|
|
|
|
if (!UseTls && Endpoint.Scheme == Uri.UriSchemeHttps)
|
|
{
|
|
throw new ArgumentException(
|
|
"An https gateway endpoint requires UseTls.",
|
|
nameof(Endpoint));
|
|
}
|
|
|
|
Retry.Validate();
|
|
}
|
|
}
|