datalake-scripts 3.0.0rc1__tar.gz → 3.0.0rc3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/PKG-INFO +1 -1
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/datalake.py +2 -2
- datalake_scripts-3.0.0rc1/datalake/endpoints/filtered_tag_subcategory.py → datalake_scripts-3.0.0rc3/datalake/endpoints/filtered_threat_entity.py +21 -16
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/cli.py +4 -4
- datalake_scripts-3.0.0rc3/datalake_scripts/scripts/get_filtered_threat_entity.py +67 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts.egg-info/PKG-INFO +1 -1
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts.egg-info/SOURCES.txt +3 -3
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/common/fixture.py +8 -28
- datalake_scripts-3.0.0rc1/tests/lib/test_filtered_tag_subcategory.py → datalake_scripts-3.0.0rc3/tests/lib/test_filtered_threat_entity.py +16 -14
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/scripts/test_cli.py +2 -2
- datalake_scripts-3.0.0rc1/datalake_scripts/scripts/get_filtered_tag_subcategory.py +0 -52
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/README.md +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/__init__.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/common/__init__.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/common/atom.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/common/atom_type.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/common/bulk_search_task.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/common/config.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/common/logger.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/common/output.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/common/throttler.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/common/token_manager.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/common/utils.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/common/warn.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/endpoints/__init__.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/endpoints/advanced_search.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/endpoints/bulk_search.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/endpoints/comments.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/endpoints/endpoint.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/endpoints/sightings.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/endpoints/sources.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/endpoints/tags.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/endpoints/threats.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/miscellaneous/__init__.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/miscellaneous/search_watch.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/__init__.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/common/__init__.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/common/base_script.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/helper_scripts/__init__.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/helper_scripts/output_builder.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/helper_scripts/utils.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/__init__.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/add_comments.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/add_tags.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/add_threats.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/advanced_search.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/bulk_lookup_threats.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/edit_score.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/get_atom_values.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/get_query_hash.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/get_threats.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/get_threats_from_query_hash.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/lookup_threats.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/search_watch.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts.egg-info/dependency_links.txt +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts.egg-info/entry_points.txt +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts.egg-info/requires.txt +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts.egg-info/top_level.txt +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/setup.cfg +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/setup.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/__init__.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/common/__init__.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/common/test_output.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/common/test_utils.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/conftest.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/lib/__init__.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/lib/test_advanced_search.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/lib/test_atom_type.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/lib/test_auth_via_tokens.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/lib/test_bulk_search.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/lib/test_search_watch.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/lib/test_sightings.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/lib/test_tags.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/lib/test_threats.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/scripts/__init__.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/scripts/test_add_new_threats.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/scripts/test_base_scripts.py +0 -0
- {datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/scripts/test_csv_builder.py +0 -0
|
@@ -10,7 +10,7 @@ from datalake.endpoints.tags import Tags
|
|
|
10
10
|
from datalake.endpoints.advanced_search import AdvancedSearch
|
|
11
11
|
from datalake.endpoints.sightings import Sightings
|
|
12
12
|
from datalake.endpoints.sources import Sources
|
|
13
|
-
from datalake.endpoints.
|
|
13
|
+
from datalake.endpoints.filtered_threat_entity import FilteredThreatEntity
|
|
14
14
|
from datalake.miscellaneous.search_watch import SearchWatch
|
|
15
15
|
|
|
16
16
|
|
|
@@ -74,7 +74,7 @@ class Datalake:
|
|
|
74
74
|
proxies=proxies,
|
|
75
75
|
verify=verify,
|
|
76
76
|
)
|
|
77
|
-
self.
|
|
77
|
+
self.FilteredThreatEntity = FilteredThreatEntity(
|
|
78
78
|
self.logger,
|
|
79
79
|
endpoint_config,
|
|
80
80
|
env,
|
|
@@ -1,31 +1,33 @@
|
|
|
1
1
|
from datalake.endpoints.endpoint import Endpoint
|
|
2
|
-
from datalake.common.output import parse_response
|
|
2
|
+
from datalake.common.output import parse_response, Output, output_supported
|
|
3
3
|
import re
|
|
4
4
|
import sys
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
class
|
|
7
|
+
class FilteredThreatEntity(Endpoint):
|
|
8
|
+
@output_supported({Output.JSON, Output.STIX})
|
|
8
9
|
def get_filtered_and_sorted_list(
|
|
9
10
|
self,
|
|
10
|
-
|
|
11
|
+
threat_category_name=None,
|
|
11
12
|
alias=None,
|
|
12
13
|
description=None,
|
|
13
14
|
ids=None,
|
|
14
15
|
limit=10,
|
|
15
16
|
name=None,
|
|
16
17
|
offset=0,
|
|
17
|
-
ordering="
|
|
18
|
+
ordering="threat_category_name",
|
|
18
19
|
stix_uuid=None,
|
|
19
20
|
tag=None,
|
|
21
|
+
output=Output.JSON,
|
|
20
22
|
):
|
|
21
23
|
"""
|
|
22
|
-
Retrieve
|
|
24
|
+
Retrieve threat entities, with available filtering options as input parameters
|
|
23
25
|
"""
|
|
24
|
-
url = self._build_url_for_endpoint("
|
|
26
|
+
url = self._build_url_for_endpoint("threat-entity-filtered")
|
|
25
27
|
body = {}
|
|
26
28
|
|
|
27
|
-
if
|
|
28
|
-
body["
|
|
29
|
+
if threat_category_name:
|
|
30
|
+
body["threat_category_name"] = threat_category_name
|
|
29
31
|
if alias:
|
|
30
32
|
body["alias"] = alias
|
|
31
33
|
if description:
|
|
@@ -42,28 +44,31 @@ class FilteredTagSubcategory(Endpoint):
|
|
|
42
44
|
# Set default values if not provided
|
|
43
45
|
body["limit"] = limit if limit is not None else 10
|
|
44
46
|
body["offset"] = offset if offset is not None else 0
|
|
45
|
-
body["ordering"] = ordering if ordering is not None else "
|
|
47
|
+
body["ordering"] = ordering if ordering is not None else "threat_category_name"
|
|
46
48
|
|
|
47
49
|
try:
|
|
48
50
|
response = self.datalake_requests(
|
|
49
|
-
url=url,
|
|
51
|
+
url=url,
|
|
52
|
+
method="post",
|
|
53
|
+
headers=self._post_headers(output=output),
|
|
54
|
+
post_body=body,
|
|
50
55
|
)
|
|
51
56
|
return parse_response(response)
|
|
52
57
|
except ValueError as ve:
|
|
53
58
|
error_message = str(ve)
|
|
54
|
-
|
|
55
|
-
r"No
|
|
59
|
+
threat_category_match = re.search(
|
|
60
|
+
r"No threat category found: ([^']+)'", error_message
|
|
56
61
|
)
|
|
57
|
-
if
|
|
62
|
+
if threat_category_match:
|
|
58
63
|
print(
|
|
59
|
-
f"The
|
|
64
|
+
f"The threat category name '{threat_category_match.group(1)}' is invalid; please note that this argument is case-sensitive."
|
|
60
65
|
)
|
|
61
66
|
ordering_match = re.search(
|
|
62
67
|
r"'([^']+)' is not a valid choice", error_message
|
|
63
68
|
)
|
|
64
69
|
if ordering_match:
|
|
65
70
|
print(
|
|
66
|
-
f"{ordering_match.group(1)} is not a valid choice for ordering, valid values: '-
|
|
71
|
+
f"{ordering_match.group(1)} is not a valid choice for ordering, valid values: '-threat_category_name', '-created_at', '-name', '-updated_at', 'threat_category_name', 'created_at', 'name', 'updated_at'"
|
|
67
72
|
)
|
|
68
73
|
limit_match = re.search(
|
|
69
74
|
r"Must be greater than or equal to 0 and less than or equal to 5000",
|
|
@@ -78,7 +83,7 @@ class FilteredTagSubcategory(Endpoint):
|
|
|
78
83
|
if token_match:
|
|
79
84
|
raise ve
|
|
80
85
|
if (
|
|
81
|
-
not
|
|
86
|
+
not threat_category_match
|
|
82
87
|
and not ordering_match
|
|
83
88
|
and not limit_match
|
|
84
89
|
and not token_match
|
|
@@ -13,14 +13,14 @@ from datalake_scripts.scripts import (
|
|
|
13
13
|
bulk_lookup_threats,
|
|
14
14
|
advanced_search,
|
|
15
15
|
get_atom_values,
|
|
16
|
-
|
|
16
|
+
get_filtered_threat_entity,
|
|
17
17
|
search_watch,
|
|
18
18
|
)
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
class Cli:
|
|
22
22
|
CLI_NAME = "ocd-dtl"
|
|
23
|
-
VERSION = "3.0.
|
|
23
|
+
VERSION = "3.0.0rc3"
|
|
24
24
|
|
|
25
25
|
def __init__(self):
|
|
26
26
|
parser = argparse.ArgumentParser(
|
|
@@ -50,8 +50,8 @@ class Cli:
|
|
|
50
50
|
self._add_command_subparser(subparsers, "advanced_search", advanced_search.main)
|
|
51
51
|
self._add_command_subparser(
|
|
52
52
|
subparsers,
|
|
53
|
-
"
|
|
54
|
-
|
|
53
|
+
"get_filtered_threat_entity",
|
|
54
|
+
get_filtered_threat_entity.main,
|
|
55
55
|
)
|
|
56
56
|
self._add_command_subparser(subparsers, "search_watch", search_watch.main)
|
|
57
57
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import json
|
|
3
|
+
from datalake import Datalake, Output
|
|
4
|
+
from datalake_scripts.common.base_script import BaseScripts
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def main(args=None):
|
|
8
|
+
parser = BaseScripts.start("Get filtered and sorted list of threat entities.")
|
|
9
|
+
# Add arguments as required by the subcommand
|
|
10
|
+
parser.add_argument(
|
|
11
|
+
"--threat-category-name", help="Name of the threat category", default=None
|
|
12
|
+
)
|
|
13
|
+
parser.add_argument("--alias", help="Alias for the threat entity", default=None)
|
|
14
|
+
parser.add_argument(
|
|
15
|
+
"--description", help="Description for the threat entity", default=None
|
|
16
|
+
)
|
|
17
|
+
parser.add_argument("-l", "--limit", help="Maximum number of item", default=None)
|
|
18
|
+
parser.add_argument("--name", help="Name of the threat entity", default=None)
|
|
19
|
+
parser.add_argument(
|
|
20
|
+
"--offset", help="Index of the first item to return", default=None
|
|
21
|
+
)
|
|
22
|
+
parser.add_argument("--ordering", help="Ordering of the result", default=None)
|
|
23
|
+
parser.add_argument("--stix_uuid", help="Filter by stix_uuid", default=None)
|
|
24
|
+
parser.add_argument(
|
|
25
|
+
"-t", "--tag", help="Filter Tag associated with threat entity", default=None
|
|
26
|
+
)
|
|
27
|
+
parser.add_argument(
|
|
28
|
+
"-ot", "--output-type", help="Desired output type", default=None
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
if args is None:
|
|
32
|
+
args = parser.parse_args()
|
|
33
|
+
else:
|
|
34
|
+
args = parser.parse_args(args)
|
|
35
|
+
|
|
36
|
+
dtl = Datalake(env=args.env, log_level=args.loglevel)
|
|
37
|
+
|
|
38
|
+
output_type = Output.JSON
|
|
39
|
+
if args.output_type:
|
|
40
|
+
try:
|
|
41
|
+
output_type = Output[args.output_type.upper()]
|
|
42
|
+
except KeyError:
|
|
43
|
+
dtl.logger.error("Not supported output, please use either json or stix")
|
|
44
|
+
exit(1)
|
|
45
|
+
|
|
46
|
+
threat_entities = dtl.FilteredThreatEntity.get_filtered_and_sorted_list(
|
|
47
|
+
threat_category_name=args.threat_category_name,
|
|
48
|
+
alias=args.alias,
|
|
49
|
+
description=args.description,
|
|
50
|
+
limit=args.limit,
|
|
51
|
+
name=args.name,
|
|
52
|
+
offset=args.offset,
|
|
53
|
+
ordering=args.ordering,
|
|
54
|
+
stix_uuid=args.stix_uuid,
|
|
55
|
+
tag=args.tag,
|
|
56
|
+
output=output_type,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
if args.output and threat_entities is not None:
|
|
60
|
+
with open(args.output, "w") as f:
|
|
61
|
+
json.dump(threat_entities, f, indent=4)
|
|
62
|
+
elif threat_entities is not None:
|
|
63
|
+
print(json.dumps(threat_entities, indent=4))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if __name__ == "__main__":
|
|
67
|
+
sys.exit(main())
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts.egg-info/SOURCES.txt
RENAMED
|
@@ -19,7 +19,7 @@ setup.py
|
|
|
19
19
|
./datalake/endpoints/bulk_search.py
|
|
20
20
|
./datalake/endpoints/comments.py
|
|
21
21
|
./datalake/endpoints/endpoint.py
|
|
22
|
-
./datalake/endpoints/
|
|
22
|
+
./datalake/endpoints/filtered_threat_entity.py
|
|
23
23
|
./datalake/endpoints/sightings.py
|
|
24
24
|
./datalake/endpoints/sources.py
|
|
25
25
|
./datalake/endpoints/tags.py
|
|
@@ -41,7 +41,7 @@ setup.py
|
|
|
41
41
|
./datalake_scripts/scripts/bulk_lookup_threats.py
|
|
42
42
|
./datalake_scripts/scripts/edit_score.py
|
|
43
43
|
./datalake_scripts/scripts/get_atom_values.py
|
|
44
|
-
./datalake_scripts/scripts/
|
|
44
|
+
./datalake_scripts/scripts/get_filtered_threat_entity.py
|
|
45
45
|
./datalake_scripts/scripts/get_query_hash.py
|
|
46
46
|
./datalake_scripts/scripts/get_threats.py
|
|
47
47
|
./datalake_scripts/scripts/get_threats_from_query_hash.py
|
|
@@ -58,7 +58,7 @@ setup.py
|
|
|
58
58
|
./tests/lib/test_atom_type.py
|
|
59
59
|
./tests/lib/test_auth_via_tokens.py
|
|
60
60
|
./tests/lib/test_bulk_search.py
|
|
61
|
-
./tests/lib/
|
|
61
|
+
./tests/lib/test_filtered_threat_entity.py
|
|
62
62
|
./tests/lib/test_search_watch.py
|
|
63
63
|
./tests/lib/test_sightings.py
|
|
64
64
|
./tests/lib/test_tags.py
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import json
|
|
1
2
|
import pytest
|
|
2
3
|
import responses
|
|
3
4
|
|
|
@@ -7,40 +8,19 @@ from datalake import Datalake
|
|
|
7
8
|
from datalake.common.config import Config
|
|
8
9
|
from datalake.common.token_manager import TokenManager
|
|
9
10
|
|
|
11
|
+
with open("tests/common/tests_endpoints.json", "r") as json_file:
|
|
12
|
+
TEST_CONFIG_FILE = json.load(json_file)
|
|
13
|
+
|
|
10
14
|
|
|
11
15
|
class TestData:
|
|
12
16
|
TEST_ENV = "prod"
|
|
13
17
|
TEST_CONFIG = {
|
|
14
18
|
"main": {
|
|
15
|
-
TEST_ENV: "
|
|
16
|
-
"preprod": "
|
|
17
|
-
},
|
|
18
|
-
"endpoints": {
|
|
19
|
-
"token": "auth/token/",
|
|
20
|
-
"refresh-token": "auth/refresh-token/",
|
|
21
|
-
"advanced-queries-threats": "mrti/advanced-queries/threats/",
|
|
22
|
-
"advanced-queries-threats-query-hash": "mrti/advanced-queries/threats/{query_hash}/",
|
|
23
|
-
"atom-values": "mrti/atom-values/",
|
|
24
|
-
"bulk-search": "mrti/bulk-search/",
|
|
25
|
-
"bulk-search-tasks": "mrti/bulk-search/tasks/",
|
|
26
|
-
"bulk-search-task": "mrti/bulk-search/task/{task_uuid}/",
|
|
27
|
-
"bulk-manual-threats": "mrti/bulk-manual-threats/",
|
|
28
|
-
"bulk-manual-threats-task": "mrti/bulk-manual-threats/task/{task_uuid}/",
|
|
29
|
-
"sources": "mrti/sources/",
|
|
30
|
-
"tag-subcategory-filtered": "mrti/tag-subcategory/filtered/",
|
|
31
|
-
"threats-manual": "mrti/threats-manual/",
|
|
32
|
-
"threats-bulk-lookup": "mrti/threats/bulk-lookup/",
|
|
33
|
-
"threats": "mrti/threats/{hashkey}/",
|
|
34
|
-
"threats-lookup": "mrti/threats/lookup/",
|
|
35
|
-
"threats-comments": "mrti/threats/{hashkey}/comments/",
|
|
36
|
-
"threats-tags": "mrti/threats/{hashkey}/tags/",
|
|
37
|
-
"threats-atom-values-extract": "mrti/threats/atom-values-extract/",
|
|
38
|
-
"threats-bulk-scoring-edits": "mrti/threats/bulk-scoring-edits/",
|
|
39
|
-
"threats-sighting": "mrti/threats/sighting/",
|
|
40
|
-
"threats-sighting-file": "mrti/threats/sighting-file/{hashkey}/",
|
|
41
|
-
"threats-sighting-filtered": "mrti/threats/sighting/filtered/",
|
|
19
|
+
TEST_ENV: TEST_CONFIG_FILE["main"][TEST_ENV],
|
|
20
|
+
"preprod": TEST_CONFIG_FILE["main"]["preprod"],
|
|
42
21
|
},
|
|
43
|
-
"
|
|
22
|
+
"endpoints": TEST_CONFIG_FILE["endpoints"],
|
|
23
|
+
"api_version": TEST_CONFIG_FILE["api_version"],
|
|
44
24
|
}
|
|
45
25
|
|
|
46
26
|
|
|
@@ -7,8 +7,8 @@ from tests.common.fixture import TestData, datalake
|
|
|
7
7
|
mock_results_data = [
|
|
8
8
|
{
|
|
9
9
|
"aliases": None,
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"threat_category_id": 6,
|
|
11
|
+
"threat_category_name": "Vulnerability",
|
|
12
12
|
"created_at": "2023-10-18T00:10:27.957064+00:00",
|
|
13
13
|
"custom_fields": None,
|
|
14
14
|
"description": "CVSS Score: 3.1 -- CVE numbers: CVE-2004-2770, CVE-2011-3389",
|
|
@@ -73,7 +73,7 @@ def mock_api_response():
|
|
|
73
73
|
responses.POST,
|
|
74
74
|
TestData.TEST_CONFIG["main"][TestData.TEST_ENV]
|
|
75
75
|
+ TestData.TEST_CONFIG["api_version"]
|
|
76
|
-
+ TestData.TEST_CONFIG["endpoints"]["
|
|
76
|
+
+ TestData.TEST_CONFIG["endpoints"]["threat-entity-filtered"],
|
|
77
77
|
json={"results": mock_results_data}, # Only return the "results" part
|
|
78
78
|
status=200,
|
|
79
79
|
)
|
|
@@ -83,12 +83,12 @@ def mock_api_response():
|
|
|
83
83
|
def test_get_filtered_and_sorted_list(datalake: Datalake):
|
|
84
84
|
mock_api_response()
|
|
85
85
|
params = {
|
|
86
|
-
"
|
|
86
|
+
"threat_category_name": "Vulnerability",
|
|
87
87
|
"limit": 5,
|
|
88
88
|
"offset": 0,
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
response =
|
|
90
|
+
filtered_threat_entity = datalake.FilteredThreatEntity
|
|
91
|
+
response = filtered_threat_entity.get_filtered_and_sorted_list(**params)
|
|
92
92
|
# Verify the response contains the "results" part
|
|
93
93
|
assert "results" in response
|
|
94
94
|
assert response["results"] == mock_results_data
|
|
@@ -97,22 +97,24 @@ def test_get_filtered_and_sorted_list(datalake: Datalake):
|
|
|
97
97
|
assert responses.calls[0].request.url, (
|
|
98
98
|
TestData.TEST_CONFIG["main"][TestData.TEST_ENV]
|
|
99
99
|
+ TestData.TEST_CONFIG["api_version"]
|
|
100
|
-
+ TestData.TEST_CONFIG["endpoints"]["
|
|
100
|
+
+ TestData.TEST_CONFIG["endpoints"]["threat-entity-filtered"]
|
|
101
101
|
)
|
|
102
102
|
assert responses.calls[0].request.method, "POST"
|
|
103
103
|
request_body = json.loads(responses.calls[0].request.body)
|
|
104
|
-
assert request_body["
|
|
104
|
+
assert request_body["threat_category_name"], params["threat_category_name"]
|
|
105
105
|
assert request_body["limit"], params["limit"]
|
|
106
106
|
|
|
107
107
|
for result in response["results"]:
|
|
108
|
-
assert "
|
|
108
|
+
assert "threat_category_id" in result, "Result should have a threat_category_id"
|
|
109
109
|
assert isinstance(
|
|
110
|
-
result["
|
|
111
|
-
), "
|
|
112
|
-
assert
|
|
110
|
+
result["threat_category_id"], int
|
|
111
|
+
), "threat_category_id should be an integer"
|
|
112
|
+
assert (
|
|
113
|
+
"threat_category_name" in result
|
|
114
|
+
), "Result should have a threat_category_name"
|
|
113
115
|
assert isinstance(
|
|
114
|
-
result["
|
|
115
|
-
), "
|
|
116
|
+
result["threat_category_name"], str
|
|
117
|
+
), "threat_category_name should be a string"
|
|
116
118
|
assert "created_at" in result, "Result should have a created_at"
|
|
117
119
|
assert isinstance(result["created_at"], str), "created_at should be a string"
|
|
118
120
|
assert "description" in result, "Result should have a description"
|
|
@@ -14,7 +14,7 @@ from datalake_scripts.scripts import (
|
|
|
14
14
|
bulk_lookup_threats,
|
|
15
15
|
advanced_search,
|
|
16
16
|
get_atom_values,
|
|
17
|
-
|
|
17
|
+
get_filtered_threat_entity,
|
|
18
18
|
search_watch,
|
|
19
19
|
)
|
|
20
20
|
|
|
@@ -34,7 +34,7 @@ from datalake_scripts.scripts import (
|
|
|
34
34
|
bulk_lookup_threats,
|
|
35
35
|
advanced_search,
|
|
36
36
|
get_atom_values,
|
|
37
|
-
|
|
37
|
+
get_filtered_threat_entity,
|
|
38
38
|
search_watch,
|
|
39
39
|
],
|
|
40
40
|
)
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
import json
|
|
3
|
-
from datalake import Datalake
|
|
4
|
-
from datalake_scripts.common.base_script import BaseScripts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
def main(args=None):
|
|
8
|
-
parser = BaseScripts.start("Get filtered and sorted list of tag subcategories.")
|
|
9
|
-
# Add arguments as required by the subcommand
|
|
10
|
-
parser.add_argument("--category-name", help="Name of the category", default=None)
|
|
11
|
-
parser.add_argument("--alias", help="Alias for the tag subcategory", default=None)
|
|
12
|
-
parser.add_argument(
|
|
13
|
-
"--description", help="Description for the tag subcategory", default=None
|
|
14
|
-
)
|
|
15
|
-
parser.add_argument("-l", "--limit", help="Maximum number of item", default=None)
|
|
16
|
-
parser.add_argument("--name", help="Name of the tag subcategory", default=None)
|
|
17
|
-
parser.add_argument(
|
|
18
|
-
"--offset", help="Index of the first item to return", default=None
|
|
19
|
-
)
|
|
20
|
-
parser.add_argument("--ordering", help="Ordering of the result", default=None)
|
|
21
|
-
parser.add_argument("--stix_uuid", help="Filter by stix_uuid", default=None)
|
|
22
|
-
parser.add_argument(
|
|
23
|
-
"-t", "--tag", help="Filter Tag associated with subcategory", default=None
|
|
24
|
-
)
|
|
25
|
-
|
|
26
|
-
if args is None:
|
|
27
|
-
args = parser.parse_args()
|
|
28
|
-
else:
|
|
29
|
-
args = parser.parse_args(args)
|
|
30
|
-
|
|
31
|
-
dtl = Datalake(env=args.env, log_level=args.loglevel)
|
|
32
|
-
subcategories = dtl.FilteredTagSubcategory.get_filtered_and_sorted_list(
|
|
33
|
-
category_name=args.category_name,
|
|
34
|
-
alias=args.alias,
|
|
35
|
-
description=args.description,
|
|
36
|
-
limit=args.limit,
|
|
37
|
-
name=args.name,
|
|
38
|
-
offset=args.offset,
|
|
39
|
-
ordering=args.ordering,
|
|
40
|
-
stix_uuid=args.stix_uuid,
|
|
41
|
-
tag=args.tag,
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
if args.output and subcategories is not None:
|
|
45
|
-
with open(args.output, "w") as f:
|
|
46
|
-
json.dump(subcategories, f, indent=4)
|
|
47
|
-
elif subcategories is not None:
|
|
48
|
-
print(json.dumps(subcategories, indent=4))
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if __name__ == "__main__":
|
|
52
|
-
sys.exit(main())
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/endpoints/advanced_search.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake/miscellaneous/search_watch.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/common/base_script.py
RENAMED
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/helper_scripts/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/helper_scripts/utils.py
RENAMED
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/__init__.py
RENAMED
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/add_comments.py
RENAMED
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/add_tags.py
RENAMED
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/add_threats.py
RENAMED
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/advanced_search.py
RENAMED
|
File without changes
|
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/edit_score.py
RENAMED
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/get_atom_values.py
RENAMED
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/get_query_hash.py
RENAMED
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/get_threats.py
RENAMED
|
File without changes
|
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/lookup_threats.py
RENAMED
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts/scripts/search_watch.py
RENAMED
|
File without changes
|
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts.egg-info/entry_points.txt
RENAMED
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts.egg-info/requires.txt
RENAMED
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/datalake_scripts.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{datalake_scripts-3.0.0rc1 → datalake_scripts-3.0.0rc3}/tests/scripts/test_add_new_threats.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|