58 lines
2.4 KiB
C#
58 lines
2.4 KiB
C#
namespace ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
|
|
|
/// <summary>
|
|
/// A caller-bound facade. Direct access needs no namespace mount; every operation applies the
|
|
/// bound caller's authority and retains the same policy and outcomes.
|
|
/// </summary>
|
|
public interface IDataConnection : IDataCatalogService, IDataReadService, IDataWriteService, IDataSubscriptionService, IAsyncDisposable
|
|
{
|
|
DataTarget Target { get; }
|
|
TimeProvider Clock { get; }
|
|
Task<DataCapabilities> GetCapabilitiesAsync(DataBudget budget, CancellationToken cancellationToken);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Authenticated authority established by the host, never supplied by an operation payload.
|
|
/// CredentialVersion is a non-secret authority fingerprint, not a bearer credential. The original
|
|
/// expiry is retained so renewal or replacement cannot extend an already admitted operation.
|
|
/// </summary>
|
|
public sealed record DataAuthenticatedContext(string PrincipalId, string ApiKeyId, string CredentialVersion,
|
|
DateTimeOffset? CredentialExpiresUtc, long AuthorityEpoch)
|
|
{
|
|
public void Validate()
|
|
{
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(PrincipalId);
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(ApiKeyId);
|
|
ArgumentException.ThrowIfNullOrWhiteSpace(CredentialVersion);
|
|
if (CredentialExpiresUtc is { Offset: var offset } && offset != TimeSpan.Zero)
|
|
{
|
|
throw new ArgumentException("Credential expiry must be UTC.", nameof(CredentialExpiresUtc));
|
|
}
|
|
if (AuthorityEpoch <= 0)
|
|
{
|
|
throw new ArgumentOutOfRangeException(nameof(AuthorityEpoch));
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Creates strictly caller-bound local facades. Hosts construct context from authenticated
|
|
/// authority, never from caller-supplied request fields, and must validate it before creation.
|
|
/// </summary>
|
|
public interface IDataConnectionFactory
|
|
{
|
|
IDataConnection Create(DataAuthenticatedContext context, DataTarget target);
|
|
}
|
|
|
|
/// <summary>Final-send guard for metadata and values prepared by a caller-bound connection.</summary>
|
|
public interface IDataConnectionPublicationGate
|
|
{
|
|
bool CanPublish(ServingIdentity expectedServing);
|
|
}
|
|
|
|
/// <summary>Discovery may report an unready role, while retaining that exact authenticated snapshot.</summary>
|
|
public interface IDataConnectionDiscoveryGate
|
|
{
|
|
bool CanPublishCapabilities(DataCapabilities expected);
|
|
}
|