Skip to content

Commit

Permalink
add regex reason as attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Max-Huneshagen committed Nov 10, 2023
1 parent 1cff278 commit db43dc7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 3 additions & 4 deletions cfripper/rules/stack_name_matches_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ class StackNameMatchesRegexRule(Rule):
RULE_MODE = RuleMode.DEBUG # for demonstration purposes
RISK_VALUE = RuleRisk.LOW
GRANULARITY = RuleGranularity.STACK
REASON = (
"The stack name {} does not follow the naming convention (only alphanumerical characters and hyphens allowed)."
)
REASON = "The stack name {} does not follow the naming convention, reason: {}"
REGEX = REGEX_ALPHANUMERICAL_OR_HYPHEN
REGEX_REASON = "Only alphanumerical characters and hyphens allowed."

def _stack_name_matches_regex(self, stack_name: str) -> bool:
"""Check that stack name follows naming convention."""
Expand All @@ -38,7 +37,7 @@ def invoke(self, cfmodel: CFModel, extras: Optional[Dict] = None) -> Result:
if not self._stack_name_matches_regex(stack_name):
self.add_failure_to_result(
result,
self.REASON.format(stack_name),
self.REASON.format(stack_name, self.REGEX_REASON),
self.GRANULARITY,
risk_value=self.RISK_VALUE,
context={"config": self._config, "extras": extras},
Expand Down
8 changes: 4 additions & 4 deletions tests/rules/test_StackNameMatchesRegexRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ def test_failure_is_added_for_invalid_stack_name():
assert result.failures
assert (
result.failures[0].reason
== "The stack name some_invalid_stack_name does not follow the naming convention (only alphanumerical "
"characters and hyphens allowed)."
== "The stack name some_invalid_stack_name does not follow the naming convention, reason: Only alphanumerical "
"characters and hyphens allowed."
)


Expand All @@ -55,6 +55,6 @@ def test_failure_is_added_for_invalid_stack_name_from_extras():
assert result.failures
assert (
result.failures[0].reason
== "The stack name some_invalid_stack_name does not follow the naming convention (only alphanumerical "
"characters and hyphens allowed)."
== "The stack name some_invalid_stack_name does not follow the naming convention, reason: Only alphanumerical "
"characters and hyphens allowed."
)

0 comments on commit db43dc7

Please sign in to comment.