def test_get_integration_data(self): """ Test for getting all the integration data """ file_path = 'Packs/CortexXDR/Integrations/PaloAltoNetworks_XDR/PaloAltoNetworks_XDR.yml' data = get_integration_data(file_path) self.assertDictEqual(data, INTEGRATION_DATA)
def is_file_has_used_id(self, file_path): """Check if the ID of the given file already exist in the system. Args: file_path (string): Path to the file. Returns: bool. Whether the ID of the given file already exist in the system or not. """ is_used = False is_json_file = False if self.is_circle: if re.match(TEST_PLAYBOOK_REGEX, file_path, re.IGNORECASE): obj_type = self.TEST_PLAYBOOK_SECTION obj_id = collect_ids(file_path) obj_data = get_playbook_data(file_path) elif re.match(SCRIPT_REGEX, file_path, re.IGNORECASE) or \ re.match(TEST_SCRIPT_REGEX, file_path, re.IGNORECASE): obj_type = self.SCRIPTS_SECTION obj_id = get_script_or_integration_id(file_path) obj_data = get_script_data(file_path) elif re.match(INTEGRATION_REGEX, file_path, re.IGNORECASE) or \ re.match(INTEGRATION_YML_REGEX, file_path, re.IGNORECASE): obj_type = self.INTEGRATION_SECTION obj_id = get_script_or_integration_id(file_path) obj_data = get_integration_data(file_path) elif re.match(PLAYBOOK_REGEX, file_path, re.IGNORECASE): obj_type = self.PLAYBOOK_SECTION obj_id = collect_ids(file_path) obj_data = get_playbook_data(file_path) elif re.match(SCRIPT_YML_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_PY_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_JS_REGEX, file_path, re.IGNORECASE): yml_path, code = get_script_package_data( os.path.dirname(file_path)) obj_data = get_script_data(yml_path, script_code=code) obj_type = self.SCRIPTS_SECTION obj_id = get_script_or_integration_id(yml_path) else: # In case of a json file is_json_file = True if not is_json_file: is_used = self.is_id_duplicated(obj_id, obj_data, obj_type) return is_used
def is_file_has_used_id(self, file_path): """Check if the ID of the given file already exist in the system. Args: file_path (string): Path to the file. Returns: bool. Whether the ID of the given file already exist in the system or not. """ is_used = False is_json_file = False if self.is_circle: if re.match(TEST_PLAYBOOK_REGEX, file_path, re.IGNORECASE): obj_type = self.TEST_PLAYBOOK_SECTION obj_id = collect_ids(file_path) obj_data = get_playbook_data(file_path) elif re.match(SCRIPT_REGEX, file_path, re.IGNORECASE) or \ re.match(TEST_SCRIPT_REGEX, file_path, re.IGNORECASE): obj_type = self.SCRIPTS_SECTION obj_id = get_script_or_integration_id(file_path) obj_data = get_script_data(file_path) elif re.match(INTEGRATION_REGEX, file_path, re.IGNORECASE) or \ re.match(INTEGRATION_YML_REGEX, file_path, re.IGNORECASE): obj_type = self.INTEGRATION_SECTION obj_id = get_script_or_integration_id(file_path) obj_data = get_integration_data(file_path) elif re.match(PLAYBOOK_REGEX, file_path, re.IGNORECASE): obj_type = self.PLAYBOOK_SECTION obj_id = collect_ids(file_path) obj_data = get_playbook_data(file_path) elif re.match(SCRIPT_YML_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_PY_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_JS_REGEX, file_path, re.IGNORECASE): yml_path, code = get_script_package_data(os.path.dirname(file_path)) obj_data = get_script_data(yml_path, script_code=code) obj_type = self.SCRIPTS_SECTION obj_id = get_script_or_integration_id(yml_path) else: # In case of a json file is_json_file = True if not is_json_file: is_used = self.is_id_duplicated(obj_id, obj_data, obj_type) return is_used
def is_file_valid_in_set(self, file_path): """Check if the file is represented correctly in the id_set Args: file_path (string): Path to the file. Returns: bool. Whether the file is represented correctly in the id_set or not. """ is_valid = True if self.is_circle: # No need to check on local env because the id_set will contain this info after the commit if re.match(PLAYBOOK_REGEX, file_path, re.IGNORECASE): playbook_data = get_playbook_data(file_path) is_valid = self.is_valid_in_id_set(file_path, playbook_data, self.playbook_set) elif re.match(TEST_PLAYBOOK_REGEX, file_path, re.IGNORECASE): playbook_data = get_playbook_data(file_path) is_valid = self.is_valid_in_id_set(file_path, playbook_data, self.test_playbook_set) elif re.match(TEST_SCRIPT_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_REGEX, file_path, re.IGNORECASE): script_data = get_script_data(file_path) is_valid = self.is_valid_in_id_set(file_path, script_data, self.script_set) elif re.match(INTEGRATION_REGEX, file_path, re.IGNORECASE) or \ re.match(INTEGRATION_YML_REGEX, file_path, re.IGNORECASE): integration_data = get_integration_data(file_path) is_valid = self.is_valid_in_id_set(file_path, integration_data, self.integration_set) elif re.match(SCRIPT_YML_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_PY_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_JS_REGEX, file_path, re.IGNORECASE): yml_path, code = get_script_package_data( os.path.dirname(file_path)) script_data = get_script_data(yml_path, script_code=code) is_valid = self.is_valid_in_id_set(yml_path, script_data, self.script_set) return is_valid
def is_file_valid_in_set(self, file_path): """Check if the file is represented correctly in the id_set Args: file_path (string): Path to the file. Returns: bool. Whether the file is represented correctly in the id_set or not. """ is_valid = True if self.is_circle: # No need to check on local env because the id_set will contain this info after the commit if re.match(PLAYBOOK_REGEX, file_path, re.IGNORECASE): playbook_data = get_playbook_data(file_path) is_valid = self.is_valid_in_id_set(file_path, playbook_data, self.playbook_set) elif re.match(TEST_PLAYBOOK_REGEX, file_path, re.IGNORECASE): playbook_data = get_playbook_data(file_path) is_valid = self.is_valid_in_id_set(file_path, playbook_data, self.test_playbook_set) elif re.match(TEST_SCRIPT_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_REGEX, file_path, re.IGNORECASE): script_data = get_script_data(file_path) is_valid = self.is_valid_in_id_set(file_path, script_data, self.script_set) elif re.match(INTEGRATION_REGEX, file_path, re.IGNORECASE) or \ re.match(INTEGRATION_YML_REGEX, file_path, re.IGNORECASE): integration_data = get_integration_data(file_path) is_valid = self.is_valid_in_id_set(file_path, integration_data, self.integration_set) elif re.match(SCRIPT_YML_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_PY_REGEX, file_path, re.IGNORECASE) or \ re.match(SCRIPT_JS_REGEX, file_path, re.IGNORECASE): yml_path, code = get_script_package_data(os.path.dirname(file_path)) script_data = get_script_data(yml_path, script_code=code) is_valid = self.is_valid_in_id_set(yml_path, script_data, self.script_set) return is_valid