Skip to content

Commit

Permalink
fix: update current-cloud backend-config on resource removal (aws-amp…
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfoyle authored and Ross Ragsdale committed Nov 19, 2020
1 parent bc1770f commit aa4716d
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,7 @@ export const safeDefaults = [
];

// These attributes cannot be modified once the auth resource is created
export const immutableAttributes = [
'resourceName',
'userPoolName',
'identityPoolName',
'usernameAttributes',
'autoVerifiedAttributes',
'requiredAttributes',
];
export const immutableAttributes = ['resourceName', 'userPoolName', 'identityPoolName', 'usernameAttributes', 'requiredAttributes'];

export const privateKeys = [
'facebookAppIdUserPool',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ function moveBackendResourcesToCurrentCloudBackend(resources) {

fs.ensureDirSync(targetDir);

fs.copySync(sourceDir, targetDir);
// in the case that the resource is being deleted, the sourceDir won't exist
if (fs.pathExistsSync(sourceDir)) {
fs.copySync(sourceDir, targetDir);
}
}

fs.copySync(amplifyMetaFilePath, amplifyCloudMetaFilePath, { overwrite: true });
Expand Down Expand Up @@ -137,10 +140,12 @@ export async function updateamplifyMetaAfterPush(resources) {
// Skip hash calculation for imported resources
if (resources[i].serviceType !== 'imported') {
const sourceDir = path.normalize(path.join(pathManager.getBackendDirPath(), resources[i].category, resources[i].resourceName));
const hashDir = await getHashForResourceDir(sourceDir);

amplifyMeta[resources[i].category][resources[i].resourceName].lastPushDirHash = hashDir;
amplifyMeta[resources[i].category][resources[i].resourceName].lastPushTimeStamp = currentTimestamp;
// skip hashing deleted resources
if (fs.pathExistsSync(sourceDir)) {
const hashDir = await getHashForResourceDir(sourceDir);
amplifyMeta[resources[i].category][resources[i].resourceName].lastPushDirHash = hashDir;
amplifyMeta[resources[i].category][resources[i].resourceName].lastPushTimeStamp = currentTimestamp;
}
}

// If the operation was a remove-sync then for imported resources we cannot set timestamp
Expand Down
6 changes: 6 additions & 0 deletions packages/amplify-e2e-core/src/utils/projectMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ function getBackendConfig(projectRoot: string) {
return JSON.parse(fs.readFileSync(backendFConfigFilePath, 'utf8'));
}

function getCloudBackendConfig(projectRoot: string) {
const currentCloudPath = path.join(projectRoot, 'amplify', '#current-cloud-backend', 'backend-config.json');
return JSON.parse(fs.readFileSync(currentCloudPath, 'utf8'));
}

function getTeamProviderInfo(projectRoot: string) {
const teamProviderFilePath = path.join(projectRoot, 'amplify', 'team-provider-info.json');
return JSON.parse(fs.readFileSync(teamProviderFilePath, 'utf8'));
Expand Down Expand Up @@ -78,4 +83,5 @@ export {
getAmplifyDirPath,
getBackendConfig,
getTeamProviderInfo,
getCloudBackendConfig,
};
8 changes: 8 additions & 0 deletions packages/amplify-e2e-tests/src/__tests__/auth_5.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
addHeadlessAuth,
updateHeadlessAuth,
removeHeadlessAuth,
getCloudBackendConfig,
} from 'amplify-e2e-core';
import { addAuthWithDefault, getBackendAmplifyMeta } from 'amplify-e2e-core';
import { createNewProjectDir, deleteProjectDir, getProjectMeta, getUserPool } from 'amplify-e2e-core';
Expand Down Expand Up @@ -85,10 +86,17 @@ describe('headless auth', () => {
it('removes auth resource', async () => {
await initJSProjectWithProfile(projRoot, defaultsSettings);
await addAuthWithDefault(projRoot, {});
await amplifyPushAuth(projRoot);
const { auth: authBefore } = getBackendAmplifyMeta(projRoot);
const authResourceName = _.keys(authBefore).find(() => true); // first element or undefined
expect(authResourceName).toBeDefined();
const { auth: authBackendConfigBefore } = getCloudBackendConfig(projRoot);
expect(_.isEmpty(authBackendConfigBefore)).toBe(false);
await removeHeadlessAuth(projRoot, authResourceName);
await amplifyPushAuth(projRoot);
const { auth: authAfter } = getBackendAmplifyMeta(projRoot);
expect(_.isEmpty(authAfter)).toBe(true);
const { auth: authBackendConfigAfter } = getCloudBackendConfig(projRoot);
expect(_.isEmpty(authBackendConfigAfter)).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async function run(context, resourceDefinition) {
await postPushGraphQLCodegen(context);
await amplifyServiceManager.postPushCheck(context);

if (resources.length > 0) {
if (resources.concat(resourcesToBeDeleted).length > 0) {
await context.amplify.updateamplifyMetaAfterPush(resources);
}

Expand Down

0 comments on commit aa4716d

Please sign in to comment.