Skip to content

Commit 1a5ff68

Browse files
authored
Merge pull request #248 from intelowlproject/develop
5.0.0
2 parents d8df8ec + 6c32281 commit 1a5ff68

File tree

7 files changed

+32
-62
lines changed

7 files changed

+32
-62
lines changed

Diff for: .github/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## [5.0.0](https://github.com/intelowlproject/pyintelowl/releases/tag/5.0.0)
4+
- Fixes for Playbook Analysis
5+
36
## [4.4.7](https://github.com/intelowlproject/pyintelowl/releases/tag/4.4.7)
47
- Fixed Running Playbook without TLP set
58

Diff for: docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import os
1414
import sys
1515

16-
VERSION = "4.4.7"
16+
VERSION = "5.0.0"
1717
GITHUB_URL = "https://github.com/intelowlproject/pyintelowl"
1818

1919
sys.path.append(os.path.abspath("../"))

Diff for: pyintelowl/cli/_jobs_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def _render_job_reports_table(rows, title: str, verbose=False):
5959
]
6060
if verbose:
6161
for field in ["report", "errors", "runtime_configuration"]:
62-
cols.append(get_json_syntax(el[field]) if el[field] else None)
62+
cols.append(get_json_syntax(el[field]) if el.get(field, "") else None)
6363
table.add_row(*cols)
6464
return table
6565

Diff for: pyintelowl/cli/analyse.py

+10-27
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,8 @@
8080
# doing it twice to remove --analyzers-list and --connectors-list
8181
__playbook_analyse_options.pop(0)
8282
__playbook_analyse_options.pop(0)
83-
84-
__playbook_analyse_options.append(
85-
click.option(
86-
"-pl",
87-
"--playbooks-list",
88-
type=str,
89-
default="",
90-
help="""
91-
Comma separated list of playbook names to invoke.
92-
Defaults to all configured playbooks.
93-
""",
94-
),
95-
)
83+
__playbook_analyse_options.pop(3)
84+
__playbook_analyse_options.pop(2)
9685

9786

