Skip to content

Commit 3ff2c69

Browse files
committed
fix(server): a changed secret provider retries unreadable instance secrets
Signed-off-by: Yordis Prieto <[email protected]>
1 parent e576e64 commit 3ff2c69

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎apps/server/src/provider/ProviderInstanceRegistryHydration.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
ProviderDriverKind,
55
ProviderInstanceId,
66
SecretProviderId,
7+
SecretProviderKind,
78
type ServerSettings,
89
} from "@t3tools/contracts";
910
import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -171,7 +172,7 @@ describe("layerSettingsWatcher", () => {
171172
const next = yield* settings.updateSettings({
172173
secretProviders: {
173174
[SecretProviderId.make("personal")]: {
174-
kind: "one_password",
175+
kind: SecretProviderKind.make("one_password"),
175176
label: "Personal",
176177
config: { account: "my" },
177178
},

‎apps/server/src/provider/ProviderInstanceRegistryHydration.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
type ProviderInstanceConfigMap,
99
ServerSettings,
1010
} from "@t3tools/contracts";
11+
import * as NodeUtil from "node:util";
12+
1113
import * as HostProcess from "@t3tools/shared/HostProcess";
1214
import type * as SecureRandom from "effect/crypto/SecureRandom";
1315
import * as Effect from "effect/Effect";
@@ -127,13 +129,25 @@ export const layerSettingsWatcher = (settingsChanges: Stream.Stream<ServerSettin
127129
Effect.gen(function* () {
128130
const mutator = yield* ProviderInstanceRegistryMutator.ProviderInstanceRegistryMutator;
129131
const serverSettings = yield* Settings.ServerSettingsService;
132+
let secretProviders = yield* serverSettings.getSettings.pipe(
133+
Effect.map((settings) => settings.secretProviders),
134+
Effect.orElseSucceed(() => undefined),
135+
);
130136
yield* settingsChanges.pipe(
131137
Stream.runForEach(() =>
132138
// The subscription predates the seed read, so a queued change can be
133139
// older than the seed. A failed current read must leave the registry intact.
134140
serverSettings.getSettings.pipe(
135141
Effect.flatMap((current) =>
136-
mutator.reconcile(deriveProviderInstanceConfigMap(current)),
142+
Effect.gen(function* () {
143+
yield* mutator.reconcile(deriveProviderInstanceConfigMap(current));
144+
// Reconcile leaves instances parked on an unreadable secret alone,
145+
// and a corrected secret provider is what can make them readable.
146+
if (!NodeUtil.isDeepStrictEqual(secretProviders, current.secretProviders)) {
147+
secretProviders = current.secretProviders;
148+
yield* mutator.reloadSecrets();
149+
}
150+
}),
137151
),
138152
Effect.catchCause((cause) =>
139153
Effect.logError("ProviderInstanceRegistry reconcile failed", cause),

0 commit comments

Comments
 (0)