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

Allow 3rd-party plugin to CDK override #9601

Merged
merged 6 commits into from May 31, 2022

Conversation

fossamagna
Copy link
Contributor

Description of changes

Allow 3rd-party plugin to CDK override. Some restricted points to starts with @aws-amplify/amplify-category- literal changed to use package location in pluginInfo.

Issue #, if available

fix #9226

Description of how you validated changes

  • Unitt Testing
  • Manual Testing (using 3rd-party plugin)
    1. Setup Local Enviroment
      1. Run git clone -b allow-3rd-party-override git@github.com:fossamagna/amplify-cli.git
      2. Setup local environment
        1. Run cd amlify-cli
        2. Run yarn setup-dev
      3. Rungit clone -b override git@github.com:fossamagna/amplify-category-console-notification.git
      4. Run cd amplify-category-console-notification
      5. Change version of amplify-cli-core in package.json to the path to local amplify-cli-core you checked out in the previous step.
      6. Run yarn build
      7. Run amplify-dev plugin add $(pwd)/amplify-category-console-notification
      8. Run amplify-dev plugin scan
    2. Run amplify-dev init. initialize sample project in order to test add command.
    3. Run amplify-dev add consolenotification

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@fossamagna fossamagna requested a review from a team as a code owner January 25, 2022 13:51
@codecov-commenter
Copy link

codecov-commenter commented Jan 26, 2022

Codecov Report

Merging #9601 (652e404) into master (896b518) will increase coverage by 0.10%.
The diff coverage is 37.93%.

@@            Coverage Diff             @@
##           master    #9601      +/-   ##
==========================================
+ Coverage   46.67%   46.78%   +0.10%     
==========================================
  Files         706      708       +2     
  Lines       35268    35273       +5     
  Branches     7148     7149       +1     
==========================================
+ Hits        16462    16502      +40     
+ Misses      17014    16981      -33     
+ Partials     1792     1790       -2     
Impacted Files Coverage Δ
...graphql-transformer/transform-graphql-schema-v2.ts 14.87% <ø> (ø)
...vider-utils/awscloudformation/apigw-input-state.ts 88.00% <0.00%> (ø)
...loudformation/utils/check-appsync-api-migration.ts 35.71% <0.00%> (ø)
...udformation/utils/attach-prev-params-to-context.ts 50.00% <0.00%> (ø)
...wscloudformation/utils/auth-sms-workflow-helper.ts 43.75% <0.00%> (ø)
...ation/service-walkthroughs/dynamoDB-input-state.ts 7.35% <0.00%> (ø)
...ls/awscloudformation/handlers/resource-handlers.ts 14.14% <5.12%> (-0.72%) ⬇️
...mation/service-walkthroughs/s3-user-input-state.ts 18.79% <13.04%> (ø)
...dformation/cdk-stack-builder/s3-stack-transform.ts 64.74% <16.66%> (ø)
packages/amplify-category-storage/src/index.ts 23.44% <25.00%> (ø)
... and 20 more

📣 Codecov can now indicate which changes are the most critical in Pull Requests. Learn more

@fossamagna
Copy link
Contributor Author

@akshbhu @ammarkarachi @jhockett @kaustavghosh06
Is this RP has blockers? Is there anything I can do to get my PR reviewed?
Thanks.

@jhockett
Copy link
Contributor

Hey @fossamagna, sorry for the delayed response.

One of our team's internal goals is to reduce the usage of the context object because it makes the code more susceptible to side effects. What is the use case for the changes made to auth, storage, and api?

Comment on lines +22 to +23
const pluginInfo = context.amplify.getCategoryPluginInfo(context, resource.category, resource.resourceName);
const { transformCategoryStack } = pluginInfo ? await import(pluginInfo.packageLocation) : { transformCategoryStack: null };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this PR was reduced to these lines here, I think that would achieve the majority of use cases for #9226. Thoughts @fossamagna?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @jhockett

If this PR was reduced to these lines here, I think that would achieve the majority of use cases for #9226.

Yes, I think so.

What is the use case for the changes made to auth, storage, and api?

I added context object to use CLIInputSchemaValidator on 3rd-party plugin at following.

https://github.com/aws-amplify/amplify-cli/pull/9601/files#diff-0261ff0abc6d6facc760fc5319008e2ebe0993de83bd0a2898a113c526a16372R149

fossamagna/amplify-category-console-notification@961262f#diff-be6013127ca9dce2788dc277cc0fefa77620c5aee6a7ec82fcb41462b415c6d4R42

I think that it will be resolved by implementing equivalent CLIInputSchemaValidator in 3rd-party plugin.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand now, thanks for the examples! I think we should include the plugin support for the schema generator too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhockett
I think that it is unnecessary modify to support for the schema generator, because generated schema path resolved by relative path. If I overlooking what should be support for the schema generator, I would like to seek your advice on this.

TYPES_SRC_ROOT = path.join('.', 'src', 'provider-utils', 'awscloudformation', 'service-walkthrough-types');
SCHEMA_FILES_ROOT = path.join('.', 'resources', 'schemas');

Copy link
Contributor

@jhockett jhockett Mar 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fossamagna The schema generator takes a category's TypeScript type for the input state and returns a JSON schema that the category's cli-inputs.json should conform to.

Example input state schema for REST APIs: https://github.com/aws-amplify/amplify-cli/blob/ae7b001f274f327a29c99c67fe851272c6208e84/packages/amplify-category-api/resources/schemas/aPIGateway/APIGatewayCLIInputs.schema.json

Where the schema validation logic is invoked:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jhockett I understand now, schema generator is pointing to CLIInputSchemaValidator class in category-base-schema-genereator.ts, not CLIInputSchemaGenerator class.
Then, I don't think I have any part of this PR that needs to be corrected.
What do you think on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @fossamagna, sorry for the delayed response. Thinking about it more, this approach LGTM 👍

packages/amplify-category-api/src/index.ts Outdated Show resolved Hide resolved
Comment on lines +22 to +23
const pluginInfo = context.amplify.getCategoryPluginInfo(context, resource.category, resource.resourceName);
const { transformCategoryStack } = pluginInfo ? await import(pluginInfo.packageLocation) : { transformCategoryStack: null };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @fossamagna, sorry for the delayed response. Thinking about it more, this approach LGTM 👍

Copy link
Contributor

@jhockett jhockett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM @fossamagna! I have one requested change above regarding a removed export and I'd also like to see a unit test for custom plugins to make sure we avoid regressions here.

Thank you for the contribution!

@fossamagna
Copy link
Contributor Author

fossamagna commented Mar 25, 2022

@jhockett Thank you for the review many times.
I revert removed export and add unit tests for transformResourceWithOverrides and CLIInputSchemaValidator.

@fossamagna
Copy link
Contributor Author

@jhockett Is this RP has blockers? Is there anything I can do?
Thanks.

@jhockett
Copy link
Contributor

jhockett commented May 13, 2022

Apologies for the delayed review @fossamagna, LGTM

Thank you for your contribution!

@ammarkarachi
Copy link
Contributor

ammarkarachi commented May 27, 2022

@fossamagna Thanks for the PR this is good work, A PR got merged would need rebasing

@fossamagna
Copy link
Contributor Author

@ammarkarachi Thank you for your review.
I resolved conflicts with git merge. Should I do git rebase?

@ammarkarachi
Copy link
Contributor

It's good we are going to squash the commits anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow third-party plugins to support CDK overrides
4 participants