Simplify DB to six tables and load credentials via Always Encrypted SonicCredential.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,8 +4,7 @@ namespace ZA.CoreService.ESBCertificateManager.Models;
|
||||
|
||||
/// <summary>
|
||||
/// Aus dbo.SonicConnection geladene Verbindungsdaten.
|
||||
/// CredentialSecret wird durch Microsoft.Data.SqlClient
|
||||
/// clientseitig entschlüsselt.
|
||||
/// Zugangsdaten liegen ausschließlich in dbo.SonicCredential.
|
||||
/// </summary>
|
||||
public sealed class DatabaseSonicConnection
|
||||
{
|
||||
@@ -15,34 +14,16 @@ public sealed class DatabaseSonicConnection
|
||||
|
||||
public required string ManagementHost { get; init; }
|
||||
|
||||
public int? ManagementPort { get; init; }
|
||||
public int ManagementPort { get; init; }
|
||||
|
||||
public string? ConnectionProtocol { get; init; }
|
||||
|
||||
public string? DomainName { get; init; }
|
||||
|
||||
public string? CredentialUserName { get; init; }
|
||||
|
||||
public string? CredentialReference { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// Nur zur Laufzeit verfügbar.
|
||||
/// Darf niemals protokolliert oder angezeigt werden.
|
||||
/// </summary>
|
||||
public string? CredentialSecret { get; init; }
|
||||
|
||||
public string? JavaHomePath { get; init; }
|
||||
|
||||
public string? SonicHomePath { get; init; }
|
||||
|
||||
public string? Notes { get; init; }
|
||||
public string? EnvironmentCode { get; init; }
|
||||
|
||||
public bool IsActive { get; init; }
|
||||
|
||||
public bool HasCredentials =>
|
||||
!string.IsNullOrWhiteSpace(CredentialUserName)
|
||||
&& !string.IsNullOrEmpty(CredentialSecret);
|
||||
|
||||
public string BuildConnectionUrl()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(ConnectionProtocol))
|
||||
@@ -57,7 +38,7 @@ public sealed class DatabaseSonicConnection
|
||||
$"Bei der Sonic-Verbindung '{Name}' fehlt ManagementHost.");
|
||||
}
|
||||
|
||||
if (ManagementPort is null or < 1 or > 65535)
|
||||
if (ManagementPort is < 1 or > 65535)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Bei der Sonic-Verbindung '{Name}' fehlt ein gültiger ManagementPort.");
|
||||
@@ -69,29 +50,26 @@ public sealed class DatabaseSonicConnection
|
||||
|
||||
string host = ManagementHost.Trim();
|
||||
|
||||
return $"{protocol}://{host}:{ManagementPort.Value}";
|
||||
return $"{protocol}://{host}:{ManagementPort}";
|
||||
}
|
||||
|
||||
public SonicConnection ToRuntimeConnection(
|
||||
RuntimeSettings runtimeSettings)
|
||||
RuntimeSettings runtimeSettings,
|
||||
SonicCredentialProfile credential)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(credential);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(DomainName))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Bei der Sonic-Verbindung '{Name}' fehlt DomainName.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(CredentialUserName))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Bei der Sonic-Verbindung '{Name}' fehlt der Benutzername.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(CredentialSecret))
|
||||
if (!credential.IsComplete)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Bei der Sonic-Verbindung '{Name}' fehlen die Zugangsdaten. " +
|
||||
"Bitte das Setup ausführen.");
|
||||
"Bitte die Einstellungen öffnen und ein Benutzerprofil hinterlegen.");
|
||||
}
|
||||
|
||||
string javaExecutablePath =
|
||||
@@ -119,10 +97,10 @@ public sealed class DatabaseSonicConnection
|
||||
Name = Name,
|
||||
DomainName = DomainName,
|
||||
ConnectionUrl = BuildConnectionUrl(),
|
||||
Username = CredentialUserName,
|
||||
Username = credential.UserName,
|
||||
|
||||
// Nur Laufzeitwert, bereits clientseitig entschlüsselt.
|
||||
Password = CredentialSecret,
|
||||
Password = credential.Secret,
|
||||
|
||||
JavaPath = javaExecutablePath,
|
||||
JavaHome = javaHome,
|
||||
@@ -133,4 +111,4 @@ public sealed class DatabaseSonicConnection
|
||||
PostRestartDelaySeconds = 20
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user