sqlinsight-pro/src/SQLInsight.Connectivity/ConnectionTarget.cs
Claude edb7410f76
Some checks are pending
CI / Integration (mcr.microsoft.com/mssql/server:2017-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2019-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2022-latest) (push) Blocked by required conditions
CI / Integration (mcr.microsoft.com/mssql/server:2025-latest) (push) Blocked by required conditions
CI / Build og unit tests (push) Waiting to run
Fase 2: Azure SQL Managed Instance, docs and rule catalog test
- Managed Instance reports 12.0.2000.8 but is evergreen: treated as the
  newest engine with all capabilities; new SelfManagedInfrastructure
  capability so backup, CHECKDB, files, tempdb, memory, patch level and
  lifecycle rules report 'handled by Azure' instead of false findings
- Microsoft Entra ID login (managed identity, service principal, default
  credential chain) via SqlConnection.AccessTokenCallback
- Least-privilege script recognizes Managed Instance; deadlock collector
  falls back to the ring buffer when event files cannot be read
- Web UI shows the right release for Managed Instance
- README and installation docs: notifications and Managed Instance
- Catalog test: 61 rules with unique, well-formed ids

Integration suite green on SQL Server 2017 and 2022.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01E3EExwndy8Z22EK2Qpt6BK
2026-09-29 08:23:40 +00:00

69 lines
2.7 KiB
C#

namespace SQLInsight.Connectivity;
/// <summary>
/// How to reach one monitored instance.
/// </summary>
public sealed record ConnectionTarget
{
/// <summary>Server name, <c>host\instance</c> or <c>host,port</c>.</summary>
public required string Server { get; init; }
public AuthenticationMode Authentication { get; init; } = AuthenticationMode.Windows;
/// <summary>SQL login name. Only used with <see cref="AuthenticationMode.SqlLogin"/>.</summary>
public string? UserName { get; init; }
/// <summary>SQL login password. Only used with <see cref="AuthenticationMode.SqlLogin"/>.</summary>
public string? Password { get; init; }
public ConnectionProvider Provider { get; init; } = ConnectionProvider.Auto;
/// <summary>
/// Whether the connection must be encrypted. Mandatory is the default; old unpatched instances that only speak
/// TLS 1.0 need <see cref="EncryptionMode.Optional"/>, which the agent reports as a warning.
/// </summary>
public EncryptionMode Encryption { get; init; } = EncryptionMode.Mandatory;
/// <summary>Skip certificate validation. Off by default; must be a deliberate choice.</summary>
public bool TrustServerCertificate { get; init; }
/// <summary>ODBC driver used for legacy instances.</summary>
public string OdbcDriver { get; init; } = "ODBC Driver 18 for SQL Server";
public TimeSpan ConnectTimeout { get; init; } = TimeSpan.FromSeconds(15);
/// <summary>Entra tenant id, for <see cref="AuthenticationMode.EntraServicePrincipal"/>.</summary>
public string? TenantId { get; init; }
public bool UsesEntra => Authentication is AuthenticationMode.EntraManagedIdentity or AuthenticationMode.EntraServicePrincipal or AuthenticationMode.EntraDefault;
}
public enum AuthenticationMode
{
/// <summary>Integrated security. Preferred on-prem; run the agent as a gMSA.</summary>
Windows,
SqlLogin,
/// <summary>Microsoft Entra ID with the agent's managed identity (Azure VM). <see cref="ConnectionTarget.UserName"/> may hold a user-assigned identity's client id.</summary>
EntraManagedIdentity,
/// <summary>Microsoft Entra ID service principal: <see cref="ConnectionTarget.UserName"/> = client id, <see cref="ConnectionTarget.Password"/> = secret.</summary>
EntraServicePrincipal,
/// <summary>Microsoft Entra ID via the default credential chain (environment, managed identity, Azure CLI …).</summary>
EntraDefault,
}
public enum ConnectionProvider
{
/// <summary>Try Microsoft.Data.SqlClient, fall back to ODBC when the instance is too old for it.</summary>
Auto,
SqlClient,
Odbc,
}
public enum EncryptionMode
{
Mandatory,
Optional,
}