UNPKG

@aws-amplify/cli-internal

Version:
97 lines 5.3 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthCognitoRollbackRefactorer = void 0; const category_refactorer_1 = require("../workflow/category-refactorer"); const rollback_category_refactorer_1 = require("../workflow/rollback-category-refactorer"); const utils_1 = require("../../_common/utils"); const auth_cognito_forward_1 = require("./auth-cognito-forward"); const amplify_cli_core_1 = require("@aws-amplify/amplify-cli-core"); const cfn_1 = require("../../_common/cfn"); class AuthCognitoRollbackRefactorer extends rollback_category_refactorer_1.RollbackCategoryRefactorer { resourceTypes() { return auth_cognito_forward_1.RESOURCE_TYPES; } async fetchSourceStackId() { return this.findNestedStack(this.gen2Branch, 'auth'); } async fetchDestStackId() { return this.findNestedStack(this.gen1Env, `auth${this.resource.resourceName}`); } async move(blueprint) { const baseOps = await super.move(blueprint); const gen2StackId = blueprint.sourceStackId; const gen2StackName = (0, utils_1.extractStackNameFromId)(gen2StackId); const holdingStackName = this.getHoldingStackName(gen2StackName); const holdingStack = await this.cfn.findStack(holdingStackName); if (!holdingStack) return baseOps; if (!cfn_1.VALID_HOLDING_STACK_STATUSES.includes(holdingStack.StackStatus)) { throw new amplify_cli_core_1.AmplifyError('StackStateError', { message: `Unexpected state of stack ${holdingStackName}: ${holdingStack.StackStatus} (expected ${cfn_1.VALID_HOLDING_STACK_STATUSES.join(', ')})`, }); } const template = await this.cfn.fetchTemplate(gen2StackId); const { domainLogicalId, idpLogicalIds } = (0, auth_cognito_forward_1.extractSocialAuthLogicalIds)(template); if (domainLogicalId || idpLogicalIds.size > 0) { const socialProvidersResourceIds = [...(domainLogicalId ? [domainLogicalId] : []), ...idpLogicalIds.values()]; const gen2StackName = (0, utils_1.extractStackNameFromId)(gen2StackId); const description = await (0, auth_cognito_forward_1.renderOrphanTable)(this.gen2Branch, socialProvidersResourceIds, template, gen2StackName, 'rollback'); baseOps.push({ resource: this.resource, validate: () => ({ description: `Deletion Protection (social auth): ${gen2StackName}`, run: async () => (0, category_refactorer_1.checkRetainPolicies)(template, socialProvidersResourceIds), }), describe: async () => [description], execute: () => this.cfn.orphan({ stackName: gen2StackId, logicalIds: socialProvidersResourceIds, resource: this.resource, }), }); } return baseOps; } async afterMove(blueprint) { const baseOps = await super.afterMove(blueprint); const gen2StackId = blueprint.sourceStackId; const gen2StackName = (0, utils_1.extractStackNameFromId)(gen2StackId); const holdingStackName = this.getHoldingStackName(gen2StackName); const holdingStack = await this.cfn.findStack(holdingStackName); if (!holdingStack) return baseOps; if (!cfn_1.VALID_HOLDING_STACK_STATUSES.includes(holdingStack.StackStatus)) { throw new amplify_cli_core_1.AmplifyError('StackStateError', { message: `Unexpected state of stack ${holdingStackName}: ${holdingStack.StackStatus} (expected ${cfn_1.VALID_HOLDING_STACK_STATUSES.join(', ')})`, }); } const holdingUserPoolId = await this.gen2Branch.fetchUserPoolId(holdingStackName); if (!holdingUserPoolId) return baseOps; const socialAuthConfig = await this.gen2Branch.fetchSocialAuthConfig(holdingUserPoolId); if (socialAuthConfig) { const template = await this.cfn.fetchTemplate(gen2StackId); const { domainLogicalId, idpLogicalIds } = (0, auth_cognito_forward_1.extractSocialAuthLogicalIds)(template); if (!domainLogicalId) { throw new amplify_cli_core_1.AmplifyError('MigrationError', { message: `Gen2 template '${gen2StackName}' has no UserPoolDomain resource for social auth import.`, }); } const { resourcesToImport, templateAdditions } = (0, auth_cognito_forward_1.buildImportSpec)(socialAuthConfig, domainLogicalId, idpLogicalIds); baseOps.push({ resource: this.resource, validate: () => undefined, describe: async () => [(0, auth_cognito_forward_1.renderImportTable)(resourcesToImport, gen2StackName)], execute: () => this.cfn.importResources({ stackName: gen2StackId, templateAdditions, resourcesToImport, resource: this.resource, }), }); } return baseOps; } } exports.AuthCognitoRollbackRefactorer = AuthCognitoRollbackRefactorer; //# sourceMappingURL=auth-cognito-rollback.js.map