mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 20:37:21 +00:00
improved module manager's secrets extraction, updated plugins
This commit is contained in:
@@ -4,6 +4,7 @@ import { makeAppFromEnv } from "cli/commands/run";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import c from "picocolors";
|
||||
import { withConfigOptions } from "cli/utils/options";
|
||||
import { $console } from "bknd/utils";
|
||||
|
||||
export const config: CliCommand = (program) => {
|
||||
withConfigOptions(program.command("config"))
|
||||
@@ -19,7 +20,14 @@ export const config: CliCommand = (program) => {
|
||||
config = getDefaultConfig();
|
||||
} else {
|
||||
const app = await makeAppFromEnv(options);
|
||||
config = app.toJSON(options.secrets);
|
||||
const manager = app.modules;
|
||||
|
||||
if (options.secrets) {
|
||||
$console.warn("Including secrets in output");
|
||||
config = manager.toJSON(true);
|
||||
} else {
|
||||
config = manager.extractSecrets().configs;
|
||||
}
|
||||
}
|
||||
|
||||
config = options.pretty ? JSON.stringify(config, null, 2) : JSON.stringify(config);
|
||||
|
||||
@@ -8,3 +8,4 @@ export { copyAssets } from "./copy-assets";
|
||||
export { types } from "./types";
|
||||
export { mcp } from "./mcp/mcp";
|
||||
export { sync } from "./sync";
|
||||
export { secrets } from "./secrets";
|
||||
|
||||
58
app/src/cli/commands/secrets.ts
Normal file
58
app/src/cli/commands/secrets.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import type { CliCommand } from "../types";
|
||||
import { makeAppFromEnv } from "cli/commands/run";
|
||||
import { writeFile } from "node:fs/promises";
|
||||
import c from "picocolors";
|
||||
import { withConfigOptions, type WithConfigOptions } from "cli/utils/options";
|
||||
import { transformObject } from "bknd/utils";
|
||||
import { Option } from "commander";
|
||||
|
||||
export const secrets: CliCommand = (program) => {
|
||||
withConfigOptions(program.command("secrets"))
|
||||
.description("get app secrets")
|
||||
.option("--template", "template output without the actual secrets")
|
||||
.addOption(
|
||||
new Option("--format <format>", "format output").choices(["json", "env"]).default("json"),
|
||||
)
|
||||
.option("--out <file>", "output file")
|
||||
.action(
|
||||
async (
|
||||
options: WithConfigOptions<{ template: string; format: "json" | "env"; out: string }>,
|
||||
) => {
|
||||
const app = await makeAppFromEnv(options);
|
||||
const manager = app.modules;
|
||||
|
||||
let secrets = manager.extractSecrets().secrets;
|
||||
if (options.template) {
|
||||
secrets = transformObject(secrets, () => "");
|
||||
}
|
||||
|
||||
console.info("");
|
||||
if (options.out) {
|
||||
if (options.format === "env") {
|
||||
await writeFile(
|
||||
options.out,
|
||||
Object.entries(secrets)
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join("\n"),
|
||||
);
|
||||
} else {
|
||||
await writeFile(options.out, JSON.stringify(secrets, null, 2));
|
||||
}
|
||||
console.info(`Secrets written to ${c.cyan(options.out)}`);
|
||||
} else {
|
||||
if (options.format === "env") {
|
||||
console.info(
|
||||
c.cyan(
|
||||
Object.entries(secrets)
|
||||
.map(([key, value]) => `${key}=${value}`)
|
||||
.join("\n"),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
console.info(secrets);
|
||||
}
|
||||
}
|
||||
console.info("");
|
||||
},
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user