From a102729848c9d378f5afe7872283928be8f6c87f Mon Sep 17 00:00:00 2001 From: Adi Daud <46249224+adi88d@users.noreply.github.com> Date: Wed, 4 Jan 2023 11:57:23 +0200 Subject: [PATCH] Content management update (#23287) --- .../ContentInstallation/ReleaseNotes/1_0_3.md | 5 +++ .../ContentPackInstaller.py | 42 +++++++++++++------ .../ContentPackInstaller.yml | 2 +- Packs/ContentInstallation/pack_metadata.json | 2 +- .../playbook-Configuration_Setup.yml | 3 ++ Packs/ContentManagement/ReleaseNotes/1_2_3.md | 9 ++++ .../Scripts/JobCreator/JobCreator.py | 24 ++++++++--- .../Scripts/JobCreator/JobCreator.yml | 2 +- Packs/ContentManagement/pack_metadata.json | 2 +- 9 files changed, 69 insertions(+), 22 deletions(-) create mode 100644 Packs/ContentInstallation/ReleaseNotes/1_0_3.md create mode 100644 Packs/ContentManagement/ReleaseNotes/1_2_3.md diff --git a/Packs/ContentInstallation/ReleaseNotes/1_0_3.md b/Packs/ContentInstallation/ReleaseNotes/1_0_3.md new file mode 100644 index 000000000000..8535c3f196de --- /dev/null +++ b/Packs/ContentInstallation/ReleaseNotes/1_0_3.md @@ -0,0 +1,5 @@ + +#### Scripts +##### ContentPackInstaller +- Added the option to specify `Demisto REST API` instance to use by setting the **using** value when running the script. +- Updated the Docker image to: *demisto/xsoar-tools:1.0.0.42327*. \ No newline at end of file diff --git a/Packs/ContentInstallation/Scripts/ContentPackInstaller/ContentPackInstaller.py b/Packs/ContentInstallation/Scripts/ContentPackInstaller/ContentPackInstaller.py index cc2c83101502..66edb8ccee95 100644 --- a/Packs/ContentInstallation/Scripts/ContentPackInstaller/ContentPackInstaller.py +++ b/Packs/ContentInstallation/Scripts/ContentPackInstaller/ContentPackInstaller.py @@ -11,13 +11,14 @@ class ContentPackInstaller: """ PACK_ID_VERSION_FORMAT = '{}::{}' - def __init__(self): + def __init__(self, instance_name: str = None): self.installed_packs: Dict[str, Union[Version, LegacyVersion]] = dict() self.newly_installed_packs: Dict[str, Version] = dict() self.already_on_machine_packs: Dict[str, Union[Version, LegacyVersion]] = dict() self.packs_data: Dict[str, Dict[str, str]] = dict() self.packs_dependencies: Dict[str, Dict[str, Dict[str, str]]] = dict() self.packs_failed: Dict[str, str] = dict() + self.instance_name: Optional[str] = instance_name self.get_installed_packs() @@ -26,9 +27,14 @@ def get_installed_packs(self) -> None: """ demisto.debug(f'{SCRIPT_NAME} - Fetching installed packs from marketplace.') + args = {'uri': '/contentpacks/metadata/installed'} + + if self.instance_name: + args['using'] = self.instance_name + status, res = execute_command( 'demisto-api-get', - {'uri': '/contentpacks/metadata/installed'}, + args, fail_on_error=False, ) @@ -61,9 +67,14 @@ def get_pack_data_from_marketplace(self, pack_id: str) -> Dict[str, str]: demisto.debug(f'{SCRIPT_NAME} - Fetching {pack_id} data from marketplace.') + args = {'uri': f'/contentpacks/marketplace/{pack_id}'} + + if self.instance_name: + args['using'] = self.instance_name + status, res = execute_command( 'demisto-api-get', - {'uri': f'/contentpacks/marketplace/{pack_id}'}, + args, fail_on_error=False, ) @@ -92,12 +103,16 @@ def get_pack_dependencies_from_marketplace(self, pack_data: Dict[str, str]) -> D demisto.debug(f'{SCRIPT_NAME} - Fetching {pack_key} dependencies data from marketplace.') + args = {'uri': '/contentpacks/marketplace/search/dependencies', + 'body': [pack_data] + } + + if self.instance_name: + args['using'] = self.instance_name + status, res = execute_command( 'demisto-api-post', - { - 'uri': '/contentpacks/marketplace/search/dependencies', - 'body': [pack_data] - }, + args, fail_on_error=False, ) @@ -165,11 +180,14 @@ def install_packs(self, packs_to_install: List[Dict[str, str]]) -> None: pack_id = pack['id'] pack_payload = json.dumps([{pack_id: pack['version']}]) + args = {'packs_to_install': str(pack_payload)} + + if self.instance_name: + args['using'] = self.instance_name + status, res = execute_command( 'demisto-api-install-packs', - { - 'packs_to_install': str(pack_payload) - }, + args, fail_on_error=False, ) @@ -322,9 +340,9 @@ def create_context(packs_to_install: List[Dict[str, str]], content_packs_install def main(): try: - installer = ContentPackInstaller() - args = demisto.args() + instance_name = args.get('using') + installer = ContentPackInstaller(instance_name) packs_to_install = format_packs_data_for_installation(args) install_dependencies = argToBoolean(args.get('install_dependencies', 'true')) diff --git a/Packs/ContentInstallation/Scripts/ContentPackInstaller/ContentPackInstaller.yml b/Packs/ContentInstallation/Scripts/ContentPackInstaller/ContentPackInstaller.yml index 939ff492a90c..a81333eeccf3 100644 --- a/Packs/ContentInstallation/Scripts/ContentPackInstaller/ContentPackInstaller.yml +++ b/Packs/ContentInstallation/Scripts/ContentPackInstaller/ContentPackInstaller.yml @@ -51,7 +51,7 @@ tags: - Content Management timeout: 600ns type: python -dockerimage: demisto/xsoar-tools:1.0.0.39936 +dockerimage: demisto/xsoar-tools:1.0.0.42327 tests: - ContentPackInstaller_Test fromversion: 6.0.0 diff --git a/Packs/ContentInstallation/pack_metadata.json b/Packs/ContentInstallation/pack_metadata.json index 4ecd84bca8d7..9a8f7e57cc31 100644 --- a/Packs/ContentInstallation/pack_metadata.json +++ b/Packs/ContentInstallation/pack_metadata.json @@ -2,7 +2,7 @@ "name": "Content Installation", "description": "This pack enables you install content packs.", "support": "xsoar", - "currentVersion": "1.0.2", + "currentVersion": "1.0.3", "author": "Cortex XSOAR", "url": "https://www.paloaltonetworks.com/cortex", "email": "", diff --git a/Packs/ContentManagement/Playbooks/playbook-Configuration_Setup.yml b/Packs/ContentManagement/Playbooks/playbook-Configuration_Setup.yml index bb6dc6d249e2..9ff57193147b 100644 --- a/Packs/ContentManagement/Playbooks/playbook-Configuration_Setup.yml +++ b/Packs/ContentManagement/Playbooks/playbook-Configuration_Setup.yml @@ -498,6 +498,9 @@ tasks: scriptarguments: job_name: simple: ${ConfigurationSetup.Jobs.name} + using: + complex: + root: inputs.InstanceName separatecontext: false view: |- { diff --git a/Packs/ContentManagement/ReleaseNotes/1_2_3.md b/Packs/ContentManagement/ReleaseNotes/1_2_3.md new file mode 100644 index 000000000000..98cd427da2e8 --- /dev/null +++ b/Packs/ContentManagement/ReleaseNotes/1_2_3.md @@ -0,0 +1,9 @@ + +#### Playbooks +##### Configuration Setup +- ***JobCreator*** script is now using the `Demisto REST API` instance name from playbook inputs. + +#### Scripts +##### JobCreator +- Added the option to specify `Demisto REST API` instance to use by setting the **using** value when running the script. +- Updated the Docker image to: *demisto/xsoar-tools:1.0.0.42327*. \ No newline at end of file diff --git a/Packs/ContentManagement/Scripts/JobCreator/JobCreator.py b/Packs/ContentManagement/Scripts/JobCreator/JobCreator.py index fd7ff8a245c9..cd1f043dca17 100644 --- a/Packs/ContentManagement/Scripts/JobCreator/JobCreator.py +++ b/Packs/ContentManagement/Scripts/JobCreator/JobCreator.py @@ -4,7 +4,7 @@ SCRIPT_NAME = 'JobCreator' -def configure_job(job_name: str, existing_job: Optional[Dict[str, Any]] = None) -> bool: +def configure_job(job_name: str, existing_job: Optional[Dict[str, Any]] = None, instance_name: str = None) -> bool: """Configures the job in the XSOAR instance. """ instance_context = demisto.context() @@ -22,9 +22,14 @@ def configure_job(job_name: str, existing_job: Optional[Dict[str, Any]] = None) if is_scheduled is False: job_params['scheduled'] = False + args = {'uri': '/jobs', 'body': job_params} + + if instance_name: + args['using'] = instance_name + status, res = execute_command( 'demisto-api-post', - {'uri': '/jobs', 'body': job_params}, + args, fail_on_error=False, ) @@ -36,11 +41,12 @@ def configure_job(job_name: str, existing_job: Optional[Dict[str, Any]] = None) return True -def search_existing_job(job_name: str) -> Dict[str, Any]: +def search_existing_job(job_name: str, instance_name: str = None) -> Dict[str, Any]: """Searches the machine for previously configured jobs with the given name. Args: job_name (str): The name of the job to update it's past configurations. + instance_name (str): Demisto REST API instance name. Returns: Dict[str, Any]. The job data as configured on the machine. @@ -51,9 +57,14 @@ def search_existing_job(job_name: str) -> Dict[str, Any]: 'query': f'name:"{job_name}"', } + args = {'uri': '/jobs/search', 'body': body} + + if instance_name: + args['using'] = instance_name + status, res = execute_command( 'demisto-api-post', - {'uri': '/jobs/search', 'body': body}, + args, fail_on_error=False, ) @@ -71,11 +82,12 @@ def search_existing_job(job_name: str) -> Dict[str, Any]: def main(): args = demisto.args() + instance_name = args.get('using') job_name = args.get('job_name') try: - existing_job = search_existing_job(job_name) - configuration_status = configure_job(job_name, existing_job) + existing_job = search_existing_job(job_name, instance_name) + configuration_status = configure_job(job_name, existing_job, instance_name) return_results( CommandResults( diff --git a/Packs/ContentManagement/Scripts/JobCreator/JobCreator.yml b/Packs/ContentManagement/Scripts/JobCreator/JobCreator.yml index b82be8fde7b4..d63043cadf10 100644 --- a/Packs/ContentManagement/Scripts/JobCreator/JobCreator.yml +++ b/Packs/ContentManagement/Scripts/JobCreator/JobCreator.yml @@ -23,7 +23,7 @@ tags: - Content Management timeout: '0' type: python -dockerimage: demisto/xsoar-tools:1.0.0.23423 +dockerimage: demisto/xsoar-tools:1.0.0.42327 tests: - No tests (auto formatted) fromversion: 6.0.0 diff --git a/Packs/ContentManagement/pack_metadata.json b/Packs/ContentManagement/pack_metadata.json index e015bd03e057..ccd3c75b6767 100644 --- a/Packs/ContentManagement/pack_metadata.json +++ b/Packs/ContentManagement/pack_metadata.json @@ -2,7 +2,7 @@ "name": "XSOAR CI/CD", "description": "This pack enables you to orchestrate your XSOAR system configuration.", "support": "xsoar", - "currentVersion": "1.2.2", + "currentVersion": "1.2.3", "author": "Cortex XSOAR", "url": "https://www.paloaltonetworks.com/cortex", "email": "",