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

Validate either Day-of-month or Day-of-week have a question mark #1405

Merged
merged 3 commits into from
Mar 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/cfnlint/rules/resources/events/RuleScheduleExpression.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ def check_rate(self, value, path):
# Check the Value
if not items[0].isdigit():
message = 'Rate Value ({}) should be of type Integer.'
extra_args = {'actual_type': type(items[0]).__name__, 'expected_type': int.__name__}
extra_args = {'actual_type': type(
items[0]).__name__, 'expected_type': int.__name__}
matches.append(RuleMatch(path, message.format(items[0]), **extra_args))

return matches
Expand All @@ -57,6 +58,12 @@ def check_cron(self, value, path):
if len(items) != 6:
message = 'Cron expression must contain 6 elements (Minutes Hours Day-of-month Month Day-of-week Year), cron contains {} elements'
matches.append(RuleMatch(path, message.format(len(items))))
return matches

_, _, day_of_month, _, day_of_week, _ = cron_expression.split(' ')
if day_of_month != '?' and day_of_week != '?':
matches.append(RuleMatch(
path, 'Don\'t specify the Day-of-month and Day-of-week fields in the same cron expression'))

return matches

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ Resources:
Type: AWS::Events::Rule
Properties:
ScheduleExpression: "cron(0 */1 * * WED)" # Not enough values
MyScheduledRule8:
Type: AWS::Events::Rule
Properties:
ScheduleExpression: "cron(* 1 * * * *)" # specify the Day-of-month and Day-of-week fields in the same cron expression
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ def test_file_positive(self):
def test_file_negative_alias(self):
"""Test failure"""
self.helper_file_negative(
'test/fixtures/templates/bad/resources/events/rule_schedule_expression.yaml', 7)
'test/fixtures/templates/bad/resources/events/rule_schedule_expression.yaml', 8)