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(s3): fail fast for s3 lifecycle configuration when ExpiredObjectDeleteMarker specified with ExpirationInDays, ExpirationDate, or TagFilters. #25841

Merged
merged 3 commits into from
Jun 14, 2023

Conversation

Zishanwang1992
Copy link
Contributor

@Zishanwang1992 Zishanwang1992 commented Jun 3, 2023

Closes #25824.


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

@gitpod-io
Copy link

gitpod-io bot commented Jun 3, 2023

@github-actions github-actions bot added bug This issue is a bug. effort/small Small work item – less than a day of effort p2 repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK labels Jun 3, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team June 3, 2023 00:18
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

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

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@Zishanwang1992
Copy link
Contributor Author

Exemption Request: This fix is to fail fast. The integ test has no difference compared to unit test. The unit test has been added for the scenario.

@aws-cdk-automation aws-cdk-automation added pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Jun 3, 2023
@abelmokadem
Copy link
Contributor

Just a random thought. Why not fix this in the type definition of Lifecycle Rule?

Copy link
Contributor

@corymhall corymhall left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Just 2 minor comments

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add tests for all the combinations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will add different combinations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@corymhall Could you help review this PR?

Comment on lines 2088 to 2092
if ((rule.expiredObjectDeleteMarker != null && rule.expiredObjectDeleteMarker != undefined)
&& (rule.expiration || rule.expirationDate || self.parseTagFilters(rule.tagFilters))) {
// ExpiredObjectDeleteMarker cannot be specified with ExpirationInDays, ExpirationDate, or TagFilters.
throw new Error('ExpiredObjectDeleteMarker cannot be specified with expiration, ExpirationDate, or TagFilters.');
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if ((rule.expiredObjectDeleteMarker != null && rule.expiredObjectDeleteMarker != undefined)
&& (rule.expiration || rule.expirationDate || self.parseTagFilters(rule.tagFilters))) {
// ExpiredObjectDeleteMarker cannot be specified with ExpirationInDays, ExpirationDate, or TagFilters.
throw new Error('ExpiredObjectDeleteMarker cannot be specified with expiration, ExpirationDate, or TagFilters.');
}
if ((rule.expiredObjectDeleteMarker)
&& (rule.expiration || rule.expirationDate || this.parseTagFilters(rule.tagFilters))) {
// ExpiredObjectDeleteMarker cannot be specified with ExpirationInDays, ExpirationDate, or TagFilters.
throw new Error('ExpiredObjectDeleteMarker cannot be specified with expiration, ExpirationDate, or TagFilters.');
}

Copy link
Contributor Author

@Zishanwang1992 Zishanwang1992 Jun 13, 2023

Choose a reason for hiding this comment

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

The reason I do not use the "if ((rule.expiredObjectDeleteMarker))" is the type of "expiredObjectDeleteMarker" is boolean. If its value is false, the validation here will pass without error(not work). I assume "false" could also not be specified with ExpirationInDays, ExpirationDate, or TagFilter according to public doc.

See if it makes sense.

Copy link
Contributor Author

@Zishanwang1992 Zishanwang1992 Jun 13, 2023

Choose a reason for hiding this comment

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

Btw, the "this.parseTagFilters(rule.tagFilters)" will not compile, and there is same "self.parseTagFilters(rule.tagFilters)" usage at line 2112/2117. My change is to stay consistent with existing code.

See if it makes sense.

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 have update the code for "if ((rule.expiredObjectDeleteMarker))" as suggested. Based on local integration test, the "false" of expiredObjectDeleteMarker can be specified together with ExpirationInDays, ExpirationDate, or TagFilter.

@corymhall corymhall self-assigned this Jun 13, 2023
@corymhall corymhall added pr-linter/exempt-integ-test The PR linter will not require integ test changes and removed pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. labels Jun 13, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review June 13, 2023 10:29

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

…eleteMarker specified with ExpirationInDays, ExpirationDate, or TagFilters.
@mergify mergify bot dismissed corymhall’s stale review June 13, 2023 17:31

Pull request has been modified.

@Zishanwang1992
Copy link
Contributor Author

Zishanwang1992 commented Jun 13, 2023

Just a random thought. Why not fix this in the type definition of Lifecycle Rule?

I am not sure if we can do this in the type definition of Lifecycle Rule, because there is complex validaiton logic. We can easily do this when Lifecycle rule gets initialized and the current code shall be the only place to initialize the Lifecycle rule.

See if it makes sense to you.

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 13, 2023
packages/aws-cdk-lib/aws-s3/test/rules.test.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-s3/test/rules.test.ts Outdated Show resolved Hide resolved
packages/aws-cdk-lib/aws-s3/test/rules.test.ts Outdated Show resolved Hide resolved
@mergify
Copy link
Contributor

mergify bot commented Jun 14, 2023

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

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jun 14, 2023
@mergify
Copy link
Contributor

mergify bot commented Jun 14, 2023

Thank you for contributing! Your pull request will be updated from main 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: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: e565f68
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

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

@mergify mergify bot merged commit 1a82d85 into aws:main Jun 14, 2023
@mergify
Copy link
Contributor

mergify bot commented Jun 14, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. effort/small Small work item – less than a day of effort p2 pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exemption-requested The contributor has requested an exemption to the PR Linter feedback. repeat-contributor [Pilot] contributed between 3-5 PRs to the CDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aws-cdk/aws-s3: cdk can generate an invalid lifecycle configuration for s3:Bucket
4 participants