namespace ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Security; /// /// Read-side projection of one inbound API key, as surfaced by the management seam. /// Hash-free by construction — the secret is never carried here; it is shown ONCE at /// creation via . /// /// Stable key identifier (the middle segment of the token). /// Operator-facing display name. /// True while the key is active (not revoked/disabled). /// The API-method names this key is scoped to call, sorted ordinally. /// When the key was created. /// When the key last authenticated a request, if ever. public sealed record InboundApiKeyInfo( string KeyId, string Name, bool Enabled, IReadOnlyList Methods, DateTimeOffset CreatedUtc, DateTimeOffset? LastUsedUtc); /// /// Result of creating a key. is the assembled bearer token /// (sbk_<keyId>_<secret>) and is the ONLY moment the secret is available — /// it is never retrievable afterwards. /// /// The new key's identifier. /// The bearer token, shown once. public sealed record InboundApiKeyCreated(string KeyId, string Token); /// /// App-facing management seam for inbound API keys. This is the single shared path CLI /// and CentralUI use to create / list / enable / disable / delete inbound keys and edit /// their method-scopes. The interface lives in Commons and is deliberately free of any /// dependency on the underlying auth library, so consumers depend only on this contract. /// /// /// Mutating operations (, , /// , ) may throw on /// store-level or configuration failures (e.g. an unavailable pepper) rather than /// exclusively signalling failure via their bool return — callers must handle /// exceptions in addition to checking the return value. /// public interface IInboundApiKeyAdmin { /// Creates a new key scoped to and returns its /// identifier plus the bearer token (shown once). Task CreateAsync( string name, IReadOnlyCollection methods, CancellationToken ct = default); /// Lists all inbound keys (hash-free projection). Task> ListAsync(CancellationToken ct = default); /// Enables or disables a key without changing its secret. Returns false if /// the key does not exist. Task SetEnabledAsync(string keyId, bool enabled, CancellationToken ct = default); /// Replaces the method-scope set on a key without changing its secret. /// Returns false if the key does not exist. Task SetMethodsAsync( string keyId, IReadOnlyCollection methods, CancellationToken ct = default); /// Removes a key (revoke-then-delete). Returns false if the key could not be /// deleted. Task DeleteAsync(string keyId, CancellationToken ct = default); /// Returns the method-scope set for a key, or an empty list if not found. /// Enumerates the full key list (O(n)); intended for admin-scale use, not hot paths. Task> GetMethodsForKeyAsync(string keyId, CancellationToken ct = default); /// Returns the identifiers of all keys whose scopes contain /// . /// Enumerates the full key list (O(n)); intended for admin-scale use, not hot paths. Task> GetKeysForMethodAsync(string methodName, CancellationToken ct = default); }