コード例 #1
0
    def check_tf_definition(self,
                            report,
                            root_folder,
                            runner_filter,
                            collect_skip_comments=True,
                            external_definitions_context=None):
        parser_registry.reset_definitions_context()
        logging.debug('Evaluating string booleans')
        self.evaluate_string_booleans()
        logging.debug('Evaluated string booleans')
        if external_definitions_context:
            definitions_context = external_definitions_context
        else:
            logging.debug('Creating definitions context')
            definitions_context = {}
            for definition in self.tf_definitions.items():
                definitions_context = parser_registry.enrich_definitions_context(
                    definition, collect_skip_comments)
            variable_evaluator = ConstVariableEvaluation(
                root_folder, self.tf_definitions, definitions_context)
            variable_evaluator.evaluate_variables()
            self.tf_definitions, self.definitions_context = variable_evaluator.tf_definitions, variable_evaluator.definitions_context
            logging.debug('Created definitions context')

        for full_file_path, definition in self.tf_definitions.items():
            scanned_file = f"/{os.path.relpath(full_file_path, root_folder)}"
            logging.debug(f"Scanning file: {scanned_file}")
            for block_type in definition.keys():
                if block_type in ['resource', 'data', 'provider', 'module']:
                    self.run_block(definition[block_type], definitions_context,
                                   full_file_path, report, scanned_file,
                                   block_type, runner_filter)
コード例 #2
0
 def setUp(self):
     test_root_dir = os.path.dirname(os.path.realpath(__file__)) + '/resources/default_evaluation'
     tf_definitions = {}
     parsing_errors = {}
     Parser().hcl2(directory=test_root_dir, tf_definitions=tf_definitions, parsing_errors=parsing_errors)
     for definition in tf_definitions.items():
         definitions_context = parser_registry.enrich_definitions_context(definition)
     variable_evaluator = ConstVariableEvaluation(test_root_dir, tf_definitions, definitions_context)
     variable_evaluator.evaluate_variables()
     self.tf_definitions = variable_evaluator.tf_definitions
     self.definitions_context = variable_evaluator.definitions_context
コード例 #3
0
 def check_tf_definition(self, report, root_folder):
     definitions_context = {}
     parser_registry.reset_definitions_context()
     for definition in self.tf_definitions.items():
         definitions_context = parser_registry.enrich_definitions_context(definition)
     self.evaluate_string_booleans()
     variable_evaluator = ConstVariableEvaluation(root_folder, self.tf_definitions, definitions_context)
     variable_evaluator.evaluate_variables()
     self.tf_definitions, self.definitions_context = variable_evaluator.tf_definitions, variable_evaluator.definitions_context
     for full_file_path, definition in self.tf_definitions.items():
         scanned_file = f"/{os.path.relpath(full_file_path, root_folder)}"
         logging.debug(f"Scanning file: {scanned_file}")
         for block_type in definition.keys():
             if block_type in ['resource', 'data', 'provider']:
                 self.run_block(definition[block_type], definitions_context, full_file_path, report, scanned_file,
                                block_type)
コード例 #4
0
ファイル: runner.py プロジェクト: jonathan-major/checkov
 def check_tf_definition(self, report, root_folder, tf_definitions):
     for definition in tf_definitions.items():
         definitions_context = parser_registry.enrich_definitions_context(
             definition)
     variable_evaluator = ConstVariableEvaluation(root_folder,
                                                  tf_definitions,
                                                  definitions_context)
     variable_evaluator.evaluate_variables()
     tf_definitions, definitions_context = variable_evaluator.tf_definitions, variable_evaluator.definitions_context
     for definition in tf_definitions.items():
         full_file_path = definition[0]
         scanned_file = definition[0].split(root_folder)[1]
         logging.debug("Scanning file: %s", scanned_file)
         for block_type in definition[1].keys():
             if block_type in ['resource', 'data']:
                 self.run_block(definition[1][block_type],
                                definitions_context, full_file_path, report,
                                scanned_file, block_type)
コード例 #5
0
 def test_extract_context_path(self):
     path = 'resource/0/aws_cognito_user_group/user_group/name/0'
     self.assertEqual(
         ConstVariableEvaluation.extract_context_path(path),
         ('resource/aws_cognito_user_group/user_group', 'name'))