Skip to content

Commit

Permalink
Content management update (demisto#23287)
Browse files Browse the repository at this point in the history
  • Loading branch information
adi88d authored and xsoar-bot committed Jan 11, 2023
1 parent 7230e9a commit a102729
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 22 deletions.
5 changes: 5 additions & 0 deletions 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*.
Expand Up @@ -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()

Expand All @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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,
)

Expand Down Expand Up @@ -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'))

Expand Down
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Packs/ContentInstallation/pack_metadata.json
Expand Up @@ -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": "",
Expand Down
Expand Up @@ -498,6 +498,9 @@ tasks:
scriptarguments:
job_name:
simple: ${ConfigurationSetup.Jobs.name}
using:
complex:
root: inputs.InstanceName
separatecontext: false
view: |-
{
Expand Down
9 changes: 9 additions & 0 deletions 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*.
24 changes: 18 additions & 6 deletions Packs/ContentManagement/Scripts/JobCreator/JobCreator.py
Expand Up @@ -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()
Expand All @@ -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,
)

Expand All @@ -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.
Expand All @@ -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,
)

Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion Packs/ContentManagement/Scripts/JobCreator/JobCreator.yml
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Packs/ContentManagement/pack_metadata.json
Expand Up @@ -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": "",
Expand Down

0 comments on commit a102729

Please sign in to comment.