envsec 0.1.6 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/load.js +49 -0
- package/dist/main.js +2 -1
- package/package.json +1 -1
package/dist/cli/load.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Command, Options } from "@effect/cli";
|
|
2
|
+
import { Effect, Console } from "effect";
|
|
3
|
+
import { SecretStore } from "../services/SecretStore.js";
|
|
4
|
+
import { rootCommand } from "./root.js";
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
const input = Options.text("input").pipe(Options.withAlias("i"), Options.withDescription("Input .env file path (default: .env)"), Options.withDefault(".env"));
|
|
7
|
+
const force = Options.boolean("force").pipe(Options.withAlias("f"), Options.withDescription("Overwrite existing secrets without prompting"));
|
|
8
|
+
const parseLine = (line) => {
|
|
9
|
+
const trimmed = line.trim();
|
|
10
|
+
if (trimmed === "" || trimmed.startsWith("#"))
|
|
11
|
+
return null;
|
|
12
|
+
const eqIndex = trimmed.indexOf("=");
|
|
13
|
+
if (eqIndex === -1)
|
|
14
|
+
return null;
|
|
15
|
+
const key = trimmed.slice(0, eqIndex).trim();
|
|
16
|
+
const value = trimmed.slice(eqIndex + 1).trim().replace(/^["']|["']$/g, "");
|
|
17
|
+
return { key, value };
|
|
18
|
+
};
|
|
19
|
+
export const loadCommand = Command.make("load", { input, force }, ({ input, force }) => Effect.gen(function* () {
|
|
20
|
+
const { env } = yield* rootCommand;
|
|
21
|
+
const content = yield* Effect.try({
|
|
22
|
+
try: () => readFileSync(input, "utf-8"),
|
|
23
|
+
catch: () => new Error(`Cannot read file: ${input}`),
|
|
24
|
+
});
|
|
25
|
+
const lines = content.split("\n");
|
|
26
|
+
let added = 0;
|
|
27
|
+
let skipped = 0;
|
|
28
|
+
let overwritten = 0;
|
|
29
|
+
for (const line of lines) {
|
|
30
|
+
const parsed = parseLine(line);
|
|
31
|
+
if (!parsed)
|
|
32
|
+
continue;
|
|
33
|
+
const secretKey = parsed.key.toLowerCase().replaceAll("_", ".");
|
|
34
|
+
const exists = yield* SecretStore.list(env).pipe(Effect.map((items) => items.some((item) => item.key === secretKey)));
|
|
35
|
+
if (exists && !force) {
|
|
36
|
+
yield* Console.log(`⚠ Skipped "${secretKey}": already exists (use --force to overwrite)`);
|
|
37
|
+
skipped++;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (exists) {
|
|
41
|
+
overwritten++;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
added++;
|
|
45
|
+
}
|
|
46
|
+
yield* SecretStore.set(env, secretKey, parsed.value, "string");
|
|
47
|
+
}
|
|
48
|
+
yield* Effect.log(`Done: ${added} added, ${overwritten} overwritten, ${skipped} skipped`);
|
|
49
|
+
}));
|
package/dist/main.js
CHANGED
|
@@ -11,10 +11,11 @@ import { searchCommand } from "./cli/search.js";
|
|
|
11
11
|
import { listCommand } from "./cli/list.js";
|
|
12
12
|
import { runCommand } from "./cli/run.js";
|
|
13
13
|
import { envFileCommand } from "./cli/env-file.js";
|
|
14
|
+
import { loadCommand } from "./cli/load.js";
|
|
14
15
|
import { SecretStore } from "./services/SecretStore.js";
|
|
15
16
|
const require = createRequire(import.meta.url);
|
|
16
17
|
const pkg = require("../package.json");
|
|
17
|
-
const command = rootCommand.pipe(Command.withSubcommands([addCommand, getCommand, deleteCommand, delCommand, searchCommand, listCommand, runCommand, envFileCommand]));
|
|
18
|
+
const command = rootCommand.pipe(Command.withSubcommands([addCommand, getCommand, deleteCommand, delCommand, searchCommand, listCommand, runCommand, envFileCommand, loadCommand]));
|
|
18
19
|
const cli = Command.run(command, {
|
|
19
20
|
name: "secenv",
|
|
20
21
|
version: pkg.version,
|