Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update current-cloud backend-config on resource removal #5658

Merged
merged 2 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
kaustavghosh06 marked this conversation as resolved.
Show resolved Hide resolved
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) {
kaustavghosh06 marked this conversation as resolved.
Show resolved Hide resolved
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) {
kaustavghosh06 marked this conversation as resolved.
Show resolved Hide resolved
await context.amplify.updateamplifyMetaAfterPush(resources);
}

Expand Down