grada-run 0.49.7 → 0.49.8
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
CHANGED
package/src/commands/apply.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import fs from 'fs';
|
|
3
|
-
import { intro, outro, spinner, log, cancel, confirm, isCancel } from '@clack/prompts';
|
|
3
|
+
import { intro, outro, spinner, log, cancel, confirm, isCancel, select } from '@clack/prompts';
|
|
4
4
|
import color from 'picocolors';
|
|
5
|
+
import { SecretsManagerClient, RestoreSecretCommand, DescribeSecretCommand, DeleteSecretCommand } from '@aws-sdk/client-secrets-manager';
|
|
5
6
|
import { renderDryRunPreview, parseTerraformConfig, buildCostTelemetryProps } from '../utils/visualizer.js';
|
|
6
7
|
import { detectFramework } from '../utils/detector.js';
|
|
7
8
|
import { trackEvent, flushTelemetry, trackSuccess, trackFailure, setActiveCommandName, resetActiveCommandName, isCliEntry } from '../core/telemetry.js';
|
|
@@ -17,7 +18,7 @@ import { requireAwakeEnvironment, resolveSleepTarget, guardSleepingEnv } from '.
|
|
|
17
18
|
import { promptStateBucketRecovery, recreateStateBucket } from '../utils/recovery.js';
|
|
18
19
|
import { resolveProjectName, readResourceSuffix } from '../utils/resolvers.js';
|
|
19
20
|
import { ensureLambdaSeedImage } from '../utils/lambda-ecr.js';
|
|
20
|
-
import { checkAwsCredentials, ensureStateBucketExists, isAuthError, printAwsAuthGuidance } from '../utils/aws.js';
|
|
21
|
+
import { checkAwsCredentials, ensureStateBucketExists, isAuthError, printAwsAuthGuidance, resolveClient } from '../utils/aws.js';
|
|
21
22
|
import { findUnreconciledFiles, isValidAccountId, PLACEHOLDER_ACCOUNT_ID } from '../utils/reconcile.js';
|
|
22
23
|
import { runWake } from './wake.js';
|
|
23
24
|
|
|
@@ -944,12 +945,74 @@ async function applyStackMain(input = {}) {
|
|
|
944
945
|
}
|
|
945
946
|
}
|
|
946
947
|
}
|
|
948
|
+
let secretRecoveryError = null;
|
|
949
|
+
if (code === 'SECRET_PENDING_DELETION' && secretName && options._secretRecovered !== true) {
|
|
950
|
+
// Offer the recovery in-flow instead of shelling the user
|
|
951
|
+
// out to pasted AWS CLI + raw terraform; declined, failed,
|
|
952
|
+
// dismissed, or unparseable runs fall through to the
|
|
953
|
+
// runbook below. Restore is non-destructive (auto under
|
|
954
|
+
// --auto-approve); force-delete always needs an explicit
|
|
955
|
+
// interactive choice, never auto.
|
|
956
|
+
const refused = await refuseIfNonInteractive(options, {
|
|
957
|
+
message: '\n✖ apply needs approval to recover the deleted secret vault.',
|
|
958
|
+
hint: ' Re-run with --auto-approve to restore non-interactively.\n',
|
|
959
|
+
event: 'infrastructure_applied',
|
|
960
|
+
telemetry: { projectName: actualProjectName },
|
|
961
|
+
errorCode: 'SECRET_RECOVERY_NON_INTERACTIVE',
|
|
962
|
+
});
|
|
963
|
+
if (refused) return refused;
|
|
964
|
+
let method = shouldAutoApprove(options) ? 'restore' : null;
|
|
965
|
+
if (!method) {
|
|
966
|
+
const choice = await select({
|
|
967
|
+
message: `Secret "${secretName}" is scheduled for deletion — recover it and retry?`,
|
|
968
|
+
options: [
|
|
969
|
+
{ value: 'restore', label: 'Restore the vault, import, and retry' },
|
|
970
|
+
{ value: 'force-delete', label: 'Force-delete without recovery and retry' },
|
|
971
|
+
{ value: 'cancel', label: 'Cancel (show manual steps)' },
|
|
972
|
+
],
|
|
973
|
+
});
|
|
974
|
+
if (!isCancel(choice) && (choice === 'restore' || choice === 'force-delete')) method = choice;
|
|
975
|
+
}
|
|
976
|
+
if (method) {
|
|
977
|
+
try {
|
|
978
|
+
const targetRegion = detectedConfig.region || process.env.AWS_REGION || 'us-east-2';
|
|
979
|
+
const client = resolveClient(options.secretsClient, SecretsManagerClient, { region: targetRegion });
|
|
980
|
+
if (method === 'restore') {
|
|
981
|
+
await client.send(new RestoreSecretCommand({ SecretId: secretName }));
|
|
982
|
+
const described = await client.send(new DescribeSecretCommand({ SecretId: secretName }));
|
|
983
|
+
if (!described || !described.ARN) {
|
|
984
|
+
throw new Error(`DescribeSecret returned no ARN for "${secretName}".`);
|
|
985
|
+
}
|
|
986
|
+
// Argv-spawned (no shell), so the count index
|
|
987
|
+
// needs no quoting — unlike the printed runbook.
|
|
988
|
+
await runTerraform(['import', 'aws_secretsmanager_secret.app_secrets[0]', described.ARN], tfDir, null, `Importing ${secretName}`);
|
|
989
|
+
} else {
|
|
990
|
+
await client.send(new DeleteSecretCommand({ SecretId: secretName, ForceDeleteWithoutRecovery: true }));
|
|
991
|
+
}
|
|
992
|
+
} catch (error) {
|
|
993
|
+
secretRecoveryError = error;
|
|
994
|
+
}
|
|
995
|
+
if (secretRecoveryError === null) {
|
|
996
|
+
trackEvent('secret_deletion_recovered', { projectName: actualProjectName, method });
|
|
997
|
+
if (method === 'restore') {
|
|
998
|
+
log.message(color.cyan('Restored the secret vault and imported it — retrying apply...'));
|
|
999
|
+
} else {
|
|
1000
|
+
log.message(color.cyan('Force-deleted the secret vault — retrying apply...'));
|
|
1001
|
+
log.message(color.dim(' Re-push your secrets after apply (secrets push): the vault is recreated empty.'));
|
|
1002
|
+
}
|
|
1003
|
+
return applyStack({ ...options, _skipPreview: true, _secretRecovered: true });
|
|
1004
|
+
}
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
947
1007
|
const runbook = getRunbook(code, { headless: shouldAutoApprove(options), lockId, secretName });
|
|
948
1008
|
log.error(color.red(`✖ ${runbook.message}`));
|
|
949
1009
|
log.message(` ${runbook.hint}\n`);
|
|
950
1010
|
if (reconfigureError) {
|
|
951
1011
|
log.message(color.dim(` (Automatic reconfigure failed: ${reconfigureError.message})`));
|
|
952
1012
|
}
|
|
1013
|
+
if (secretRecoveryError) {
|
|
1014
|
+
log.message(color.dim(` (Automatic recovery failed: ${secretRecoveryError.message})`));
|
|
1015
|
+
}
|
|
953
1016
|
log.message(color.dim(errString.split('\n').slice(0, 8).join('\n')));
|
|
954
1017
|
} else {
|
|
955
1018
|
// Generic fallback for unknown errors
|
|
@@ -161,8 +161,8 @@ const RUNBOOKS = {
|
|
|
161
161
|
},
|
|
162
162
|
SECRET_PENDING_DELETION: {
|
|
163
163
|
message: 'A Secrets Manager secret is scheduled for deletion.',
|
|
164
|
-
headless: 'Restore it (aws secretsmanager restore-secret --secret-id <name>, then cd terraform && terraform import aws_secretsmanager_secret.app_secrets <arn>) or force-delete without recovery (aws secretsmanager delete-secret --secret-id <name> --force-delete-without-recovery) and re-apply + push — fetch the ARN via aws secretsmanager describe-secret --secret-id <name> --query ARN --output text. Grada never force-deletes: the window protects against accidental loss.',
|
|
165
|
-
interactive: 'Restore it (aws secretsmanager restore-secret --secret-id <name>, then cd terraform && terraform import aws_secretsmanager_secret.app_secrets <arn>) or force-delete without recovery (aws secretsmanager delete-secret --secret-id <name> --force-delete-without-recovery) and re-apply + push — fetch the ARN via aws secretsmanager describe-secret --secret-id <name> --query ARN --output text. Grada never force-deletes: the window protects against accidental loss.',
|
|
164
|
+
headless: 'Restore it (aws secretsmanager restore-secret --secret-id <name>, then cd terraform && terraform import \'aws_secretsmanager_secret.app_secrets[0]\' <arn>) or force-delete without recovery (aws secretsmanager delete-secret --secret-id <name> --force-delete-without-recovery) and re-apply + push — fetch the ARN via aws secretsmanager describe-secret --secret-id <name> --query ARN --output text. Grada never force-deletes: the window protects against accidental loss.',
|
|
165
|
+
interactive: 'Restore it (aws secretsmanager restore-secret --secret-id <name>, then cd terraform && terraform import \'aws_secretsmanager_secret.app_secrets[0]\' <arn>) or force-delete without recovery (aws secretsmanager delete-secret --secret-id <name> --force-delete-without-recovery) and re-apply + push — fetch the ARN via aws secretsmanager describe-secret --secret-id <name> --query ARN --output text. Grada never force-deletes: the window protects against accidental loss.',
|
|
166
166
|
},
|
|
167
167
|
};
|
|
168
168
|
|