|
| 1 | +from collections.abc import Iterable, Callable |
| 2 | +from typing import Any |
| 3 | +import google.cloud.storage |
| 4 | +import numpy as np |
| 5 | +import posixpath |
| 6 | +import dill as pickle |
| 7 | +import os |
| 8 | +import itertools |
| 9 | +import string |
| 10 | +import re |
| 11 | +import math |
| 12 | +from itertools import groupby |
| 13 | +import traceback |
1 | 14 | import demistomock as demisto # noqa: F401
|
2 | 15 | from CommonServerPython import * # noqa: F401
|
| 16 | +demisto.debug('pack name = Cortex Attack Surface Management, pack version = 1.7.65') |
| 17 | + |
| 18 | + |
3 | 19 | """Script for identifying and recommending the most likely owners of a discovered service
|
4 | 20 | from those surfaced by Cortex ASM Enrichment.
|
5 | 21 | """
|
6 | 22 |
|
7 |
| -import traceback |
8 |
| -from itertools import groupby |
9 |
| -import math |
10 |
| - |
11 |
| -import re |
12 |
| -import string |
13 |
| -import itertools |
14 |
| -import os |
15 |
| -import dill as pickle |
16 |
| -import posixpath |
17 |
| -import numpy as np |
18 |
| -import google.cloud.storage |
19 |
| - |
20 |
| - |
21 |
| -from typing import Any |
22 |
| -from collections.abc import Iterable, Callable |
23 |
| - |
24 | 23 |
|
25 | 24 | STRING_DELIMITER = ' | ' # delimiter used for joining source fields and any additional fields of type string
|
26 | 25 |
|
@@ -614,24 +613,34 @@ def featurize(self, service_identifiers: Iterable[str], owners: list[dict[str, A
|
614 | 613 | return X
|
615 | 614 |
|
616 | 615 |
|
| 616 | +def write_output_to_context_key(final_owners: list[dict[str, str]], owner_related_field: str, platform_tenant: str): |
| 617 | + stringify_platform_tenant = str(platform_tenant) |
| 618 | + set_alert_issue_map = {"True": "setIssue", "False": "setAlert"} |
| 619 | + if final_owners and owner_related_field: |
| 620 | + res = demisto.executeCommand(set_alert_issue_map[stringify_platform_tenant], {owner_related_field: final_owners}) |
| 621 | + if isError(res): |
| 622 | + raise ValueError('Unable to update field') |
| 623 | + return_results(CommandResults(readable_output=f"Owners ranked and written to {owner_related_field}")) |
| 624 | + else: |
| 625 | + return_results(CommandResults(readable_output='No owners found')) |
| 626 | + |
| 627 | + |
617 | 628 | def main():
|
618 | 629 | try:
|
619 | 630 | # parse inputs
|
620 | 631 | unranked = demisto.args().get("owners", [])
|
621 | 632 | if isinstance(unranked, dict):
|
622 | 633 | unranked = [unranked]
|
623 | 634 | asm_system_ids = demisto.args().get("asmsystemids", [])
|
624 |
| - |
| 635 | + owner_related_field = demisto.args().get("ownerrelatedfield", "asmserviceowner") |
| 636 | + platform_tenant_usage = demisto.args().get("tenantcommand", "False") |
625 | 637 | # deduplicate/normalize, score, and rank owners
|
626 | 638 | normalized = aggregate(canonicalize(unranked))
|
627 | 639 | final_owners = justify(rank(score(owners=normalized, asm_system_ids=asm_system_ids)))
|
628 | 640 |
|
629 |
| - # write output to context |
630 |
| - if final_owners: |
631 |
| - demisto.executeCommand("setAlert", {"asmserviceowner": final_owners}) |
632 |
| - return_results(CommandResults(readable_output='Service owners ranked and written to asmserviceowner')) |
633 |
| - else: |
634 |
| - return_results(CommandResults(readable_output='No service owners found')) |
| 641 | + write_output_to_context_key(final_owners=final_owners, |
| 642 | + owner_related_field=owner_related_field, |
| 643 | + platform_tenant=platform_tenant_usage) |
635 | 644 |
|
636 | 645 | except Exception as ex:
|
637 | 646 | demisto.error(traceback.format_exc()) # print the traceback
|
|
0 commit comments