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

Prevent conflicts in references #11555

Merged
merged 1 commit into from
Feb 7, 2024
Merged
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
11 changes: 11 additions & 0 deletions ssg/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,16 @@ def get_level_with_ancestors_sequence(self, level_id):
levels[l] = ""
return list(levels.keys())

def _check_conflict_in_rules(self, rules):
for rule_id, rule in rules.items():
if self.reference_type in rule.references:
msg = (
"Rule %s contains %s reference, but this reference "
"type is provided by %s controls. Please remove the "
"reference from rule.yml." % (
rule_id, self.reference_type, self.id))
raise ValueError(msg)

def add_references(self, rules):
if not self.reference_type:
return
Expand All @@ -398,6 +408,7 @@ def add_references(self, rules):
if self.reference_type not in allowed_reference_types:
msg = "Unknown reference type %s" % (self.reference_type)
raise(ValueError(msg))
self._check_conflict_in_rules(rules)
for control in self.controls_by_id.values():
control.add_references(self.reference_type, rules)

Expand Down
Loading