-
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
fix(sqs): does not print all failed validations for Queue props #33070
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Construct } from 'constructs'; | ||
import { Queue, QueueProps, RedriveAllowPolicy, RedrivePermission } from './index'; | ||
import { Token } from '../../core'; | ||
import { validateAllProps, ValidationRule } from '../../core/lib/helpers-internal'; | ||
|
||
function validateRange(value: number | undefined, minValue: number, maxValue: number): boolean { | ||
return value !== undefined && !Token.isUnresolved(value) && (value < minValue || value > maxValue); | ||
} | ||
|
||
const queueValidationRules: ValidationRule<QueueProps>[] = [ | ||
{ | ||
condition: (props) => validateRange(props.deliveryDelay?.toSeconds(), 0, 900), | ||
message: (props) => `delivery delay must be between 0 and 900 seconds, but ${props.deliveryDelay?.toSeconds()} was provided`, | ||
}, | ||
{ | ||
condition: (props) => validateRange(props.maxMessageSizeBytes, 1_024, 262_144), | ||
message: (props) => `maximum message size must be between 1,024 and 262,144 bytes, but ${props.maxMessageSizeBytes} was provided`, | ||
}, | ||
{ | ||
condition: (props) => validateRange(props.retentionPeriod?.toSeconds(), 60, 1_209_600), | ||
message: (props) => `message retention period must be between 60 and 1,209,600 seconds, but ${props.retentionPeriod?.toSeconds()} was provided`, | ||
}, | ||
{ | ||
condition: (props) => validateRange(props.receiveMessageWaitTime?.toSeconds(), 0, 20), | ||
message: (props) => `receive wait time must be between 0 and 20 seconds, but ${props.receiveMessageWaitTime?.toSeconds()} was provided`, | ||
}, | ||
{ | ||
condition: (props) => validateRange(props.visibilityTimeout?.toSeconds(), 0, 43_200), | ||
message: (props) => `visibility timeout must be between 0 and 43,200 seconds, but ${props.visibilityTimeout?.toSeconds()} was provided`, | ||
}, | ||
{ | ||
condition: (props) => validateRange(props.deadLetterQueue?.maxReceiveCount, 1, Number.MAX_SAFE_INTEGER), | ||
message: (props) => `dead letter target maximum receive count must be 1 or more, but ${props.deadLetterQueue?.maxReceiveCount} was provided`, | ||
}, | ||
]; | ||
|
||
const redriveValidationRules: ValidationRule<RedriveAllowPolicy>[] = [ | ||
{ | ||
condition: ({ redrivePermission, sourceQueues }) => | ||
redrivePermission === RedrivePermission.BY_QUEUE && (!sourceQueues || sourceQueues.length === 0), | ||
message: () => 'At least one source queue must be specified when RedrivePermission is set to \'byQueue\'', | ||
}, | ||
{ | ||
condition: ({ redrivePermission, sourceQueues }) => | ||
!!(redrivePermission === RedrivePermission.BY_QUEUE && sourceQueues && sourceQueues.length > 10), | ||
message: () => 'Up to 10 sourceQueues can be specified. Set RedrivePermission to \'allowAll\' to specify more', | ||
}, | ||
{ | ||
condition: ({ redrivePermission, sourceQueues }) => | ||
!!((redrivePermission === RedrivePermission.ALLOW_ALL || redrivePermission === RedrivePermission.DENY_ALL) && sourceQueues), | ||
message: () => 'sourceQueues cannot be configured when RedrivePermission is set to \'allowAll\' or \'denyAll\'', | ||
}, | ||
]; | ||
|
||
export function validateQueueProps(scope: Construct, props: QueueProps) { | ||
validateAllProps(scope, Queue.name, props, queueValidationRules); | ||
} | ||
|
||
export function validateRedriveAllowPolicy(scope: Construct, policy: RedriveAllowPolicy) { | ||
validateAllProps(scope, Queue.name, policy, redriveValidationRules); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 logic for this used to essentially be:
redrivePermission && redrivePermission !== RedrivePermission.BY_QUEUE
. If any more options were added to theRedrivePermission
enum, the logic would have failed, since the permission might not be any of:byQueue
,allowAll
ordenyAll
. This adjusted logic protects against this possibility by being more specific.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 like this! It's more defensive towards the unknown. ❤️