UNPKG

@aws-amplify/cli-internal

Version:
77 lines 4.24 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AmplifyGen2MigrationValidations = void 0; const drift_1 = require("../../drift"); const amplify_cli_core_1 = require("@aws-amplify/amplify-cli-core"); const client_cloudformation_1 = require("@aws-sdk/client-cloudformation"); const execa_1 = __importDefault(require("execa")); const chalk_1 = __importDefault(require("chalk")); class AmplifyGen2MigrationValidations { constructor(logger, gen1App, context) { this.logger = logger; this.gen1App = gen1App; this.context = context; } async validateDrift() { var _a, _b; const result = await new drift_1.AmplifyDriftDetector(this.context, this.logger).detect(); if (result.code !== 0) { throw new amplify_cli_core_1.AmplifyError('DriftDetectedError', { message: (_b = (_a = result.report) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : 'Drift detected', resolution: 'Inspect the drift report above and resolve the drift', }); } } async validateWorkingDirectory() { this.logger.debug('Inspecting local directory state for uncommitted changes'); const { stdout: statusOutput } = await (0, execa_1.default)('git', ['status', '--porcelain']); if (statusOutput.trim()) { throw new amplify_cli_core_1.AmplifyError('UncommittedChangesError', { message: 'Working directory has uncommitted changes', resolution: 'Commit or stash your changes before proceeding with migration.', }); } } async validateDeploymentStatus() { this.logger.debug(`Inspecting root stack '${this.gen1App.rootStackName}' status`); const response = await this.gen1App.clients.cloudFormation.send(new client_cloudformation_1.DescribeStacksCommand({ StackName: this.gen1App.rootStackName })); if (!response.Stacks || response.Stacks.length === 0) { throw new amplify_cli_core_1.AmplifyError('StackNotFoundError', { message: `Stack ${this.gen1App.rootStackName} not found in CloudFormation`, resolution: 'Ensure the project is deployed.', }); } const stackStatus = response.Stacks[0].StackStatus; const validStatuses = ['UPDATE_COMPLETE', 'CREATE_COMPLETE', 'UPDATE_ROLLBACK_COMPLETE']; if (!validStatuses.includes(stackStatus)) { throw new amplify_cli_core_1.AmplifyError('StackStateError', { message: `Root stack status is ${stackStatus}, expected UPDATE_COMPLETE or CREATE_COMPLETE`, resolution: 'Complete the deployment before proceeding.', }); } } async validateLockStatus() { this.logger.debug(`Inspecting stack policy for ${this.gen1App.rootStackName}`); const { StackPolicyBody } = await this.gen1App.clients.cloudFormation.send(new client_cloudformation_1.GetStackPolicyCommand({ StackName: this.gen1App.rootStackName })); if (!StackPolicyBody) { throw new amplify_cli_core_1.AmplifyError('StackPolicyError', { message: 'Stack is not locked', resolution: 'Run the lock command before proceeding with migration.', }); } const currentPolicy = JSON.parse(StackPolicyBody); const hasLockStatement = currentPolicy.Statement.some((s) => s.Effect === 'Deny' && s.Action === 'Update:*' && s.Principal === '*' && s.Resource === '*'); if (!hasLockStatement) { throw new amplify_cli_core_1.AmplifyError('StackPolicyError', { message: 'Stack policy does not match expected lock policy', resolution: 'Run the lock command to set the correct stack policy.', }); } this.logger.debug(chalk_1.default.green(`Stack ${this.gen1App.rootStackName} is locked ✔`)); } } exports.AmplifyGen2MigrationValidations = AmplifyGen2MigrationValidations; //# sourceMappingURL=validations.js.map