2024-08-05 02:30:34 +00:00
|
|
|
from pydantic import BaseModel
|
2024-08-14 01:05:06 +00:00
|
|
|
from utils import convert_snake_case
|
2024-08-12 08:38:43 +00:00
|
|
|
from typing import List
|
2024-08-05 02:30:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RuleCheckResult(BaseModel):
|
|
|
|
passed: bool
|
2024-08-12 08:38:43 +00:00
|
|
|
compliant_resources: List[str]
|
|
|
|
non_compliant_resources: List[str]
|
2024-08-14 01:05:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
class RuleChecker:
|
|
|
|
def __init__(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def check_rule(self, rule_name) -> RuleCheckResult:
|
|
|
|
check_func = getattr(self, convert_snake_case(rule_name))
|
2024-08-14 04:21:46 +00:00
|
|
|
try:
|
|
|
|
result = check_func()
|
|
|
|
except Exception as e:
|
|
|
|
result = RuleCheckResult(
|
|
|
|
passed=False,
|
|
|
|
compliant_resources=[],
|
|
|
|
non_compliant_resources=[
|
|
|
|
"Rule check failed due to folling errors: ",
|
|
|
|
str(e),
|
|
|
|
],
|
|
|
|
)
|
|
|
|
return result
|