From 140a27e1d2e48ecc2e2a140222a44f72259d4e62 Mon Sep 17 00:00:00 2001 From: Mickael BRUNEL Date: Thu, 15 Dec 2022 12:32:46 +0100 Subject: [PATCH 1/4] Download an attachment from an observable Add a method to download an attachment from the observableendpoint class and be able to retrieve a file from a given observable. The download can also be done with a zip and the parameter as_zip. --- thehive4py/endpoints/observable.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/thehive4py/endpoints/observable.py b/thehive4py/endpoints/observable.py index 8a510881..9b4dee70 100644 --- a/thehive4py/endpoints/observable.py +++ b/thehive4py/endpoints/observable.py @@ -111,3 +111,13 @@ def count(self, filters: Optional[FilterExpr] = None) -> int: params={"name": "observable.count"}, json={"query": query}, ) + + def download_attachment( + self, observable_id: str, attachment_id: str, attachment_path: str, as_zip: bool = False + ) -> None: + return self._session.make_request( + "GET", + path=f"/api/v1/observable/{observable_id}/attachment/{attachment_id}/download", + params={"asZip": as_zip}, + download_path=attachment_path, + ) From 7e5e54b1b90145dacd8a21d962927d88186f3214 Mon Sep 17 00:00:00 2001 From: Mickael BRUNEL Date: Wed, 21 Dec 2022 09:25:04 +0100 Subject: [PATCH 2/4] Rename attachment_path to observable_path Renaming of the variable attachment_path to observable_path to be better align with the existing name conventions. --- thehive4py/endpoints/observable.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thehive4py/endpoints/observable.py b/thehive4py/endpoints/observable.py index 9b4dee70..9a6514d4 100644 --- a/thehive4py/endpoints/observable.py +++ b/thehive4py/endpoints/observable.py @@ -113,11 +113,11 @@ def count(self, filters: Optional[FilterExpr] = None) -> int: ) def download_attachment( - self, observable_id: str, attachment_id: str, attachment_path: str, as_zip: bool = False + self, observable_id: str, attachment_id: str, observable_path: str, as_zip: bool = False ) -> None: return self._session.make_request( "GET", path=f"/api/v1/observable/{observable_id}/attachment/{attachment_id}/download", params={"asZip": as_zip}, - download_path=attachment_path, + download_path=observable_path, ) From 737371ff394ef94df7da17a27721097973de2513 Mon Sep 17 00:00:00 2001 From: Mickael BRUNEL Date: Thu, 5 Jan 2023 13:05:48 +0100 Subject: [PATCH 3/4] Lint code for check validation Reindent code in order to have lines that have less than 88 characters in order to pass the CI check --- thehive4py/endpoints/observable.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/thehive4py/endpoints/observable.py b/thehive4py/endpoints/observable.py index 9a6514d4..61b31cdb 100644 --- a/thehive4py/endpoints/observable.py +++ b/thehive4py/endpoints/observable.py @@ -113,11 +113,16 @@ def count(self, filters: Optional[FilterExpr] = None) -> int: ) def download_attachment( - self, observable_id: str, attachment_id: str, observable_path: str, as_zip: bool = False + self, + observable_id: str, + attachment_id: str, + observable_path: str, + as_zip: bool = False ) -> None: return self._session.make_request( "GET", - path=f"/api/v1/observable/{observable_id}/attachment/{attachment_id}/download", + path=(f"/api/v1/observable/{observable_id} + f"/attachment/{attachment_id}/download"), params={"asZip": as_zip}, download_path=observable_path, ) From 2dfe0e1addfdd9b2f788f924074e5e54c5ab14b9 Mon Sep 17 00:00:00 2001 From: Mickael BRUNEL Date: Tue, 10 Jan 2023 10:36:24 +0100 Subject: [PATCH 4/4] Fix flake8 and typo Remove space and add a double quote in order to fix flake8 and validate CI --- thehive4py/endpoints/observable.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/thehive4py/endpoints/observable.py b/thehive4py/endpoints/observable.py index 61b31cdb..2141a20e 100644 --- a/thehive4py/endpoints/observable.py +++ b/thehive4py/endpoints/observable.py @@ -113,15 +113,15 @@ def count(self, filters: Optional[FilterExpr] = None) -> int: ) def download_attachment( - self, - observable_id: str, - attachment_id: str, - observable_path: str, + self, + observable_id: str, + attachment_id: str, + observable_path: str, as_zip: bool = False ) -> None: return self._session.make_request( "GET", - path=(f"/api/v1/observable/{observable_id} + path=(f"/api/v1/observable/{observable_id}" f"/attachment/{attachment_id}/download"), params={"asZip": as_zip}, download_path=observable_path,