mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 20:37:21 +00:00
mm: added secrets extraction for db mode
This commit is contained in:
37
app/src/plugins/dev/sync-secrets.plugin.ts
Normal file
37
app/src/plugins/dev/sync-secrets.plugin.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { type App, ModuleManagerEvents, type AppPlugin } from "bknd";
|
||||
import type { DbModuleManager } from "modules/db/DbModuleManager";
|
||||
|
||||
export type SyncSecretsOptions = {
|
||||
enabled?: boolean;
|
||||
write: (secrets: Record<string, any>) => Promise<void>;
|
||||
};
|
||||
|
||||
export function syncSecrets({ enabled = true, write }: SyncSecretsOptions): AppPlugin {
|
||||
let firstBoot = true;
|
||||
return (app: App) => ({
|
||||
name: "bknd-sync-secrets",
|
||||
onBuilt: async () => {
|
||||
if (!enabled) return;
|
||||
const manager = app.modules as DbModuleManager;
|
||||
|
||||
if (!("extractSecrets" in manager)) {
|
||||
throw new Error("ModuleManager does not support secrets");
|
||||
}
|
||||
|
||||
app.emgr.onEvent(
|
||||
ModuleManagerEvents.ModuleManagerSecretsExtractedEvent,
|
||||
async ({ params: { secrets } }) => {
|
||||
await write?.(secrets);
|
||||
},
|
||||
{
|
||||
id: "sync-secrets",
|
||||
},
|
||||
);
|
||||
|
||||
if (firstBoot) {
|
||||
firstBoot = false;
|
||||
await write?.(manager.extractSecrets().secrets);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user