-
Notifications
You must be signed in to change notification settings - Fork 4k
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(scheduler): validate schedule name length #31200
feat(scheduler): validate schedule name length #31200
Conversation
There was a problem hiding this 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.
Exemption Request: not really sure how to cover this with an integration test - I thought a unit test might suffice for something this small? |
There was a problem hiding this 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. I just made a few minor comments.
@@ -324,6 +324,9 @@ export class Schedule extends Resource implements ISchedule { | |||
const flexibleTimeWindow = props.timeWindow ?? TimeWindow.off(); | |||
|
|||
this.validateTimeFrame(props.start, props.end); | |||
if (props.scheduleName && !Token.isUnresolved(props.scheduleName) && props.scheduleName.length > 64) { | |||
throw new Error(`schedule name '${props.scheduleName}' exceeds 64 characters in length`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be user-friendly and good to display the length.
throw new Error(`schedule name '${props.scheduleName}' exceeds 64 characters in length`); | |
throw new Error(`scheduleName cannot be longer than 64 characters, got: ${props.scheduleName.length}`); |
@@ -214,5 +214,16 @@ describe('Schedule', () => { | |||
}); | |||
}).toThrow('The provided duration must be between 1 minute and 1440 minutes, got 0'); | |||
}); | |||
|
|||
test('throw error when schedule name exceeds 64', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test('throw error when schedule name exceeds 64', () => { | |
test('throw error when scheduleName exceeds 64 characters', () => { |
As this issue is not about a bug, the PR title may be good for |
Thanks for the review, I've updated the title and made the requested changes. |
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is technically a feat! validation is a feature of CDK so I think this counts. I also want this to show up in the changelog
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 CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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). |
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
N/A
Reason for this change
To catch name too long errors before hitting Cloudformation.
Description of changes
I've added a length assertion in the
Schedule
constructor against the schedule name length, the documentation on schedule name already makes it clear that there is a limit though AFAICS this isn't validated.Also see the Cloudformation doc here: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-scheduler-schedule.html#cfn-scheduler-schedule-name.
Description of how you validated changes
I've added a unit test.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license