UNPKG

@aws-amplify/amplify-category-auth

Version:

amplify-cli authentication plugin

36 lines 1.64 kB
"use strict"; const { JSONUtilities, pathManager } = require('@aws-amplify/amplify-cli-core'); const path = require('path'); const { generateUserPoolGroupStackTemplate } = require('./generate-user-pool-group-stack-template'); async function transformUserPoolGroupSchema(context) { const userPoolPrecedencePath = path.join(pathManager.getBackendDirPath(), 'auth', 'userPoolGroups', 'user-pool-group-precedence.json'); const { allResources } = await context.amplify.getResourceStatus(); const authResource = allResources.filter((resource) => resource.service === 'Cognito'); let authResourceName; if (authResource.length > 0) { const resource = authResource[0]; authResourceName = resource.resourceName; } else { throw new Error('Cognito UserPool does not exists'); } const groups = JSONUtilities.readJson(userPoolPrecedencePath); groups.forEach((group) => { if (group.customPolicies) { group.customPolicies.forEach((policy) => { if (policy.PolicyDocument && policy.PolicyDocument.Statement) { policy.PolicyDocument.Statement.forEach((statement) => { if (statement.Resource.includes('${env}')) { statement.Resource = { 'Fn::Sub': [statement.Resource, { env: { Ref: 'env' } }] }; } }); } }); } }); await generateUserPoolGroupStackTemplate(context, authResourceName); } module.exports = { transformUserPoolGroupSchema, }; //# sourceMappingURL=transform-user-pool-group.js.map