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

feat: inject project info into overrides #12064

Merged
merged 9 commits into from
Feb 22, 2023

Conversation

sobolk
Copy link
Member

@sobolk sobolk commented Feb 21, 2023

Description of changes

This PR injects AmplifyProjectInfo into override functions as second parameter.

Issue #, if available

Description of how you validated changes

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)
  • New AWS SDK calls or CloudFormation actions have been added to relevant test and service IAM policies
  • Pull request labels are added

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

@sobolk sobolk requested a review from a team as a code owner February 21, 2023 20:41
import { AmplifyAuthCognitoStackTemplate } from '@aws-amplify/cli-extensibility-helper';
import { AmplifyAuthCognitoStackTemplate, AmplifyProjectInfo } from '@aws-amplify/cli-extensibility-helper';

export function override(resources: AmplifyAuthCognitoStackTemplate, projectInfo: AmplifyProjectInfo) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the variable name should be called amplifyProjectInfo even with the type specifying it's Amplify since this var name gets used in the customer code.

Comment on lines 10 to 13

if (!projectInfo || !projectInfo.envName || !projectInfo.projectName) {
throw new Error('Project info is missing in override');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a test that actually uses the projectInfo?

@@ -123,10 +124,11 @@ export class AmplifyAuthTransform extends AmplifyCategoryTransform {
external: true,
},
});
const projectInfo = getProjectInfo();
Copy link
Contributor

Choose a reason for hiding this comment

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

Does getProjectInfo return a clone / readonly version of the object?

Copy link
Member Author

Choose a reason for hiding this comment

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

it returns reference to fresh object with two strings, see

const projectInfo: AmplifyProjectInfo = {
envName: localEnvInfo.envName,
projectName: projectConfig.projectName,
};
return projectInfo;
.

I think I can make AmplifyProjectInfo readonly to make it better.

@codecov-commenter
Copy link

Codecov Report

Merging #12064 (cfefa1c) into cdkv2 (379e360) will decrease coverage by 3.56%.
The diff coverage is 52.41%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##            cdkv2   #12064      +/-   ##
==========================================
- Coverage   50.18%   46.62%   -3.56%     
==========================================
  Files         702      826     +124     
  Lines       33976    37986    +4010     
  Branches     6976     7752     +776     
==========================================
+ Hits        17050    17712     +662     
- Misses      15447    18607    +3160     
- Partials     1479     1667     +188     
Impacted Files Coverage Δ
...sync-simulator/src/data-loader/opensearch/index.ts 45.45% <0.00%> (ø)
...s/amplify-appsync-simulator/src/type-definition.ts 100.00% <ø> (ø)
...sync-simulator/src/velocity/util/dynamodb-utils.ts 6.55% <0.00%> (ø)
...y-appsync-simulator/src/velocity/util/map-utils.ts 10.00% <ø> (ø)
...tor/src/velocity/util/transform/dynamodb-filter.ts 4.93% <0.00%> (ø)
...ync-simulator/src/velocity/util/transform/index.ts 21.05% <0.00%> (ø)
...appsync-simulator/src/velocity/value-mapper/map.ts 86.88% <ø> (ø)
...ackages/amplify-category-auth/src/commands/auth.ts 0.00% <0.00%> (ø)
...es/amplify-category-auth/src/commands/auth/help.ts 0.00% <0.00%> (ø)
.../amplify-category-auth/src/commands/auth/import.ts 0.00% <0.00%> (ø)
... and 523 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

export const replaceOverrideFileWitProjectInfo = (srcPath: string, destPath: string, envName: string, projectName: string) => {
const content = fs.readFileSync(srcPath).toString();
const contentWithProjectInfo = content.replace('##EXPECTED_ENV_NAME', envName).replace('##EXPECTED_PROJECT_NAME', projectName);
fs.writeFileSync(destPath, contentWithProjectInfo);

Check failure

Code scanning / CodeQL

Insecure temporary file

Insecure creation of file in [the os temp dir](1).
Copy link
Member Author

Choose a reason for hiding this comment

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

Dismissed as occurring in tests.

edwardfoyle
edwardfoyle previously approved these changes Feb 21, 2023
jhockett
jhockett previously approved these changes Feb 21, 2023
@sobolk sobolk dismissed stale reviews from jhockett and edwardfoyle via 79499c3 February 22, 2023 00:38
edwardfoyle
edwardfoyle previously approved these changes Feb 22, 2023
jhockett
jhockett previously approved these changes Feb 22, 2023
packages/amplify-e2e-core/src/utils/overrides.ts Outdated Show resolved Hide resolved
@sobolk sobolk dismissed stale reviews from jhockett and edwardfoyle via 2c7937d February 22, 2023 01:14
@sobolk sobolk merged commit 9ceaefa into aws-amplify:cdkv2 Feb 22, 2023
@sobolk sobolk deleted the project-info-in-overrides-cdkv2 branch February 22, 2023 13:17
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.

5 participants