Skip to content

Commit

Permalink
fix(amplify-category-notifications): fix notifications env change iss…
Browse files Browse the repository at this point in the history
…ue (#2669)

* fix(amplify-category-notifications): fix notifications env change issue

fix #2616

* store current cloud backend to deployment bucket after notifications changes
  • Loading branch information
UnleashedMind committed Nov 25, 2019
1 parent 377dfa7 commit 54d4d64
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ async function pushChanges(context, pinpointNotificationsMeta) {
}
});

await pinpointHelper.ensurePinpointApp(context, pinpointNotificationsMeta.resourceName);
await pinpointHelper.ensurePinpointApp(context, pinpointNotificationsMeta);

const tasks = [];
channelsToEnable.forEach(channel => {
Expand Down Expand Up @@ -207,6 +207,7 @@ async function writeData(context) {
writeBackendConfig(context, pinpointMeta, context.amplify.pathManager.getCurrentBackendConfigFilePath());
writeAmplifyMeta(context, categoryMeta, context.amplify.pathManager.getAmplifyMetaFilePath());
writeAmplifyMeta(context, categoryMeta, context.amplify.pathManager.getCurrentAmplifyMetaFilePath());
await context.amplify.storeCurrentCloudBackend(context);
await context.amplify.onCategoryOutputsChange(context);
}

Expand Down
59 changes: 42 additions & 17 deletions packages/amplify-category-notifications/lib/pinpoint-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,54 @@ function getPinpointApp(context) {
return pinpointApp;
}

async function ensurePinpointApp(context, resourceName) {
async function ensurePinpointApp(context, pinpointNotificationsMeta) {
let pinpointApp;
let resourceName;
const { amplifyMeta, localEnvInfo } = context.exeInfo;
const scanOptions = {
isRegulatingResourceName: true,
envName: localEnvInfo.envName,
};
let pinpointApp = scanCategoryMetaForPinpoint(amplifyMeta[constants.CategoryName], scanOptions);
if (pinpointApp) {
resourceName = scanOptions.regulatedResourceName;
} else {

if (pinpointNotificationsMeta) {
if (
pinpointNotificationsMeta.service === constants.PinpointName &&
pinpointNotificationsMeta.output &&
pinpointNotificationsMeta.output.Id
) {
if (pinpointNotificationsMeta.resourceName) {
resourceName = pinpointNotificationsMeta.resourceName; //eslint-disable-line
} else {
resourceName = generateResourceName(pinpointNotificationsMeta.Name, localEnvInfo.envName);
}

pinpointApp = pinpointNotificationsMeta.output;
constructResourceMeta(amplifyMeta, resourceName, pinpointApp);
} else {
resourceName = pinpointNotificationsMeta.resourceName; //eslint-disable-line
}
}

if (!pinpointApp) {
const scanOptions = {
isRegulatingResourceName: true,
envName: localEnvInfo.envName,
};
pinpointApp = scanCategoryMetaForPinpoint(amplifyMeta[constants.CategoryName], scanOptions);
if (pinpointApp) {
resourceName = scanOptions.regulatedResourceName;
}
}

if (!pinpointApp) {
pinpointApp = scanCategoryMetaForPinpoint(amplifyMeta[constants.AnalyticsCategoryName]);
if (pinpointApp) {
resourceName = generateResourceName(pinpointApp.Name, localEnvInfo.envName);
constructResourceMeta(amplifyMeta, resourceName, pinpointApp);
} else {
context.print.info('');
resourceName = await createPinpointApp(context, resourceName);
}
}

if (!pinpointApp) {
context.print.info('');
resourceName = await createPinpointApp(context, resourceName);
}

context.exeInfo.serviceMeta = context.exeInfo.amplifyMeta[constants.CategoryName][resourceName];
context.exeInfo.pinpointApp = context.exeInfo.serviceMeta.output;
}
Expand Down Expand Up @@ -96,11 +125,7 @@ function constructResourceMeta(amplifyMeta, resourceName, pinpointApp) {
amplifyMeta[constants.CategoryName] = amplifyMeta[constants.CategoryName] || {};
amplifyMeta[constants.CategoryName][resourceName] = {
service: constants.PinpointName,
output: {
Name: pinpointApp.Name,
Id: pinpointApp.Id,
Region: pinpointApp.Region,
},
output: pinpointApp,
lastPushTimeStamp: new Date(),
};
}
Expand Down
6 changes: 6 additions & 0 deletions packages/amplify-cli/src/domain/amplify-toolkit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class AmplifyToolkit {
private _pathManager: any;
private _pressEnterToContinue: any;
private _pushResources: any;
private _storeCurrentCloudBackend: any;
private _readJsonFile: any;
private _removeEnvFromCloud: any;
private _removeResource: any;
Expand Down Expand Up @@ -205,6 +206,11 @@ export class AmplifyToolkit {
this._pushResources = this._pushResources || require(path.join(this._amplifyHelpersDirPath, 'push-resources')).pushResources;
return this._pushResources;
}
get storeCurrentCloudBackend(): any {
this._storeCurrentCloudBackend = this._storeCurrentCloudBackend ||
require(path.join(this._amplifyHelpersDirPath, 'push-resources')).storeCurrentCloudBackend;
return this._storeCurrentCloudBackend;
}
get readJsonFile(): any {
this._readJsonFile = this._readJsonFile || require(path.join(this._amplifyHelpersDirPath, 'read-json-file')).readJsonFile;
return this._readJsonFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ async function providersPush(context, category, resourceName, filteredResources)
await Promise.all(providerPromises);
}

async function storeCurrentCloudBackend(context) {
const { providers } = getProjectConfig();
const providerPlugins = getProviderPlugins(context);
const providerPromises = [];

for (let i = 0; i < providers.length; i += 1) {
const providerModule = require(providerPlugins[providers[i]]);
providerPromises.push(providerModule.storeCurrentCloudBackend(context));
}

await Promise.all(providerPromises);
}

module.exports = {
pushResources,
storeCurrentCloudBackend,
};
5 changes: 5 additions & 0 deletions packages/amplify-provider-awscloudformation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ function pushResources(context, resourceList) {
return resourcePusher.run(context, resourceList);
}

function storeCurrentCloudBackend(context) {
return resourcePusher.storeCurrentCloudBackend(context);
}

function deleteEnv(context, envName, deleteS3) {
return envRemover.run(context, envName, deleteS3);
}
Expand Down Expand Up @@ -96,6 +100,7 @@ module.exports = {
configureNewUser,
constants,
pushResources,
storeCurrentCloudBackend,
buildResources,
providerUtils,
setupNewUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,5 @@ function updateIdPRolesInNestedStack(context, nestedStack, authResourceName) {
module.exports = {
run,
updateStackForAPIMigration,
storeCurrentCloudBackend,
};

0 comments on commit 54d4d64

Please sign in to comment.