Example #1
0
    def _parse_raw_check(
            self, raw_check: Dict[str, Any],
            resources_types: Optional[List[str]]) -> BaseGraphCheck:
        check = BaseGraphCheck()
        complex_operator = get_complex_operator(raw_check)
        if complex_operator:
            check.type = SolverType.COMPLEX
            check.operator = complex_operator
            sub_solvers = raw_check.get(complex_operator, [])
            for sub_solver in sub_solvers:
                check.sub_checks.append(
                    self._parse_raw_check(sub_solver, resources_types))
            resources_types_of_sub_solvers = [
                q.resource_types for q in check.sub_checks
                if q is not None and q.resource_types is not None
            ]
            check.resource_types = list(
                set(sum(resources_types_of_sub_solvers, [])))
            if any(q.type in
                   [SolverType.CONNECTION, SolverType.COMPLEX_CONNECTION]
                   for q in check.sub_checks):
                check.type = SolverType.COMPLEX_CONNECTION

        else:
            resource_type = raw_check.get("resource_types", [])
            if (not resource_type or (isinstance(resource_type, str)
                                      and resource_type.lower() == "all")
                    or (isinstance(resource_type, list)
                        and resource_type[0].lower() == "all")):
                check.resource_types = resources_types
            else:
                check.resource_types = resource_type

            connected_resources_type = raw_check.get(
                "connected_resource_types", [])
            if connected_resources_type == [
                    "All"
            ] or connected_resources_type == "all":
                check.connected_resources_types = resources_types
            else:
                check.connected_resources_types = connected_resources_type

            condition_type = raw_check.get("cond_type", "")
            check.type = condition_type_to_solver_type.get(condition_type)
            if condition_type == "":
                check.operator = "any"
            else:
                check.operator = raw_check.get("operator")
            check.attribute = raw_check.get("attribute")
            check.attribute_value = raw_check.get("value")

        return check
Example #2
0
    def _parse_raw_check(self, raw_check, resources_types):
        check = BaseGraphCheck()
        complex_operator = get_complex_operator(raw_check)
        if complex_operator:
            check.type = SolverType.COMPLEX
            check.operator = complex_operator
            sub_solvers = raw_check.get(complex_operator)
            for sub_solver in sub_solvers:
                check.sub_checks.append(
                    self._parse_raw_check(sub_solver, resources_types))
            resources_types_of_sub_solvers = [
                q.resource_types for q in check.sub_checks
                if q is not None and q.resource_types is not None
            ]
            check.resource_types = list(
                set(sum(resources_types_of_sub_solvers, [])))
            if any(q.type in
                   [SolverType.CONNECTION, SolverType.COMPLEX_CONNECTION]
                   for q in check.sub_checks):
                check.type = SolverType.COMPLEX_CONNECTION

        else:
            resource_type = raw_check.get("resource_types", [])
            if resource_type == [
                    'All'
            ] or resource_type == 'all' or not resource_type:
                check.resource_types = resources_types
            else:
                check.resource_types = resource_type

            connected_resources_type = raw_check.get(
                'connected_resource_types', [])
            if connected_resources_type == [
                    'All'
            ] or connected_resources_type == 'all':
                check.connected_resources_types = resources_types
            else:
                check.connected_resources_types = connected_resources_type

            condition_type = raw_check.get('cond_type', '')
            check.type = condition_type_to_solver_type.get(condition_type)
            if condition_type == '':
                check.operator = 'any'
            else:
                check.operator = raw_check.get('operator')
            check.attribute = raw_check.get('attribute')
            check.attribute_value = raw_check.get('value')

        return check