grada-run 0.40.10 → 0.40.11
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/package.json +1 -1
- package/src/commands/secrets.js +60 -9
package/package.json
CHANGED
package/src/commands/secrets.js
CHANGED
|
@@ -92,12 +92,34 @@ export async function resolveSecretsRegion(options = {}) {
|
|
|
92
92
|
return 'us-east-2';
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
// Quote one value so `dotenv.parse` reads it back byte-identical. Plain
|
|
96
|
+
// values keep the legacy double-quote style; values holding a double
|
|
97
|
+
// quote switch to a literal style (single or backtick) because dotenv
|
|
98
|
+
// keeps `\"` verbatim instead of unescaping it. Returns null when no
|
|
99
|
+
// style round-trips — the caller must refuse to write rather than
|
|
100
|
+
// corrupt the file.
|
|
101
|
+
export function quoteEnvValue(value) {
|
|
102
|
+
const text = String(value ?? '');
|
|
103
|
+
const hasSingle = text.includes("'");
|
|
104
|
+
const hasDouble = text.includes('"');
|
|
105
|
+
const hasBacktick = text.includes('`');
|
|
106
|
+
if (hasDouble) {
|
|
107
|
+
if (hasSingle && hasBacktick) return null;
|
|
108
|
+
if (hasSingle) return `\`${text}\``;
|
|
109
|
+
return `'${text}'`;
|
|
110
|
+
}
|
|
111
|
+
if (hasSingle) {
|
|
112
|
+
// Literal backslash-n/r sequences are indistinguishable from escaped
|
|
113
|
+
// newlines inside double quotes, so they force the literal styles.
|
|
114
|
+
if (/\\[nr]/.test(text)) return hasBacktick ? null : `\`${text}\``;
|
|
115
|
+
return `"${text.replace(/\n/g, '\\n').replace(/\r/g, '\\r')}"`;
|
|
116
|
+
}
|
|
117
|
+
if (text.includes('\\')) return `'${text}'`;
|
|
118
|
+
return `"${text.replace(/\n/g, '\\n').replace(/\r/g, '\\r')}"`;
|
|
97
119
|
}
|
|
98
120
|
|
|
99
121
|
function serializeEnv(orderedKeys, values) {
|
|
100
|
-
return orderedKeys.map((key) => `${key}
|
|
122
|
+
return orderedKeys.map((key) => `${key}=${quoteEnvValue(values[key])}`).join('\n') + '\n';
|
|
101
123
|
}
|
|
102
124
|
|
|
103
125
|
function normalizeSecretsArgs(projectName, options) {
|
|
@@ -117,10 +139,12 @@ function resolvePullAuditArgs(projectName, options) {
|
|
|
117
139
|
}
|
|
118
140
|
|
|
119
141
|
export function diffSecretsEnvs(localSecrets = {}, remoteSecrets = {}) {
|
|
120
|
-
|
|
121
|
-
|
|
142
|
+
// Own-property checks: `in` matches inherited names (toString,
|
|
143
|
+
// __proto__), which would misclassify real vault keys.
|
|
144
|
+
const missingLocally = Object.keys(remoteSecrets).filter((k) => !Object.hasOwn(localSecrets, k));
|
|
145
|
+
const untrackedLocally = Object.keys(localSecrets).filter((k) => !Object.hasOwn(remoteSecrets, k));
|
|
122
146
|
const mismatched = Object.keys(remoteSecrets).filter(
|
|
123
|
-
(k) => k
|
|
147
|
+
(k) => Object.hasOwn(localSecrets, k) && String(localSecrets[k]) !== String(remoteSecrets[k])
|
|
124
148
|
);
|
|
125
149
|
return { missingLocally, mismatched, untrackedLocally };
|
|
126
150
|
}
|
|
@@ -298,6 +322,19 @@ async function pushSecretsMain(envFilePath, projectName, options = {}) {
|
|
|
298
322
|
});
|
|
299
323
|
return { keysChanged: false, restarted: false };
|
|
300
324
|
}
|
|
325
|
+
// Automated runs cannot answer prompts: skip the restart (fresh
|
|
326
|
+
// deploys pick up the values) instead of hanging on confirm.
|
|
327
|
+
if (opts.isHeadless || process.env.CI) {
|
|
328
|
+
console.log(color.dim('Headless environment detected: skipping the ECS restart prompt — new values apply on the next deployment or restart.'));
|
|
329
|
+
console.log(color.blue(`\n📘 Learn how secrets reach your app: ${color.underline('https://github.com/grada-run/grada/blob/main/apps/docs/src/content/docs/guides/secrets-management.md')}`));
|
|
330
|
+
await trackSuccess('secrets_pushed', {
|
|
331
|
+
projectName: resolvedProjectName,
|
|
332
|
+
secret_count: Object.keys(parsedSecrets).length,
|
|
333
|
+
keys_changed: false,
|
|
334
|
+
ecs_restart: false
|
|
335
|
+
});
|
|
336
|
+
return { keysChanged: false, restarted: false };
|
|
337
|
+
}
|
|
301
338
|
const shouldRestart = await confirm({
|
|
302
339
|
message: 'Keys are unchanged. Trigger a rolling ECS restart to apply new values immediately?',
|
|
303
340
|
initialValue: false,
|
|
@@ -436,17 +473,31 @@ async function pullSecretsMain(envFilePath, projectName, options = {}) {
|
|
|
436
473
|
}
|
|
437
474
|
}
|
|
438
475
|
|
|
439
|
-
|
|
476
|
+
// Null-prototype map: a `__proto__` vault key lands as an own data
|
|
477
|
+
// property instead of mutating the merge target's prototype.
|
|
478
|
+
const merged = Object.assign(Object.create(null), localSecrets);
|
|
440
479
|
for (const [key, value] of Object.entries(remoteSecrets)) {
|
|
441
|
-
if (!(key
|
|
480
|
+
if (!Object.hasOwn(merged, key) || overwrite) {
|
|
442
481
|
merged[key] = String(value);
|
|
443
482
|
}
|
|
444
483
|
}
|
|
445
484
|
|
|
446
485
|
const orderedKeys = [
|
|
447
486
|
...Object.keys(localSecrets),
|
|
448
|
-
...remoteKeys.filter((k) => !(k
|
|
487
|
+
...remoteKeys.filter((k) => !Object.hasOwn(localSecrets, k)),
|
|
449
488
|
];
|
|
489
|
+
const unrepresentable = orderedKeys.filter((key) =>
|
|
490
|
+
key === '__proto__' || quoteEnvValue(merged[key]) === null
|
|
491
|
+
);
|
|
492
|
+
if (unrepresentable.length > 0) {
|
|
493
|
+
const abort = new Error(
|
|
494
|
+
`Refusing to write ${resolvedFilePath}: ${unrepresentable.length} entr${unrepresentable.length === 1 ? 'y' : 'ies'} ` +
|
|
495
|
+
`cannot round-trip through .env quoting (${unrepresentable.join(', ')}). ` +
|
|
496
|
+
'Rename or re-encode them in the vault and retry.'
|
|
497
|
+
);
|
|
498
|
+
abort.code = 'SECRETS_PULL_UNREPRESENTABLE_VALUE';
|
|
499
|
+
throw abort;
|
|
500
|
+
}
|
|
450
501
|
await fs.writeFile(envPath, serializeEnv(orderedKeys, merged));
|
|
451
502
|
|
|
452
503
|
outro(`Successfully synced ${remoteKeys.length} secrets to ${resolvedFilePath}`);
|