qatools-cli 1.2.29 → 1.2.32
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/context-sync.js +1 -0
- package/hooks.js +7 -2
- package/package.json +3 -2
- package/qatools.js +3017 -2921
- package/vault.js +30 -0
package/vault.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// signals.feature-request-key-to-vault: store a newly created key in the owner's own secret vault by running
|
|
2
|
+
// their command with {key} replaced — the key is never printed, and any trace of it in error output is masked.
|
|
3
|
+
const { spawn } = require("child_process");
|
|
4
|
+
|
|
5
|
+
// Keys are letters, digits, '-' and '_' only, so putting one into a shell command cannot change the command
|
|
6
|
+
function vaultCommand(template, key) {
|
|
7
|
+
if (!String(template || "").includes("{key}")) throw new Error("The --vault command must contain {key} where the new key goes");
|
|
8
|
+
if (!/^[A-Za-z0-9_-]+$/.test(String(key || ""))) throw new Error("Unexpected key format — not passed to a shell");
|
|
9
|
+
return template.split("{key}").join(key);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const maskKey = (text, key) => String(text || "").split(key).join(`•••${key.slice(-4)}`);
|
|
13
|
+
|
|
14
|
+
// Runs the command; its output is kept from the screen (vault CLIs often echo the secret back)
|
|
15
|
+
function runVault(template, key, { run = spawn } = {}) {
|
|
16
|
+
const command = vaultCommand(template, key);
|
|
17
|
+
return new Promise((resolve) => {
|
|
18
|
+
let stderr = "";
|
|
19
|
+
const child = run(command, { shell: true, stdio: ["ignore", "pipe", "pipe"], windowsHide: true });
|
|
20
|
+
child.stdout?.on("data", () => {});
|
|
21
|
+
child.stderr?.on("data", (d) => { stderr += d; });
|
|
22
|
+
child.on("error", (e) => resolve({ ok: false, code: -1, stderr: maskKey(e.message, key) }));
|
|
23
|
+
child.on("close", (code) => resolve({ ok: code === 0, code, stderr: maskKey(stderr, key).trim() }));
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// What the CLI shows about the command: the template, never the key
|
|
28
|
+
const describeVault = (template) => String(template).replace(/\s+/g, " ").trim();
|
|
29
|
+
|
|
30
|
+
module.exports = { vaultCommand, maskKey, runVault, describeVault };
|