9887
@click.group("analyse")
@@ -184,57 +173,53 @@ def file(
184173

185174
@analyse.command(help="Send playbook analysis request for an observable")
186175
@click.argument("value")
176+
@click.argument("playbook")
187177
@add_options(__playbook_analyse_options)
188178
@click.pass_context
189179
def playbook_observable(
190180
ctx: ClickContext,
191181
value: str,
192-
playbooks_list: str,
182+
playbook: str,
193183
tags_list: str,
194184
tlp: str,
195-
check,
196-
check_minutes_ago: int,
197185
runtime_config,
198186
should_poll: bool,
199187
):
200-
playbooks_list = playbooks_list.split(",") if len(playbooks_list) else []
201188
tags_labels = tags_list.split(",") if len(tags_list) else []
202189
if runtime_config:
203190
runtime_config = get_json_data(runtime_config)
204191
else:
205192
runtime_config = {}
206193
try:
194+
print("here")
207195
ctx.obj._new_analysis_playbook_cli(
208196
value,
209197
"observable",
210-
check,
198+
playbook,
211199
tlp,
212-
playbooks_list,
213200
runtime_config,
214201
tags_labels,
215202
should_poll,
216-
check_minutes_ago,
217203
)
204+
print("here3")
218205
except IntelOwlClientException as e:
219206
ctx.obj.logger.fatal(str(e))
220207

221208

222209
@analyse.command(help="Send playbook analysis request for an observable")
223210
@click.argument("filepath", type=click.Path(exists=True, resolve_path=True))
211+
@click.argument("playbook")
224212
@add_options(__playbook_analyse_options)
225213
@click.pass_context
226214
def playbook_file(
227215
ctx: ClickContext,
228216
filepath: str,
229-
playbooks_list: str,
217+
playbook: str,
230218
tags_list: str,
231219
tlp: str,
232-
check,
233-
check_minutes_ago: int,
234220
runtime_config,
235221
should_poll: bool,
236222
):
237-
playbooks_list = playbooks_list.split(",") if len(playbooks_list) else []
238223
tags_labels = tags_list.split(",") if len(tags_list) else []
239224
if runtime_config:
240225
runtime_config = get_json_data(runtime_config)
@@ -244,13 +229,11 @@ def playbook_file(
244229
ctx.obj._new_analysis_playbook_cli(
245230
filepath,
246231
"file",
247-
check,
232+
playbook,
248233
tlp,
249-
playbooks_list,
250234
runtime_config,
251235
tags_labels,
252236
should_poll,
253-
check_minutes_ago,
254237
)
255238
except IntelOwlClientException as e:
256239
ctx.obj.logger.fatal(str(e))

Diff for: pyintelowl/pyintelowl.py

+12-28
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ def send_file_analysis_playbook_request(
213213
self,
214214
filename: str,
215215
binary: bytes,
216-
tlp: TLPType = None,
217-
playbooks_requested: List[str] = None,
216+
playbook_requested: str,
217+
tlp: TLPType = "CLEAR",
218218
runtime_configuration: Dict = None,
219219
tags_labels: List[str] = None,
220220
) -> Dict:
@@ -227,9 +227,7 @@ def send_file_analysis_playbook_request(
227227
Filename
228228
binary (bytes):
229229
File contents as bytes
230-
playbooks_requested (List[str], optional):
231-
List of specific playbooks to invoke.
232-
Defaults to ``[]`` i.e. all playbooks.
230+
playbook_requested (str, optional):
233231
tlp (str, optional):
234232
TLP for the analysis.
235233
(options: ``WHITE, GREEN, AMBER, RED``).
@@ -245,14 +243,12 @@ def send_file_analysis_playbook_request(
245243
Dict: JSON body
246244
"""
247245
try:
248-
if not playbooks_requested:
249-
playbooks_requested = []
250246
if not tags_labels:
251247
tags_labels = []
252248
if not runtime_configuration:
253249
runtime_configuration = {}
254250
data = {
255-
"playbooks_requested": playbooks_requested,
251+
"playbook_requested": playbook_requested,
256252
"tags_labels": tags_labels,
257253
}
258254
# send this value only if populated,
@@ -357,8 +353,8 @@ def send_observable_analysis_request(
357353
def send_observable_analysis_playbook_request(
358354
self,
359355
observable_name: str,
360-
tlp: TLPType = None,
361-
playbooks_requested: List[str] = None,
356+
playbook_requested: str,
357+
tlp: TLPType = "CLEAR",
362358
runtime_configuration: Dict = None,
363359
tags_labels: List[str] = None,
364360
observable_classification: str = None,
@@ -369,9 +365,7 @@ def send_observable_analysis_playbook_request(
369365
Args:
370366
observable_name (str):
371367
Observable value
372-
playbooks_requested (List[str], optional):
373-
List of specific playbooks to invoke.
374-
Defaults to ``[]`` i.e. all playbooks.
368+
playbook_requested str:
375369
tlp (str, optional):
376370
TLP for the analysis.
377371
(options: ``WHITE, GREEN, AMBER, RED``).
@@ -392,8 +386,6 @@ def send_observable_analysis_playbook_request(
392386
Dict: JSON body
393387
"""
394388
try:
395-
if not playbooks_requested:
396-
playbooks_requested = []
397389
if not tags_labels:
398390
tags_labels = []
399391
if not runtime_configuration:
@@ -415,7 +407,7 @@ def send_observable_analysis_playbook_request(
415407
)
416408
data = {
417409
"observables": [[observable_classification, observable_name]],
418-
"playbooks_requested": playbooks_requested,
410+
"playbook_requested": playbook_requested,
419411
"tags_labels": tags_labels,
420412
"runtime_configuration": runtime_configuration,
421413
}
@@ -777,32 +769,24 @@ def _new_analysis_playbook_cli(
777769
self,
778770
obj: str,
779771
type_: str,
780-
check,
772+
playbook: str,
781773
tlp: TLPType = None,
782-
playbooks_list: List[str] = None,
783774
runtime_configuration: Dict = None,
784775
tags_labels: List[str] = None,
785776
should_poll: bool = False,
786-
minutes_ago: int = None,
787777
) -> None:
788778
"""
789779
For internal use by the pyintelowl CLI.
790780
"""
791-
if not playbooks_list:
792-
playbooks_list = []
793781
if not runtime_configuration:
794782
runtime_configuration = {}
795783
if not tags_labels:
796784
tags_labels = []
797785

798-
if len(playbooks_list) == 0:
799-
print(("No Playbooks selected!\n"))
800-
return
801-
802786
self.logger.info(
803787
f"""Requesting analysis..
804788
{type_}: [blue]{obj}[/]
805-
playbooks: [i green]{playbooks_list}[/]
789+
playbook: [i green]{playbook}[/]
806790
tags: [i green]{tags_labels}[/]
807791
"""
808792
)
@@ -811,8 +795,8 @@ def _new_analysis_playbook_cli(
811795
if type_ == "observable":
812796
resp = self.send_observable_analysis_playbook_request(
813797
observable_name=obj,
798+
playbook_requested=playbook,
814799
tlp=tlp,
815-
playbooks_requested=playbooks_list,
816800
runtime_configuration=runtime_configuration,
817801
tags_labels=tags_labels,
818802
)
@@ -821,8 +805,8 @@ def _new_analysis_playbook_cli(
821805
resp = self.send_file_analysis_playbook_request(
822806
filename=path.name,
823807
binary=path.read_bytes(),
808+
playbook_requested=playbook,
824809
tlp=tlp,
825-
playbooks_requested=playbooks_list,
826810
runtime_configuration=runtime_configuration,
827811
tags_labels=tags_labels,
828812
)

Diff for: pyintelowl/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "4.4.7"
1+
__version__ = "5.0.0"

Diff for: tests/test_general.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ def test_send_file_analysis_request_failure(self, mocked_requests):
185185
def test_send_observable_playbook_analysis_request(self, mocked_requests):
186186
observable_name = self.domain
187187
runtime_config = {"test_key": "test_param"}
188-
playbooks_requested = ["TEST_PLAYBOOK"]
188+
playbook_requested = "TEST_PLAYBOOK"
189189
result = self.client.send_observable_analysis_playbook_request(
190190
observable_name,
191-
playbooks_requested=playbooks_requested,
191+
playbook_requested=playbook_requested,
192192
runtime_configuration=runtime_config,
193193
)
194194

@@ -202,14 +202,14 @@ def test_send_observable_playbook_analysis_request(self, mocked_requests):
202202
)
203203
)
204204
def test_send_file_playbook_analysis_request(self, mocked_requests):
205-
playbooks_requested = ["TEST_PLAYBOOK"]
205+
playbook_requested = "TEST_PLAYBOOK"
206206
filename = self.filepath
207207
binary = get_file_data(self.filepath)
208208
runtime_config = {"test_key": "test_param"}
209209
result = self.client.send_file_analysis_playbook_request(
210210
filename,
211211
binary,
212-
playbooks_requested=playbooks_requested,
212+
playbook_requested=playbook_requested,
213213
runtime_configuration=runtime_config,
214214
)
215215

0 commit comments

Comments
 (0)