in provider-utils/awscloudformation/service-walkthroughs/vod-push.js [546:610]
async function authGroupHack(context, bucketName) {
const userPoolGroupFile = path.join(
context.amplify.pathManager.getBackendDirPath(),
'auth',
'userPoolGroups',
'user-pool-group-precedence.json',
);
const amplifyMeta = context.amplify.getProjectMeta();
if (!('auth' in amplifyMeta) || Object.keys(amplifyMeta.auth).length === 0) {
context.print.error('You have no auth projects. Moving on.');
return;
}
let resourceName = '';
Object.keys(amplifyMeta.auth).forEach((authCategory) => {
if (amplifyMeta.auth[authCategory].service === 'Cognito') {
resourceName = authCategory;
}
});
if (fs.existsSync(userPoolGroupFile)) {
const userPoolGroup = JSON.parse(fs.readFileSync(userPoolGroupFile));
if (userPoolGroup.length === 0) {
userPoolGroup.push(generateIAMAdmin(resourceName, bucketName));
} else {
userPoolGroup.forEach((userGroup, index) => {
if (userGroup.groupName === 'Admin') {
if (!('customPolicies' in userGroup)) {
userGroup.customPolicies = [];
}
const policy = generateIAMAdminPolicy(resourceName, bucketName);
if (!userGroup.customPolicies.some(
(existingPolicy) => existingPolicy.PolicyName === policy.PolicyName,
)) {
userGroup.customPolicies.push(policy);
}
return;
}
if (userPoolGroup.length === index + 1) {
userPoolGroup.push(generateIAMAdmin(resourceName, bucketName));
}
});
}
updateUserPoolGroups(context, userPoolGroup);
} else {
const admin = generateIAMAdmin(resourceName, bucketName);
const userPoolGroupList = [admin];
updateUserPoolGroups(context, userPoolGroupList);
context.amplify.updateamplifyMetaAfterResourceAdd('auth', 'userPoolGroups', {
service: 'Cognito-UserPool-Groups',
providerPlugin: 'awscloudformation',
dependsOn: [
{
category: 'auth',
resourceName,
attributes: ['UserPoolId', 'AppClientIDWeb', 'AppClientID', 'IdentityPoolId'],
},
],
});
}
}