Skip to content

Commit

Permalink
fix: data inconsitency (#5344)
Browse files Browse the repository at this point in the history
* fix: data inconsistency
  • Loading branch information
ammarkarachi committed Sep 23, 2020
1 parent 2200f51 commit bfe1903
Show file tree
Hide file tree
Showing 86 changed files with 316 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
context.print.info(err.stack);
context.print.error('There was an error adding the analytics resource');
context.usageData.emitError(err);
process.exitCode = 1;
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
context.print.info(err.stack);
context.print.error('An error occurred when pushing the analytics resource');
context.usageData.emitError(err);
process.exitCode = 1;
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
context.print.info(err.stack);
context.print.error('An error occurred when removing the analytics resource');
context.usageData.emitError(err);
process.exitCode = 1;
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = {
context.print.info(err.stack);
context.print.error(`There was an error updating the ${category} resource`);
context.usageData.emitError(err);
process.exitCode = 1;
});
},
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { NotImplementedError } from 'amplify-cli-core';
function addResource(context, category, service) {
const serviceMetadata = context.amplify.readJsonFile(`${__dirname}/../supported-services.json`)[service];
const { defaultValuesFilename, serviceWalkthroughFilename } = serviceMetadata;
Expand All @@ -15,7 +16,9 @@ function updateResource(context, category, service) {
const { updateWalkthrough } = require(serviceWalkthroughSrc);

if (!updateWalkthrough) {
context.print.error('Update functionality not available for this service');
const message = 'Update functionality not available for this service';
context.print.error(message);
context.usageData.emitError(new NotImplementedError(message));
process.exit(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ const path = require('path');
// FIXME: may be removed from here, since addResource can pass category to addWalkthrough
const category = 'analytics';
const service = 'Kinesis';
const { ResourceAlreadyExistsError, ResourceDoesNotExistError } = require('amplify-cli-core');

async function addWalkthrough(context, defaultValuesFilename, serviceMetadata) {
const resourceName = resourceAlreadyExists(context);

if (resourceName) {
context.print.warning('Kinesis resource have already been added to your project.');
const errMessage = 'Kinesis resource have already been added to your project.';
context.print.warning(errMessage);
context.usageData.emitError(new ResourceAlreadyExistsError(errMessage));
process.exit(0);
}
return configure(context, defaultValuesFilename, serviceMetadata);
Expand Down Expand Up @@ -130,7 +133,9 @@ async function updateWalkthrough(context, defaultValuesFilename, serviceMetadata

let targetResourceName;
if (kinesisResources.length === 0) {
context.print.error('No Kinesis streams resource to update. Please use "amplify add analytics" command to create a new Kinesis stream');
const errMessage = 'No Kinesis streams resource to update. Please use "amplify add analytics" command to create a new Kinesis stream';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
return;
} else if (kinesisResources.length === 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ const category = 'analytics';
const parametersFileName = 'parameters.json';
const serviceName = 'Pinpoint';
const templateFileName = 'pinpoint-cloudformation-template.json';
import { ResourceAlreadyExistsError } from 'amplify-cli-core';

async function addWalkthrough(context, defaultValuesFilename, serviceMetadata) {
const resourceName = resourceAlreadyExists(context);

if (resourceName) {
context.print.warning('Pinpoint analytics have already been added to your project.');
const errMessage = 'Pinpoint analytics have already been added to your project.';
context.print.warning(errMessage);
context.usageData.emitError(new ResourceAlreadyExistsError(errMessage));
process.exit(0);
} else {
return configure(context, defaultValuesFilename, serviceMetadata);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require('path');
const { RelationalDBSchemaTransformer } = require('graphql-relational-schema-transformer');
const { RelationalDBTemplateGenerator, AuroraServerlessMySQLDatabaseReader } = require('graphql-relational-schema-transformer');
const { mergeTypeDefs } = require('@graphql-tools/merge');
const { ResourceDoesNotExistError } = require('amplify-cli-core');

const subcommand = 'add-graphql-datasource';
const categories = 'categories';
Expand Down Expand Up @@ -164,6 +165,7 @@ module.exports = {
context.print.info(err.stack);
context.print.error('There was an error adding the datasource');
context.usageData.emitError(err);
process.exitCode = 1;
});
},
readSchema,
Expand All @@ -186,7 +188,9 @@ function datasourceSelectionPrompt(context, supportedDatasources) {
});

if (options.length === 0) {
context.print.error(`No datasources defined by configured providers for category: ${category}`);
const errMessage = `No datasources defined by configured providers for category: ${category}`;
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(1);
}

Expand Down
1 change: 1 addition & 0 deletions packages/amplify-category-api/src/commands/api/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
context.print.info(err.stack);
context.print.error('There was an error adding the API resource');
context.usageData.emitError(err);
process.exitCode = 1;
});
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-api/src/commands/api/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ module.exports = {
context.print.error('Error opening console.');
context.print.info(err.message);
context.usageData.emitError(err);
process.exitCode = 1;
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
} catch (err) {
context.print.error(err.toString());
context.usageData.emitError(err);
process.exitCode = 1;
}
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-api/src/commands/api/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
context.print.error('There was an error pushing the API resource');
context.print.error(err.toString());
context.usageData.emitError(err);
process.exitCode = 1;
});
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-api/src/commands/api/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = {
context.print.info(err.stack);
context.print.error('There was an error removing the api resource');
context.usageData.emitError(err);
process.exitCode = 1;
});
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-api/src/commands/api/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
context.print.error(err.message);
console.log(err.stack);
context.usageData.emitError(err);
process.exitCode = 1;
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import { legacyAddResource } from './legacy-add-resource';
import { legacyUpdateResource } from './legacy-update-resource';
import { UpdateApiRequest } from 'amplify-headless-interface';
import { editSchemaFlow } from './utils/edit-schema-flow';
import { NotImplementedError } from 'amplify-cli-core';

export async function console(context, service) {
const { serviceWalkthroughFilename } = await serviceMetadataFor(service);
const serviceWalkthroughSrc = `${__dirname}/service-walkthroughs/${serviceWalkthroughFilename}`;
const { openConsole } = require(serviceWalkthroughSrc);

if (!openConsole) {
context.print.error('Opening console functionality not available for this option');
const errMessage = 'Opening console functionality not available for this option';
context.print.error(errMessage);
context.usageData.emitError(new NotImplementedError(errMessage));
process.exit(0);
}

Expand Down Expand Up @@ -46,7 +49,9 @@ export async function updateResource(context, category, service) {
const { updateWalkthrough } = require(serviceWalkthroughSrc);

if (!updateWalkthrough) {
context.print.error('Update functionality not available for this option');
const errMessage = 'Update functionality not available for this option';
context.print.error(errMessage);
context.usageData.emitError(new NotImplementedError(errMessage));
process.exit(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import uuid from 'uuid';
import { rootAssetDir } from '../aws-constants';
import { checkForPathOverlap, validatePathName, formatCFNPathParamsForExpressJs } from '../utils/rest-api-path-utils';
import { ServiceName as FunctionServiceName } from 'amplify-category-function';
import { ResourceDoesNotExistError } from 'amplify-cli-core';

const category = 'api';
const serviceName = 'API Gateway';
Expand Down Expand Up @@ -37,7 +38,9 @@ export async function updateWalkthrough(context, defaultValuesFilename) {

// There can only be one appsync resource
if (resources.length === 0) {
context.print.error('No REST API resource to update. Please use "amplify add api" command to create a new REST API');
const errMessage = 'No REST API resource to update. Please use "amplify add api" command to create a new REST API';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
return;
}
Expand Down Expand Up @@ -68,9 +71,9 @@ export async function updateWalkthrough(context, defaultValuesFilename) {
const updateApi = await inquirer.prompt(question);

if (updateApi.resourceName === 'AdminQueries') {
context.print.warning(
`The Admin Queries API is maintained through the Auth category and should be updated using 'amplify update auth' command`,
);
const errMessage = `The Admin Queries API is maintained through the Auth category and should be updated using 'amplify update auth' command`;
context.print.warning(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const inquirer = require('inquirer');
const ora = require('ora');
const { DataApiParams } = require('graphql-relational-schema-transformer');
const { ResourceDoesNotExistError, ResourceCredentialsNotFoundError } = require('amplify-cli-core');

const spinner = ora('');
const category = 'api';
Expand All @@ -11,9 +12,10 @@ async function serviceWalkthrough(context, defaultValuesFilename, datasourceMeta

// Verify that an API exists in the project before proceeding.
if (amplifyMeta == null || amplifyMeta[category] == null || Object.keys(amplifyMeta[category]).length === 0) {
context.print.error(
'You must create an AppSync API in your project before adding a graphql datasource. Please use "amplify api add" to create the API.',
);
const errMessage =
'You must create an AppSync API in your project before adding a graphql datasource. Please use "amplify api add" to create the API.';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
}

Expand All @@ -30,9 +32,10 @@ async function serviceWalkthrough(context, defaultValuesFilename, datasourceMeta

// If an AppSync API does not exist, inform the user to create the AppSync API
if (!appSyncApi) {
context.print.error(
'You must create an AppSync API in your project before adding a graphql datasource. Please use "amplify api add" to create the API.',
);
const errMessage =
'You must create an AppSync API in your project before adding a graphql datasource. Please use "amplify api add" to create the API.';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
}

Expand Down Expand Up @@ -92,7 +95,9 @@ async function selectCluster(context, inputs, AWS) {
clusterResourceId: selectedCluster.DbClusterResourceId,
};
}
context.print.error('No properly configured Aurora Serverless clusters found.');
const errMessage = 'No properly configured Aurora Serverless clusters found.';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
}

Expand Down Expand Up @@ -142,7 +147,9 @@ async function getSecretStoreArn(context, inputs, clusterResourceId, AWS) {
const selectedSecretName = await promptWalkthroughQuestion(inputs, 2, Array.from(secrets.keys()));
selectedSecretArn = secrets.get(selectedSecretName);
} else {
context.print.error('No RDS access credentials found in the AWS Secrect Manager.');
const errMessage = 'No RDS access credentials found in the AWS Secrect Manager.';
context.print.error(errMessage);
context.usageData.emitError(new ResourceCredentialsNotFoundError(errMessage));
process.exit(0);
}
}
Expand Down Expand Up @@ -185,7 +192,9 @@ async function selectDatabase(context, inputs, clusterArn, secretArn, AWS) {
return await promptWalkthroughQuestion(inputs, 3, databaseList);
}

context.print.error('No properly configured databases found.');
const errMessage = 'No properly configured databases found.';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { authConfigToAppSyncAuthType } from '../utils/auth-config-to-app-sync-au
import { resolverConfigToConflictResolution } from '../utils/resolver-config-to-conflict-resolution-bi-di-mapper';
import _ from 'lodash';
import { getAppSyncAuthConfig, checkIfAuthExists, authConfigHasApiKey } from '../utils/amplify-meta-utils';
import { ResourceAlreadyExistsError, ResourceDoesNotExistError, UnknownResourceTypeError } from 'amplify-cli-core';

const serviceName = 'AppSync';
const providerName = 'awscloudformation';
Expand Down Expand Up @@ -64,9 +65,10 @@ export const serviceWalkthrough = async (context, defaultValuesFilename, service
let resolverConfig;

if (resourceName) {
context.print.warning(
'You already have an AppSync API in your project. Use the "amplify update api" command to update your existing AppSync API.',
);
const errMessage =
'You already have an AppSync API in your project. Use the "amplify update api" command to update your existing AppSync API.';
context.print.warning(errMessage);
context.usageData.emitError(new ResourceAlreadyExistsError(errMessage));
process.exit(0);
}

Expand Down Expand Up @@ -175,7 +177,9 @@ export const updateWalkthrough = async (context): Promise<UpdateApiRequest> => {
const backEndDir = context.amplify.pathManager.getBackendDirPath();
resourceDir = path.normalize(path.join(backEndDir, category, resourceName));
} else {
context.print.error('No AppSync resource to update. Use the "amplify add api" command to update your existing AppSync API.');
const errMessage = 'No AppSync resource to update. Use the "amplify add api" command to update your existing AppSync API.';
context.print.error(errMessage);
context.usageData.emitError(new ResourceDoesNotExistError(errMessage));
process.exit(0);
}

Expand Down Expand Up @@ -492,7 +496,9 @@ async function askAuthQuestions(authType, context, printLeadText = false) {
return openIDConnectConfig;
}

context.print.error(`Unknown authType: ${authType}`);
const errMessage = `Unknown authType: ${authType}`;
context.print.error(errMessage);
context.usageData.emitError(new UnknownResourceTypeError(errMessage));
process.exit(1);
}

Expand Down
1 change: 1 addition & 0 deletions packages/amplify-category-auth/src/commands/auth/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module.exports = {
context.print.info(err.stack);
context.print.error('There was an error pushing the auth resource');
context.usageData.emitError(err);
process.exitCode = 1;
});
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-auth/src/commands/auth/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ module.exports = {
context.print.info(err.stack);
context.print.error('There was an error adding the auth resource');
context.usageData.emitError(err);
process.exitCode = 1;
});
},
};
1 change: 1 addition & 0 deletions packages/amplify-category-auth/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ async function add(context) {
context.print.info(err.stack);
context.print.error('There was an error adding the auth resource');
context.usageData.emitError(err);
process.exitCode = 1;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const getAddAuthHandler = (context: any) => async (request: ServiceQuesti
context.print.info(err.stack);
context.print.error('There was an error adding the auth resource');
context.usageData.emitError(err);
process.exitCode = 1;
});
return requestWithDefaults.resourceName!;
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = {
context.print.info(err.stack);
context.print.error('There was an error adding the function resource');
context.usageData.emitError(err);
process.exitCode = 1;
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
context.print.info(err.stack);
context.print.error('There was an error building the function resources');
context.usageData.emitError(err);
process.exitCode = 1;
});
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = {
context.print.info(err.stack);
context.print.error('An error occurred when pushing the function resource');
context.usageData.emitError(err);
process.exitCode = 1;
});
},
};

0 comments on commit bfe1903

Please sign in to comment.