Files
lmxopcua/src/Server/ZB.MOM.WW.OtOpcUa.ControlPlane/Audit/AuditOutcomeMapper.cs
T
Joseph Doherty 1aa7905676 review(ControlPlane): fix premature deploy-seal from unexpected-node ack
Review at HEAD 7286d320. ControlPlane-001 (Medium): ConfigPublishCoordinator.HandleAck
now discards acks from nodes not in _expectedAcks (prevented premature SealDeployment) +
regression test. -002 (flipped-node log count), -003 (redundant mapper arms) tidied.
2026-06-19 10:52:22 -04:00

39 lines
2.0 KiB
C#

using ZB.MOM.WW.Audit;
namespace ZB.MOM.WW.OtOpcUa.ControlPlane.Audit;
/// <summary>
/// Maps OtOpcUa's audit <c>Action</c> vocabulary onto the canonical
/// <see cref="AuditOutcome"/>. The vocabulary is the set of values documented on
/// <c>ConfigAuditLog.EventType</c>: config verbs are <see cref="AuditOutcome.Success"/>,
/// the two authorization-rejection events are <see cref="AuditOutcome.Denied"/>. OtOpcUa
/// emits no <see cref="AuditOutcome.Failure"/> events today.
/// </summary>
/// <remarks>
/// Pure function — no live emit sites construct an <see cref="AuditEvent"/> in production
/// (the structured audit path is dormant; all live audit flows through the bespoke stored
/// procedure path). This helper exists so that when the structured path is wired up, the
/// required <c>Outcome</c> field is derived consistently from the action verb. Tested, not
/// yet exercised in production.
/// </remarks>
public static class AuditOutcomeMapper
{
/// <summary>
/// Derives the canonical <see cref="AuditOutcome"/> for an OtOpcUa audit action verb.
/// Unknown verbs default to <see cref="AuditOutcome.Success"/> (config writes are the
/// overwhelming majority and the only non-success cases are the two explicit
/// authorization rejections enumerated below).
/// </summary>
/// <param name="action">The audit action verb (e.g. <c>DraftCreated</c>, <c>OpcUaAccessDenied</c>).</param>
/// <returns>The mapped outcome.</returns>
public static AuditOutcome FromAction(string action) => action switch
{
"OpcUaAccessDenied" or "CrossClusterNamespaceAttempt" => AuditOutcome.Denied,
// All other known config-write verbs (DraftCreated, DraftEdited, Published, RolledBack,
// NodeApplied, ClusterCreated, NodeAdded, CredentialAdded, CredentialDisabled,
// ExternalIdReleased) and any future verbs default to Success — config writes are the
// overwhelming majority and the only non-success cases are the two Denied entries above.
_ => AuditOutcome.Success,
};
}