diff --git a/Directory.Packages.props b/Directory.Packages.props index 93d01d98..07f57ce7 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -98,10 +98,11 @@ - - - - + + + + + diff --git a/src/ZB.MOM.WW.ScadaBridge.Host/InboundApiKeyStoreOptions.cs b/src/ZB.MOM.WW.ScadaBridge.Host/InboundApiKeyStoreOptions.cs new file mode 100644 index 00000000..69798ed7 --- /dev/null +++ b/src/ZB.MOM.WW.ScadaBridge.Host/InboundApiKeyStoreOptions.cs @@ -0,0 +1,36 @@ +using Microsoft.Extensions.Configuration; + +namespace ZB.MOM.WW.ScadaBridge.Host; + +/// Which backend holds inbound API keys. Bound from ScadaBridge:InboundApi:ApiKeyStore alongside the library's own ApiKeyOptions. +public enum InboundApiKeyStoreProvider { Sqlite, SqlServer } + +/// Host-side selector for the inbound API key store. Sqlite is per-node (single-node installs); SqlServer shares one row set across a central pair (design 2026-09-02). +public sealed class InboundApiKeyStoreOptions +{ + public const string SectionPath = "ScadaBridge:InboundApi:ApiKeyStore"; + + public InboundApiKeyStoreProvider Provider { get; set; } = InboundApiKeyStoreProvider.Sqlite; + + /// SQLite file to import once when is SqlServer; defaults to the library's SqlitePath. Renamed *.imported afterwards. + public string? ImportFromSqlitePath { get; set; } + + /// Reads Provider from configuration (case-insensitive). Throws naming the legal values on an unknown one, so a typo fails the boot with a readable message instead of silently falling back to SQLite. + public static InboundApiKeyStoreProvider ReadProvider(IConfiguration configuration) + { + var value = configuration[$"{SectionPath}:Provider"]; + if (string.IsNullOrWhiteSpace(value)) + { + return InboundApiKeyStoreProvider.Sqlite; + } + + if (Enum.TryParse(value, ignoreCase: true, out var parsed) + && Enum.IsDefined(parsed)) + { + return parsed; + } + + throw new InvalidOperationException( + $"{SectionPath}:Provider '{value}' is not recognised; use 'Sqlite' or 'SqlServer'."); + } +} diff --git a/src/ZB.MOM.WW.ScadaBridge.Host/ZB.MOM.WW.ScadaBridge.Host.csproj b/src/ZB.MOM.WW.ScadaBridge.Host/ZB.MOM.WW.ScadaBridge.Host.csproj index 57a1ae27..24f4bc73 100644 --- a/src/ZB.MOM.WW.ScadaBridge.Host/ZB.MOM.WW.ScadaBridge.Host.csproj +++ b/src/ZB.MOM.WW.ScadaBridge.Host/ZB.MOM.WW.ScadaBridge.Host.csproj @@ -32,6 +32,7 @@ +