@cryptotaxi247 / CoPilot / commits / e0e7af0c

Create assets.py

taylor_socfortress committed Jul 10, 2023 at 16:42 UTC e0e7af0ca6648e23ddf8a0beee7ffabaf5e8c7db
1 file changed +47
backend/app/services/DFIR_IRIS/assets.py new
+47
@@ -0,0 +1,47 @@
1 +from typing import Dict
2 +import requests
3 +from loguru import logger
4 +from app.services.DFIR_IRIS.universal import UniversalService
5 +from dfir_iris_client.case import Case
6 +from dfir_iris_client.helper.utils import assert_api_resp
7 +from dfir_iris_client.helper.utils import get_data_from_resp
8 +from dfir_iris_client.session import ClientSession
9 +
10 +
11 +class AssetsService:
12 + """
13 + A service class that encapsulates the logic for pulling case assets from DFIR-IRIS.
14 + """
15 +
16 + def __init__(self):
17 + self.universal_service = UniversalService("DFIR-IRIS")
18 + session_result = self.universal_service.create_session()
19 +
20 + if not session_result['success']:
21 + logger.error(session_result['message'])
22 + self.iris_session = None
23 + else:
24 + self.iris_session = session_result['session']
25 +
26 + def get_case_assets(self, cid: int) -> Dict[str, object]:
27 + """
28 + Gets a case's assets from DFIR-IRIS
29 +
30 + ARGS:
31 + cid: The case ID to search for
32 +
33 + Returns:
34 + dict: A dictionary containing the success status, a message and potentially the notes of a given case.
35 + """
36 + if self.iris_session is None:
37 + return {"success": False, "message": "DFIR-IRIS session was not successfully created."}
38 +
39 + logger.info(f"Collecting case {cid} assets from DFIR-IRIS")
40 + case = Case(session=self.iris_session)
41 + result = self.universal_service.fetch_and_parse_data(self.iris_session, case.list_assets, cid)
42 +
43 + if not result["success"]:
44 + return {"success": False, "message": "Failed to collect notes from DFIR-IRIS"}
45 +
46 + return result
47 +