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(appsync): strongly type expires prop in apiKeyConfig #9122

Merged
merged 43 commits into from
Sep 9, 2020

Conversation

BryanPan342
Copy link
Contributor

@BryanPan342 BryanPan342 commented Jul 16, 2020

[ISSUE]
apiKeyConfig has prop expires that has unclear documentation/not strongly typed and is prone to user errors.

[APPROACH]
Force expires to take Expiration class from core and will be able to output api key configurations easily through Expiration static functions: after(...), fromString(...), atDate(...), atTimeStamp(...).

Fixes #8698

BREAKING CHANGE: force apiKeyConfig require a Expiration class instead of string

  • appsync: Parameter apiKeyConfig takes Expiration class instead of string

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

@BryanPan342 BryanPan342 self-assigned this Jul 16, 2020
@BryanPan342 BryanPan342 added @aws-cdk/aws-appsync Related to AWS AppSync @aws-cdk/aws-s3-deployment @aws-cdk/core Related to core CDK functionality labels Jul 16, 2020
@mergify
Copy link
Contributor

mergify bot commented Jul 16, 2020

Title does not follow the guidelines of Conventional Commits. Please adjust title before merge.

@BryanPan342 BryanPan342 added the pr/breaking-change This PR is a breaking change. It needs to be modified to be allowed in the current major version. label Jul 16, 2020
Copy link
Contributor

@iliapolo iliapolo left a comment

Choose a reason for hiding this comment

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

@eladb @MrArnoldPalmer This mainly involves your are ownerships, have a look as well?

packages/@aws-cdk/core/lib/expires.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/core/lib/expires.ts Outdated Show resolved Hide resolved
@iliapolo
Copy link
Contributor

@BryanPan342 Note that breaking changes should be specified with a BREAKING CHANGE prefix in the PR body. Like so: #9016

@BryanPan342 BryanPan342 requested a review from eladb July 22, 2020 20:19
eladb
eladb previously requested changes Jul 26, 2020
packages/@aws-cdk/core/lib/expires.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-appsync/lib/graphqlapi.ts Outdated Show resolved Hide resolved
}

type Query {
getTests: [ test! ]
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this related to this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just for the integrity test to see if the API Key works for query/mutation

typeName: 'Query',
fieldName: 'getTests',
requestMappingTemplate: MappingTemplate.dynamoDbScanTable(),
responseMappingTemplate: MappingTemplate.dynamoDbResultList(),
Copy link
Contributor

Choose a reason for hiding this comment

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

How is this related to this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same as the comment above

just for the integrity test to see if the API Key works for query/mutation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@eladb o i see.. i just need to check if the apikey exist is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think its important to test the connection else i can just remove the integ test all together

@BryanPan342
Copy link
Contributor Author

@iliapolo

I was suggested to move the equivalent of asEpoch() into core by @eladb and I'm more inclined to go with that because of the suggestion to implement an expires?.lessThan(...) into the Expiration class.

If we add those functions to Expiration I dont see why we can't do the same for asEpoch:

const getEpoch = (d: Expires) => { return Math.floor( d.date.getTime() / 86400000) * 86400; };

wdyt?

@mergify mergify bot dismissed eladb’s stale review July 28, 2020 19:33

Pull request has been modified.

@BryanPan342 BryanPan342 requested a review from eladb July 28, 2020 19:45
eladb
eladb previously requested changes Sep 2, 2020
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

Still feels like this PR includes two different changes: one is the introduction of the Expiration class in core and using it in various places and the second is the change to the appsync library and the apikey tests.

packages/@aws-cdk/core/lib/expiration.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/core/lib/expiration.ts Outdated Show resolved Hide resolved
/**
* Expiration value as a string
*/
public readonly value: string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed? Seems like this the UTC representation of the date, which can be obtained from x.date.toUTCString(), no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

s3-deployments uses the value property, I added the date property myself, but I wouldn't mind just removing the date property entirely.

*
* @param s the string that represents date to expire at
*/
public static fromString(s: string) { return new Expiration(s, new Date(s)); }
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed? Expiration.atDate(new Date(s)) is short enough, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It existed in the s3-deployment version and I don't have the domain knowledge to know if this is something that should keep maybe @iliapolo knows more about this

Copy link
Contributor

Choose a reason for hiding this comment

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

From a user's mental model, I think .date makes much more sense then .value. We can change s3-deployment to use .date.toUTCString() or whatever it needs.

@BryanPan342
Copy link
Contributor Author

BryanPan342 commented Sep 2, 2020

Still feels like this PR includes two different changes: one is the introduction of the Expiration class in core and using it in various places and the second is the change to the appsync library and the apikey tests.

@eladb would it be better if I separated this PR?

@eladb
Copy link
Contributor

eladb commented Sep 2, 2020

Still feels like this PR includes two different changes: one is the introduction of the Expiration class in core and using it in various places and the second is the change to the appsync library and the apikey tests.

@eladb would it be better if I separated this PR?

Yes, I think it makes sense to separate.

@BryanPan342
Copy link
Contributor Author

@iliapolo @eladb separated to #10192

@BryanPan342 BryanPan342 dismissed eladb’s stale review September 5, 2020 00:00

moved core and s3 changes to #10192

@BryanPan342 BryanPan342 removed @aws-cdk/aws-s3-deployment @aws-cdk/core Related to core CDK functionality labels Sep 5, 2020
mergify bot pushed a commit that referenced this pull request Sep 8, 2020
Move `Expires` class from s3-deployments to core. Rename to `Expiration`

**BREAKING CHANGE**: s3-deployments property `expires` takes `cdk.Expiration` instead of  `Expires`
- **s3-deployments**: `BucketDeploymentProps.expires` now takes in type `cdk.Expiration`

**Note**: PR separated from #9122

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@BryanPan342
Copy link
Contributor Author

@MrArnoldPalmer @shivlaks got #10192 approved! Would love it you guys could take a pass at this today. I dont think there is anything too controversial here. Maybe the integ test is unnecessary?

@BryanPan342 BryanPan342 removed the pr/do-not-merge This PR should not be merged at this time. label Sep 9, 2020
@mergify
Copy link
Contributor

mergify bot commented Sep 9, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 7af4dab
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Sep 9, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 287f808 into aws:master Sep 9, 2020
vrr-21 added a commit to vrr-21/aws-cdk that referenced this pull request Sep 9, 2020
fix(appsync): strongly type `expires` prop in apiKeyConfig (aws#9122)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-appsync Related to AWS AppSync contribution/core This is a PR that came from AWS. pr/breaking-change This PR is a breaking change. It needs to be modified to be allowed in the current major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

appsync - apiKeyConfig expires outputting incorrect format
5 participants