@envsave/cli 1.0.38 → 1.0.40
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.js +41 -19
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -259,6 +259,7 @@ __export(exports_vault, {
|
|
|
259
259
|
showSecret: () => showSecret,
|
|
260
260
|
setSecret: () => setSecret,
|
|
261
261
|
searchKeys: () => searchKeys,
|
|
262
|
+
revealKeysByPattern: () => revealKeysByPattern,
|
|
262
263
|
revealKey: () => revealKey,
|
|
263
264
|
listKeys: () => listKeys,
|
|
264
265
|
initVault: () => initVault,
|
|
@@ -514,7 +515,7 @@ function initVault(password, options) {
|
|
|
514
515
|
const hmacSeed = randomBytes2(32).toString("hex");
|
|
515
516
|
const sshKeyContent = options?.sshKeyPath ? readFileSync3(options.sshKeyPath, "utf8") : undefined;
|
|
516
517
|
const vault = {
|
|
517
|
-
version:
|
|
518
|
+
version: 5,
|
|
518
519
|
hmacSeed,
|
|
519
520
|
sshKeyPath: options?.sshKeyPath,
|
|
520
521
|
secrets: {},
|
|
@@ -544,7 +545,8 @@ function setSecret(key, value, password) {
|
|
|
544
545
|
const vault = readMainVault(password);
|
|
545
546
|
const sshKeyContent = loadSshKey(vault);
|
|
546
547
|
const opaque = computeOpaqueName(vault.hmacSeed, key, sshKeyContent);
|
|
547
|
-
|
|
548
|
+
const updated = opaque in vault.secrets;
|
|
549
|
+
if (!updated && !hasValidLicense()) {
|
|
548
550
|
if (vault.registry.length >= FREE_TIER_MAX_SECRETS) {
|
|
549
551
|
throw new Error(`Free tier limit: max ${FREE_TIER_MAX_SECRETS} secrets. Run 'envsave activate <token>' to unlock unlimited secrets.
|
|
550
552
|
Get your license at https://api.envsave.com`);
|
|
@@ -556,7 +558,7 @@ Get your license at https://api.envsave.com`);
|
|
|
556
558
|
}
|
|
557
559
|
writeMainVault(vault, password);
|
|
558
560
|
writeSessionCache(vault.secrets, vault.registry);
|
|
559
|
-
return opaque;
|
|
561
|
+
return { opaque, updated };
|
|
560
562
|
}
|
|
561
563
|
function showSecret(cleanName, password) {
|
|
562
564
|
const vault = readMainVault(password);
|
|
@@ -572,6 +574,22 @@ function revealKey(cleanName, password) {
|
|
|
572
574
|
const opaque = computeOpaqueName(vault.hmacSeed, cleanName, sshKeyContent);
|
|
573
575
|
return opaque in vault.secrets ? opaque : undefined;
|
|
574
576
|
}
|
|
577
|
+
function revealKeysByPattern(patterns, password) {
|
|
578
|
+
const vault = readMainVault(password);
|
|
579
|
+
const sshKeyContent = loadSshKey(vault);
|
|
580
|
+
writeSessionCache(vault.secrets, vault.registry);
|
|
581
|
+
return patterns.map((pattern) => {
|
|
582
|
+
const lower = pattern.toLowerCase();
|
|
583
|
+
const matchingNames = vault.registry.filter((k) => k.toLowerCase().includes(lower));
|
|
584
|
+
return {
|
|
585
|
+
pattern,
|
|
586
|
+
matches: matchingNames.map((name) => ({
|
|
587
|
+
name,
|
|
588
|
+
opaque: computeOpaqueName(vault.hmacSeed, name, sshKeyContent)
|
|
589
|
+
}))
|
|
590
|
+
};
|
|
591
|
+
});
|
|
592
|
+
}
|
|
575
593
|
function getSecretFromCache(opaqueKey) {
|
|
576
594
|
checkRateLimit();
|
|
577
595
|
const cache = readSessionCache();
|
|
@@ -892,7 +910,7 @@ Usage:
|
|
|
892
910
|
envsave set <key> <value> Add/update a secret (outputs opaque key)
|
|
893
911
|
envsave get <opaque_key> Retrieve a value (no password needed)
|
|
894
912
|
envsave show <key> Show real value by key name (password required)
|
|
895
|
-
envsave reveal <
|
|
913
|
+
envsave reveal <keyword> [keyword2]... Show opaque key(s) for any name matching keyword (password required)
|
|
896
914
|
envsave delete <key> Remove a secret (password required)
|
|
897
915
|
envsave search <keyword> Search keys matching keyword (no password)
|
|
898
916
|
envsave scan [dir] Scan project for env variable usage
|
|
@@ -1041,9 +1059,9 @@ Use 'envsave reveal <KEY>' to get the opaque key for each secret.`);
|
|
|
1041
1059
|
process.exit(1);
|
|
1042
1060
|
}
|
|
1043
1061
|
const password = await requirePassword();
|
|
1044
|
-
const opaque = setSecret(key, value, password);
|
|
1062
|
+
const { opaque, updated } = setSecret(key, value, password);
|
|
1045
1063
|
console.log(`
|
|
1046
|
-
${key} → ${opaque}
|
|
1064
|
+
${updated ? "Updated" : "Added"}: ${key} → ${opaque}
|
|
1047
1065
|
`);
|
|
1048
1066
|
console.log(` Use this in your code to access ${key}:`);
|
|
1049
1067
|
console.log(` envsave.get("${opaque}")
|
|
@@ -1051,27 +1069,31 @@ Use 'envsave reveal <KEY>' to get the opaque key for each secret.`);
|
|
|
1051
1069
|
break;
|
|
1052
1070
|
}
|
|
1053
1071
|
case "reveal": {
|
|
1054
|
-
const
|
|
1055
|
-
if (
|
|
1056
|
-
console.error("Usage: envsave reveal <
|
|
1072
|
+
const patterns = args.slice(1);
|
|
1073
|
+
if (patterns.length === 0) {
|
|
1074
|
+
console.error("Usage: envsave reveal <keyword> [keyword2]...");
|
|
1057
1075
|
process.exit(1);
|
|
1058
1076
|
}
|
|
1059
1077
|
const password = await requirePassword();
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1078
|
+
const results = revealKeysByPattern(patterns, password);
|
|
1079
|
+
let totalMatches = 0;
|
|
1080
|
+
let notFoundPatterns = 0;
|
|
1081
|
+
for (const { pattern, matches } of results) {
|
|
1082
|
+
if (matches.length === 0) {
|
|
1083
|
+
console.error(`No keys matching '${pattern}'.`);
|
|
1084
|
+
notFoundPatterns++;
|
|
1085
|
+
continue;
|
|
1086
|
+
}
|
|
1087
|
+
for (const { name, opaque } of matches) {
|
|
1064
1088
|
console.log(`
|
|
1065
|
-
${
|
|
1089
|
+
${name} → ${opaque}`);
|
|
1066
1090
|
console.log(` envsave.get("${opaque}")`);
|
|
1067
|
-
|
|
1068
|
-
console.error(`Secret '${key}' not found.`);
|
|
1069
|
-
notFound++;
|
|
1091
|
+
totalMatches++;
|
|
1070
1092
|
}
|
|
1071
1093
|
}
|
|
1072
|
-
if (
|
|
1094
|
+
if (totalMatches > 0)
|
|
1073
1095
|
console.log();
|
|
1074
|
-
if (
|
|
1096
|
+
if (notFoundPatterns === patterns.length)
|
|
1075
1097
|
process.exit(1);
|
|
1076
1098
|
break;
|
|
1077
1099
|
}
|