fix(secrets): SqlServer/Akka registration is order-independent; bump 0.6.6 (scadaproj#30)
AddZbSecretsSqlServerStore / AddZbSecretsSqlServerReplication (and the Akka extension, same defect class) TryAdd-ed their ISecretStore, ISecretsStoreMigrator and ISecretReplicator ahead of their internal AddZbSecrets call. An application that had already called AddZbSecrets therefore silently kept the SQLite store (shared-store mode) or NoOpSecretReplicator (hub/Akka modes). They now call AddZbSecrets first and RemoveAll + AddSingleton their own registrations; a later AddZbSecrets only TryAdds, so either order yields the same graph with exactly one ISecretStore registration. - tests: RegistrationOrderTests (SqlServer + Akka) build and resolve the real container in both orders; core-first fails without the fix - Directory.Build.props 0.6.5 -> 0.6.6 (NOT packed or published) - code-reviews: Secrets-001 Resolved; README regenerated Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
+22
-10
@@ -48,14 +48,19 @@ public static class SqlServerSecretsServiceCollectionExtensions
|
||||
{
|
||||
RegisterSqlServerCore(services, config, sqlServerSectionPath);
|
||||
|
||||
// Registered BEFORE AddZbSecrets so its TryAdd calls find these already present and leave
|
||||
// them alone — that is the whole mechanism by which the SQL-Server store displaces SQLite.
|
||||
services.TryAddSingleton<ISecretStore>(sp => sp.GetRequiredService<SqlServerSecretStore>());
|
||||
services.TryAddSingleton<ISecretsStoreMigrator>(sp =>
|
||||
sp.GetRequiredService<SqlServerSecretsStoreMigrator>());
|
||||
|
||||
services.AddZbSecrets(config, secretsSectionPath);
|
||||
|
||||
// REPLACE, not TryAdd (scadaproj#30): the application may already have called AddZbSecrets,
|
||||
// whose SQLite ISecretStore / ISecretsStoreMigrator a TryAdd here would silently leave in
|
||||
// place — each node of a "shared-store" pair would then write its own local file. Replacing
|
||||
// after the core call makes the outcome independent of call order: a later AddZbSecrets only
|
||||
// TryAdds, so it cannot displace these either.
|
||||
services.RemoveAll<ISecretStore>();
|
||||
services.AddSingleton<ISecretStore>(sp => sp.GetRequiredService<SqlServerSecretStore>());
|
||||
services.RemoveAll<ISecretsStoreMigrator>();
|
||||
services.AddSingleton<ISecretsStoreMigrator>(sp =>
|
||||
sp.GetRequiredService<SqlServerSecretsStoreMigrator>());
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -87,15 +92,22 @@ public static class SqlServerSecretsServiceCollectionExtensions
|
||||
|
||||
services.TryAddSingleton<ISecretReplicationHub>(sp => sp.GetRequiredService<SqlServerSecretStore>());
|
||||
|
||||
services.TryAddSingleton<ISecretReplicator>(sp =>
|
||||
new SqlServerSecretReplicator(sp.GetRequiredService<ISecretReplicationHub>()));
|
||||
|
||||
// The local store + its migrator come from AddZbSecrets (SQLite by default).
|
||||
services.AddZbSecrets(config, secretsSectionPath);
|
||||
|
||||
// REPLACE, not TryAdd (scadaproj#30): if the application called AddZbSecrets first, its
|
||||
// NoOpSecretReplicator is already registered and a TryAdd would silently lose to it — live
|
||||
// publish disabled, propagation left to the sweep interval, no error anywhere.
|
||||
services.RemoveAll<ISecretReplicator>();
|
||||
services.AddSingleton<ISecretReplicator>(sp =>
|
||||
new SqlServerSecretReplicator(sp.GetRequiredService<ISecretReplicationHub>()));
|
||||
|
||||
// Decorate the local store so every write publishes. Resolved from the concrete SQLite store
|
||||
// rather than ISecretStore, because ISecretStore is what we are replacing — asking the
|
||||
// container for it here would resolve this very decorator and recurse forever.
|
||||
// container for it here would resolve this very decorator and recurse forever. Any earlier
|
||||
// ISecretStore registration (the core's SQLite forward) is removed so the decorator is the
|
||||
// only one, whichever order the calls came in.
|
||||
services.RemoveAll<ISecretStore>();
|
||||
services.AddSingleton<ISecretStore>(sp => new ReplicatingSecretStore(
|
||||
sp.GetRequiredService<Secrets.Sqlite.SqliteSecretStore>(),
|
||||
sp.GetRequiredService<ISecretReplicator>(),
|
||||
|
||||
Reference in New Issue
Block a user