136 lines
4.0 KiB
C#
136 lines
4.0 KiB
C#
using ZA.CoreService.ESBCertificateManager.Services;
|
|
|
|
namespace ZA.CoreService.ESBCertificateManager.Models;
|
|
|
|
/// <summary>
|
|
/// Aus dbo.SonicConnection geladene Verbindungsdaten.
|
|
/// CredentialSecret wird durch Microsoft.Data.SqlClient
|
|
/// clientseitig entschlüsselt.
|
|
/// </summary>
|
|
public sealed class DatabaseSonicConnection
|
|
{
|
|
public int Id { get; init; }
|
|
|
|
public required string Name { get; init; }
|
|
|
|
public required string ManagementHost { 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 bool IsActive { get; init; }
|
|
|
|
public bool HasCredentials =>
|
|
!string.IsNullOrWhiteSpace(CredentialUserName)
|
|
&& !string.IsNullOrEmpty(CredentialSecret);
|
|
|
|
public string BuildConnectionUrl()
|
|
{
|
|
if (string.IsNullOrWhiteSpace(ConnectionProtocol))
|
|
{
|
|
throw new InvalidOperationException(
|
|
$"Bei der Sonic-Verbindung '{Name}' fehlt ConnectionProtocol.");
|
|
}
|
|
|
|
if (string.IsNullOrWhiteSpace(ManagementHost))
|
|
{
|
|
throw new InvalidOperationException(
|
|
$"Bei der Sonic-Verbindung '{Name}' fehlt ManagementHost.");
|
|
}
|
|
|
|
if (ManagementPort is null or < 1 or > 65535)
|
|
{
|
|
throw new InvalidOperationException(
|
|
$"Bei der Sonic-Verbindung '{Name}' fehlt ein gültiger ManagementPort.");
|
|
}
|
|
|
|
string protocol = ConnectionProtocol
|
|
.Trim()
|
|
.TrimEnd(':', '/');
|
|
|
|
string host = ManagementHost.Trim();
|
|
|
|
return $"{protocol}://{host}:{ManagementPort.Value}";
|
|
}
|
|
|
|
public SonicConnection ToRuntimeConnection(
|
|
RuntimeSettings runtimeSettings)
|
|
{
|
|
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))
|
|
{
|
|
throw new InvalidOperationException(
|
|
$"Bei der Sonic-Verbindung '{Name}' fehlen die Zugangsdaten. " +
|
|
"Bitte das Setup ausführen.");
|
|
}
|
|
|
|
string javaExecutablePath =
|
|
PathResolver.ResolvePath(
|
|
runtimeSettings.JavaExecutablePath);
|
|
|
|
string sonicClientLibraryPath =
|
|
PathResolver.ResolvePath(
|
|
runtimeSettings.SonicClientLibraryPath);
|
|
|
|
string javaBinDirectory =
|
|
Path.GetDirectoryName(javaExecutablePath)
|
|
?? string.Empty;
|
|
|
|
string javaHome =
|
|
Directory.GetParent(javaBinDirectory)?.FullName
|
|
?? string.Empty;
|
|
|
|
string sonicHome =
|
|
Directory.GetParent(sonicClientLibraryPath)?.FullName
|
|
?? string.Empty;
|
|
|
|
return new SonicConnection
|
|
{
|
|
Name = Name,
|
|
DomainName = DomainName,
|
|
ConnectionUrl = BuildConnectionUrl(),
|
|
Username = CredentialUserName,
|
|
|
|
// Nur Laufzeitwert, bereits clientseitig entschlüsselt.
|
|
Password = CredentialSecret,
|
|
|
|
JavaPath = javaExecutablePath,
|
|
JavaHome = javaHome,
|
|
MfClientLibPath = sonicClientLibraryPath,
|
|
SonicHome = sonicHome,
|
|
|
|
TimeoutSeconds = 120,
|
|
PostRestartDelaySeconds = 20
|
|
};
|
|
}
|
|
} |