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(amplify-provider-awscloudformation): use amplify prompts for warnings #8731

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('sandbox mode helpers', () => {
},
} as unknown as $TSContext;

jest.spyOn(prompts.printer, 'info').mockImplementation();
jest.spyOn(prompts.printer, 'warn').mockImplementation();
jest.spyOn(apiKeyHelpers, 'hasApiKey').mockReturnValue(apiKeyPresent);
});

Expand All @@ -32,14 +32,10 @@ describe('sandbox mode helpers', () => {
it('displays warning', async () => {
await showSandboxModePrompts(ctx);

expect(prompts.printer.info).toBeCalledWith(
`
⚠️ WARNING: Global Sandbox Mode has been enabled, which requires a valid API key. If
you'd like to disable, remove ${chalk.green('"input AMPLIFY { globalAuthRule: AuthRule = { allow: public } }"')}
from your GraphQL schema and run 'amplify push' again. If you'd like to proceed with
sandbox mode disabled, do not create an API Key.
`,
'yellow',
expect(prompts.printer.warn).toBeCalledWith(
` Global Sandbox Mode has been enabled, which requires a valid API key. If you'd like to disable, remove ${chalk.green(
'"input AMPLIFY { globalAuthRule: AuthRule = { allow: public } }"',
)} from your GraphQL schema and run 'amplify push' again. If you'd like to proceed with sandbox mode disabled, do not create an API Key.\n`,
);
expect(ctx.amplify.invokePluginMethod).toBeCalledWith(ctx, 'api', undefined, 'promptToAddApiKey', [ctx]);
});
Expand All @@ -50,11 +46,8 @@ sandbox mode disabled, do not create an API Key.
it('prints sandbox api key message', () => {
showGlobalSandboxModeWarning();

expect(prompts.printer.info).toBeCalledWith(
`
⚠️ WARNING: your GraphQL API currently allows public create, read, update, and delete access to all models via an API Key. To configure PRODUCTION-READY authorization rules, review: https://docs.amplify.aws/cli/graphql-transformer/auth
`,
'yellow',
expect(prompts.printer.warn).toBeCalledWith(
` WARNING: Your GraphQL API currently allows public create, read, update, and delete access to all models via an API Key. To configure PRODUCTION-READY authorization rules, review: https://docs.amplify.aws/cli/graphql-transformer/auth\n`,
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,21 @@ const PUBLIC = 'public';

export async function showSandboxModePrompts(context: $TSContext): Promise<any> {
if (!hasApiKey()) {
printer.info(
`
⚠️ WARNING: Global Sandbox Mode has been enabled, which requires a valid API key. If
you'd like to disable, remove ${chalk.green('"input AMPLIFY { globalAuthRule: AuthRule = { allow: public } }"')}
from your GraphQL schema and run 'amplify push' again. If you'd like to proceed with
sandbox mode disabled, do not create an API Key.
`,
'yellow',
printer.warn(
` Global Sandbox Mode has been enabled, which requires a valid API key. If ` +
`you'd like to disable, remove ${chalk.green('"input AMPLIFY { globalAuthRule: AuthRule = { allow: public } }"')} ` +
`from your GraphQL schema and run 'amplify push' again. If you'd like to proceed with ` +
`sandbox mode disabled, do not create an API Key.\n`,
);
return await context.amplify.invokePluginMethod(context, 'api', undefined, 'promptToAddApiKey', [context]);
}
}

export function showGlobalSandboxModeWarning(): void {
printer.info(
`
⚠️ WARNING: your GraphQL API currently allows public create, read, update, and delete access to all models via an API Key. To configure PRODUCTION-READY authorization rules, review: https://docs.amplify.aws/cli/graphql-transformer/auth
`,
'yellow',
printer.warn(
` WARNING: Your GraphQL API currently allows public create, read, update, and delete ` +
cjihrig marked this conversation as resolved.
Show resolved Hide resolved
`access to all models via an API Key. To configure PRODUCTION-READY authorization rules, ` +
`review: https://docs.amplify.aws/cli/graphql-transformer/auth\n`,
);
}

Expand Down