Skip to content

Commit

Permalink
Validate either Day-of-month or Day-of-week have a question mark (#1405)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Mar 9, 2020
1 parent c9d78f4 commit ec366bb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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)

0 comments on commit ec366bb

Please sign in to comment.