PrismaCloudRemoteTrustedImagesListUpdate
Gets the existing "Trusted Images" results from Prisma Cloud Compute and updates the relevant trust group with the images stored in the given internal list.
Source
import demistomock as demisto # noqa: F401 from CommonServerPython import * # noqa: F401 DATE_FORMAT = "%Y-%m-%dT%H:%M:%SZ" # ISO8601 format with UTC, default in XSOAR def get_xsoar_list(list_name: str) -> dict: """ Gets a list from XSOAR if it exists. """ res = demisto.executeCommand("getList", {"listName": list_name}) if "Item not found" in res[0]["Contents"]: raise DemistoException(f"List {list_name} was not found.") if is_error(res): raise DemistoException(get_error(res)) current_list = json.loads(res[0]["Contents"]) or {} return current_list def current_remote_images_same_as_local(remote_images: list, local_images: list): """ Compares remote images to local trusted images list and returns True if same, False otherwise. """ return set(remote_images) == set(local_images) def update_group_from_images( remote_trusted_images: Dict[str, Any], current_trusted_images: list, trusted_group_id: str ) -> tuple[bool, str]: """ Update the remote trusted images group with latest images from local source. """ for group in remote_trusted_images["groups"]: if group["_id"] == trusted_group_id: if current_remote_images_same_as_local(group["images"], current_trusted_images): return False, "Local and remote lists were equal, not updating list." group["images"] = current_trusted_images return True, "" return False, f"Group {trusted_group_id} was not found in the given trusted images groups list." def update_remote_list(current_dict: dict): """ Updates the remote trusted images list with the latest images from the local trusted images list. """ res = demisto.executeCommand("prisma-cloud-compute-trusted-images-update", {"images_list_json": json.dumps(current_dict)}) if is_error(res): raise DemistoException(get_error(res)) return res[0]["HumanReadable"] def update_remote_trusted_images(args: Dict[str, Any]): """ Updates the remote trusted images list from the local trusted images list. """ list_name = args["list_name"] local_trusted_images = list((get_xsoar_list(list_name)).keys()) remote_trusted_images = args.get("current_trusted_images") if isinstance(remote_trusted_images, str): remote_trusted_images = json.loads(remote_trusted_images) trusted_group_id = str(args.get("trusted_group_id")) update_remote, result = update_group_from_images(remote_trusted_images, local_trusted_images, trusted_group_id) if update_remote: result = update_remote_list(remote_trusted_images) return CommandResults(readable_output=result) def main(): try: args = demisto.args() result = update_remote_trusted_images(args) return_results(result) except Exception as e: return_error(f"Failed to execute PrismaCloudLocalTrustedImagesListUpdate. Error: {e!s}") """ ENTRY POINT """ if __name__ in ("__main__", "__builtin__", "builtins"): main()
README
Gets the existing “Trusted Images” results from Prisma Cloud Compute and updates the relevant trust group with the images stored in the given internal list.
Script Data
| Name | Description |
|---|---|
| Script Type | python3 |
| Cortex XSOAR Version | 6.9.0 |
Dependencies
This script uses the following commands and scripts.
- PaloAltoNetworks_PrismaCloudCompute
- prisma-cloud-compute-trusted-images-update
Inputs
| Argument Name | Description |
|---|---|
| list_name | The name of the XSOAR internal list we wish to use in order to update the remote trust images list. |
| trusted_group_id | The trusted group which should be updated with the images of the given list. In order to get the trusted groups ID, either use the Prisma Cloud UI (the ID would be the group name) or use the “prisma-cloud-compute-trusted-images-list” command. |
| current_trusted_images | The current state of the trusted images in Prisma Cloud. Can be retrieved with the “prisma-cloud-compute-trusted-images-list” command. |
Outputs
There are no outputs for this script.