Files
lmxopcua/src/Server/ZB.MOM.WW.OtOpcUa.Host/Configuration/SecretChangeSignallingInvalidator.cs
T

30 lines
1.6 KiB
C#

using ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Runtime;
using ZB.MOM.WW.Secrets.Abstractions;
namespace ZB.MOM.WW.OtOpcUa.Host.Configuration;
/// <summary>
/// Decorates the Secrets library's <see cref="ISecretCacheInvalidator"/> so a secret change also reaches the
/// <see cref="GalaxyAckIdentityDirectory"/> (lmxopcua#765). The library has no change event; this seam is the
/// one every in-process writer already calls — the AdminUI <c>/api-keys</c> ack-identity service, the
/// <c>/admin/secrets</c> editor and delete modal, and the replication appliers (Akka / SQL Server).
/// </summary>
/// <param name="inner">The library's invalidator (the resolver cache).</param>
/// <param name="directory">The node's directory, or null on a node that runs no drivers.</param>
internal sealed class SecretChangeSignallingInvalidator(
ISecretCacheInvalidator inner, GalaxyAckIdentityDirectory? directory, DataConnectionSecretChangeHandler? dataChanges = null) : ISecretCacheInvalidator
{
/// <summary>Gets the decorated invalidator (test seam).</summary>
internal ISecretCacheInvalidator Inner => inner;
/// <inheritdoc />
public void Invalidate(SecretName name)
{
List<Exception>? failures = null;
try { inner.Invalidate(name); } catch (Exception ex) { (failures ??= []).Add(ex); }
try { directory?.NotifySecretChanged(name); } catch (Exception ex) { (failures ??= []).Add(ex); }
try { dataChanges?.NotifySecretChanged(name); } catch (Exception ex) { (failures ??= []).Add(ex); }
if (failures is not null) throw new AggregateException(failures);
}
}