Handle exceptions gracefully
This commit is contained in:
parent
fb94b40c23
commit
f7923b4890
13
models.py
13
models.py
@ -15,4 +15,15 @@ class RuleChecker:
|
|||||||
|
|
||||||
def check_rule(self, rule_name) -> RuleCheckResult:
|
def check_rule(self, rule_name) -> RuleCheckResult:
|
||||||
check_func = getattr(self, convert_snake_case(rule_name))
|
check_func = getattr(self, convert_snake_case(rule_name))
|
||||||
return check_func()
|
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
|
||||||
|
@ -9,7 +9,7 @@ class CloudFrontRuleChecker(RuleChecker):
|
|||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def distributions(self):
|
def distributions(self):
|
||||||
return self.client.list_distributions()["DistributionList"]["Items"]
|
return self.client.list_distributions()["DistributionList"].get("Items", [])
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def distribution_details(self):
|
def distribution_details(self):
|
||||||
|
@ -11,6 +11,8 @@ class CodeSeriesChecker(RuleChecker):
|
|||||||
@cached_property
|
@cached_property
|
||||||
def projects(self):
|
def projects(self):
|
||||||
project_names = self.build_client.list_projects()["projects"]
|
project_names = self.build_client.list_projects()["projects"]
|
||||||
|
if not project_names:
|
||||||
|
return []
|
||||||
return self.build_client.batch_get_projects(names=project_names)["projects"]
|
return self.build_client.batch_get_projects(names=project_names)["projects"]
|
||||||
|
|
||||||
def codebuild_project_environment_privileged_check(self):
|
def codebuild_project_environment_privileged_check(self):
|
||||||
@ -59,6 +61,10 @@ class CodeSeriesChecker(RuleChecker):
|
|||||||
deployment_group_names = self.deploy_client.list_deployment_groups(
|
deployment_group_names = self.deploy_client.list_deployment_groups(
|
||||||
applicationName=application
|
applicationName=application
|
||||||
)["deploymentGroups"]
|
)["deploymentGroups"]
|
||||||
|
|
||||||
|
if not deployment_group_names:
|
||||||
|
continue
|
||||||
|
|
||||||
deployment_groups = self.deploy_client.batch_get_deployment_groups(
|
deployment_groups = self.deploy_client.batch_get_deployment_groups(
|
||||||
applicationName=application, deploymentGroupNames=deployment_group_names
|
applicationName=application, deploymentGroupNames=deployment_group_names
|
||||||
)["deploymentGroupsInfo"]
|
)["deploymentGroupsInfo"]
|
||||||
|
Loading…
Reference in New Issue
Block a user