Skip to content

Commit

Permalink
Make compliance_include a public function
Browse files Browse the repository at this point in the history
  • Loading branch information
johanek committed Jul 19, 2023
1 parent 0c37391 commit 24e30f4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.DEFAULT_GOAL := help

format: ## Run python formatter
find . -type f -name '*.py' | grep -v .eggs | xargs pipenv run yapf -i
find . -type f -name '*.py' | grep -v .eggs | xargs yapf -i

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

setup(
name="sohonet-nsot-helpers",
version="0.1.3",
version="0.1.4",
packages=find_packages(),
author="Johan van den Dorpe",
author_email="[email protected]",
Expand Down
11 changes: 6 additions & 5 deletions sohonet_nsot_helpers/nautobot.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import re
from nautobot_golden_config.models import FUNC_MAPPER

def _compliance_include(obj):

def compliance_include(compliance_include, actual_config):
included_lines = []
matchers = [re.compile(pattern) for pattern in obj.rule.custom_field_data.get("compliance_include")]
for line in obj.actual.splitlines():
matchers = [re.compile(pattern) for pattern in compliance_include]
for line in actual_config.splitlines():
if any(matcher.search(line) for matcher in matchers):
included_lines.append(line)

Expand All @@ -27,10 +28,10 @@ def sohonet_custom_compliance(obj):
# Filter included lines only from actual config
compliance_include = obj.rule.custom_field_data.get("compliance_include")
if compliance_include and isinstance(compliance_include, list):
included_lines = _compliance_include(obj)
included_lines = compliance_include(obj.rule.custom_field_data.get("compliance_include"), obj.actual)
obj.actual = '\n'.join(included_lines)

# Run compliance method with filtered actual configuration
compliance_method = FUNC_MAPPER['cli']
compliance_details = compliance_method(obj)
return compliance_details
return compliance_details

0 comments on commit 24e30f4

Please sign in to comment.