in src/services/rule_meta_service.py [0:0]
def filter_by(rules: Iterable[Rule],
customer: Optional[FilterValue] = None,
cloud: Optional[FilterValue] = None,
name_prefix: Optional[FilterValue] = None,
version: Optional[FilterValue] = None,
git_project: Optional[FilterValue] = None,
ref: Optional[FilterValue] = None,
rule_source_id: Optional[FilterValue] = None,
resource: Optional[FilterValue] = None
) -> Iterator[Rule]:
"""
God-like filter. Filter just using python. No queries
"""
if isinstance(customer, str):
customer = (customer, )
if isinstance(cloud, str):
cloud = (cloud, )
if isinstance(name_prefix, str):
name_prefix = (name_prefix, )
if isinstance(version, str):
name_prefix = (version, )
if isinstance(git_project, str):
git_project = (git_project, )
if isinstance(ref, str):
ref = (ref, )
if isinstance(resource, str):
resource = (resource, )
if isinstance(rule_source_id, str):
rule_source_id = (rule_source_id, )
def _check(rule: Rule) -> bool:
if customer and rule.customer not in customer:
return False
if cloud and rule.cloud not in map(adjust_cloud, cloud):
return False
if name_prefix and not any(
map(lambda n: rule.name.startswith(n), name_prefix)):
return False
if git_project and rule.git_project not in git_project:
return False
if ref and rule.ref not in ref:
return False
if rule_source_id and rule.rule_source_id not in rule_source_id:
return False
if resource and rule.resource not in resource:
return False
return True
return filter(_check, rules)