def search_pack_and_its_dependencies(client: demisto_client, pack_id: str, packs_to_install: list, installation_request_body: list, lock: Lock): """ Searches for the pack of the specified file path, as well as its dependencies, and updates the list of packs to be installed accordingly. Args: client (demisto_client): The configured client to use. pack_id (str): The id of the pack to be installed. packs_to_install (list) A list of the packs to be installed in this iteration. installation_request_body (list): A list of packs to be installed, in the request format. lock (Lock): A lock object. """ pack_data = {} if pack_id not in packs_to_install: pack_display_name = get_pack_display_name(pack_id) if pack_display_name: pack_data = search_pack(client, pack_display_name, pack_id, lock) if pack_data is None: pack_data = { 'id': pack_id, 'version': '1.0.0' } if pack_data: dependencies = get_pack_dependencies(client, pack_data, lock) current_packs_to_install = [pack_data] if dependencies: # Check that the dependencies don't include a deprecated pack: for dependency in dependencies: pack_path = os.path.join(PACKS_FOLDER, dependency.get('id')) if is_pack_deprecated(pack_path): logging.critical(f'Pack {pack_id} depends on pack {dependency.get("id")} which is a deprecated ' f'pack.') global SUCCESS_FLAG SUCCESS_FLAG = False else: current_packs_to_install.extend(dependencies) lock.acquire() for pack in current_packs_to_install: if pack['id'] not in packs_to_install: packs_to_install.append(pack['id']) installation_request_body.append(pack) lock.release()
def test_is_pack_deprecated(tmp_path, pack_metadata_content, expected): """ Given: - Case A: Pack is not deprecated - Case B: Pack is deprecated When: - Checking if pack is deprecated Then: - Case A: Verify pack is not deprecated, since the 'hidden' flag is set to 'false' - Case B: Verify pack is deprecated, since the 'hidden' flag is set to 'true' """ pack_metadata_file = tmp_path / PACKS_PACK_META_FILE_NAME pack_metadata_file.write_text(json.dumps(pack_metadata_content)) assert is_pack_deprecated(str(tmp_path)) == expected