def run(self, root_folder: Optional[str]=None, external_checks_dir: Optional[List[str]]=None, files: Optional[List[str]]=None, runner_filter: RunnerFilter=RunnerFilter(), collect_skip_comments: bool=True) -> Report:
    report = Report(self.check_type)
    self.tf_definitions = {}
    parsing_errors = {}
    if external_checks_dir:
        for directory in external_checks_dir:
            resource_registry.load_external_checks(directory)
            self.graph_registry.load_external_checks(directory)
    if root_folder:
        files = ([] if (not files) else files)
        for (root, d_names, f_names) in os.walk(root_folder):
            filter_ignored_paths(root, d_names, runner_filter.excluded_paths)
            filter_ignored_paths(root, f_names, runner_filter.excluded_paths)
            for file in f_names:
                file_ending = os.path.splitext(file)[1]
                if (file_ending == '.json'):
                    try:
                        with open(f'{root}/{file}') as f:
                            content = json.load(f)
                        if (isinstance(content, dict) and content.get('terraform_version')):
                            files.append(os.path.join(root, file))
                    except Exception as e:
                        logging.debug(f'Failed to load json file {root}/{file}, skipping')
                        logging.debug('Failure message:')
                        logging.debug(e, stack_info=True)
    if files:
        files = [os.path.abspath(file) for file in files]
        for file in files:
            if file.endswith('.json'):
                (tf_definitions, template_lines) = parse_tf_plan(file)
                if (not tf_definitions):
                    continue
                self.tf_definitions = tf_definitions
                self.template_lines = template_lines
                self.check_tf_definition(report, runner_filter)
            else:
                logging.debug(f'Failed to load {file} as is not a .json file, skipping')
    report.add_parsing_errors(parsing_errors.keys())
    if self.tf_definitions:
        graph = self.graph_manager.build_graph_from_definitions(self.tf_definitions, render_variables=False)
        self.graph_manager.save_graph(graph)
        graph_report = self.get_graph_checks_report(root_folder, runner_filter)
        merge_reports(report, graph_report)
    return report
def run(self, root_folder: Optional[str]=None, external_checks_dir: Optional[List[str]]=None, files: Optional[List[str]]=None, runner_filter: RunnerFilter=RunnerFilter(), collect_skip_comments: bool=True) -> Report:
    report = Report(self.check_type)
    self.tf_definitions = {}
    parsing_errors = {}
    if external_checks_dir:
        for directory in external_checks_dir:
            resource_registry.load_external_checks(directory)
            self.graph_registry.load_external_checks(directory)
    if root_folder:
        files = ([] if (not files) else files)
        for (root, d_names, f_names) in os.walk(root_folder):
            filter_ignored_paths(root, d_names, runner_filter.excluded_paths)
            filter_ignored_paths(root, f_names, runner_filter.excluded_paths)
            for file in f_names:
                file_ending = os.path.splitext(file)[1]
                if (file_ending == '.json'):
                    try:
                        with open(f'{root}/{file}') as f:
                            content = json.load(f)
                        if (isinstance(content, dict) and content.get('terraform_version')):
                            files.append(os.path.join(root, file))
                    except Exception as e:
                        logging.debug(f'Failed to load json file {root}/{file}, skipping')
                        logging.debug('Failure message:')
                        logging.debug(e, stack_info=True)
    if files:
        files = [os.path.abspath(file) for file in files]
        for file in files:
            if file.endswith('.json'):
                (tf_definitions, template_lines) = parse_tf_plan(file)
                if (not tf_definitions):
                    continue
                self.tf_definitions = tf_definitions
                self.template_lines = template_lines
                self.check_tf_definition(report, runner_filter)
            else:
                logging.debug(f'Failed to load {file} as is not a .json file, skipping')
    report.add_parsing_errors(parsing_errors.keys())
    if self.tf_definitions:
        graph = self.graph_manager.build_graph_from_definitions(self.tf_definitions, render_variables=False)
        self.graph_manager.save_graph(graph)
        graph_report = self.get_graph_checks_report(root_folder, runner_filter)
        merge_reports(report, graph_report)
    return report