@@ -45,10 +45,26 @@ def unknown_type(self, stix_object):
4545 'Unknown object type "' + stix_object ["type" ] + '", doing nothing...' ,
4646 )
4747
48- def convert_markdown (self , text ):
48+ def convert_markdown (self , text ) -> str :
49+ """converts input text to markdown style code annotation
50+
51+ :param text: input text
52+ :type text: str
53+ :return: sanitized text with markdown style code annotation
54+ :rtype: str
55+ """
56+
4957 return text .replace ("<code>" , "`" ).replace ("</code>" , "`" )
5058
5159 def format_date (self , date ):
60+ """converts multiple input date formats to OpenCTI style dates
61+
62+ :param date: input date
63+ :type date:
64+ :return: OpenCTI style date
65+ :rtype: datetime
66+ """
67+
5268 if isinstance (date , datetime .date ):
5369 return date .isoformat (timespec = "milliseconds" ).replace ("+00:00" , "Z" )
5470 if date is not None :
@@ -64,15 +80,33 @@ def format_date(self, date):
6480 .replace ("+00:00" , "Z" )
6581 )
6682
67- def filter_objects (self , uuids , objects ):
83+ def filter_objects (self , uuids : list , objects : list ) -> list :
84+ """filters objects based on UUIDs
85+
86+ :param uuids: list of UUIDs
87+ :type uuids: list
88+ :param objects: list of objects to filter
89+ :type objects: list
90+ :return: list of filtered objects
91+ :rtype: list
92+ """
93+
6894 result = []
6995 if objects is not None :
70- for object in objects :
71- if "id" in object and object ["id" ] not in uuids :
72- result .append (object )
96+ for item in objects :
97+ if "id" in item and item ["id" ] not in uuids :
98+ result .append (item )
7399 return result
74100
75- def pick_aliases (self , stix_object ):
101+ def pick_aliases (self , stix_object ) -> list :
102+ """check stix2 object for multiple aliases and return a list
103+
104+ :param stix_object: valid stix2 object
105+ :type stix_object:
106+ :return: list of aliases
107+ :rtype: list
108+ """
109+
76110 # Add aliases
77111 if CustomProperties .ALIASES in stix_object :
78112 return stix_object [CustomProperties .ALIASES ]
@@ -85,8 +119,18 @@ def pick_aliases(self, stix_object):
85119 return None
86120
87121 def check_max_marking_definition (
88- self , max_marking_definition_entity , entity_marking_definitions
89- ):
122+ self , max_marking_definition_entity : str , entity_marking_definitions : list
123+ ) -> bool :
124+ """checks if a list of marking definitions conforms with a given max level
125+
126+ :param max_marking_definition_entity: the maximum allowed marking definition level
127+ :type max_marking_definition_entity: str, optional
128+ :param entity_marking_definitions: list of entities to check
129+ :type entity_marking_definitions: list
130+ :return: `True` if the list conforms with max marking definition
131+ :rtype: bool
132+ """
133+
90134 # Max is not set, return True
91135 if max_marking_definition_entity is None :
92136 return True
@@ -111,7 +155,19 @@ def check_max_marking_definition(
111155 return True
112156 return False
113157
114- def import_bundle_from_file (self , file_path , update = False , types = None ):
158+ def import_bundle_from_file (self , file_path : str , update = False , types = None ) -> List :
159+ """import a stix2 bundle from a file
160+
161+ :param file_path: valid path to the file
162+ :type file_path: str
163+ :param update: whether to updated data in the database, defaults to False
164+ :type update: bool, optional
165+ :param types: list of stix2 types, defaults to None
166+ :type types: list, optional
167+ :return: list of imported stix2 objects
168+ :rtype: List
169+ """
170+
115171 if types is None :
116172 types = []
117173 if not os .path .isfile (file_path ):
@@ -124,12 +180,34 @@ def import_bundle_from_file(self, file_path, update=False, types=None):
124180 return self .import_bundle (data , update , types )
125181
126182 def import_bundle_from_json (self , json_data , update = False , types = None ) -> List :
183+ """import a stix2 bundle from JSON data
184+
185+ :param json_data: JSON data
186+ :type json_data:
187+ :param update: whether to updated data in the database, defaults to False
188+ :type update: bool, optional
189+ :param types: list of stix2 types, defaults to None
190+ :type types: list, optional
191+ :return: list of imported stix2 objects
192+ :rtype: List
193+ """
194+
127195 if types is None :
128196 types = []
129197 data = json .loads (json_data )
130198 return self .import_bundle (data , update , types )
131199
132- def extract_embedded_relationships (self , stix_object , types = None ):
200+ def extract_embedded_relationships (self , stix_object , types = None ) -> dict :
201+ """extracts embedded relationship objects from a stix2 entity
202+
203+ :param stix_object: valid stix2 object
204+ :type stix_object:
205+ :param types: list of stix2 types, defaults to None
206+ :type types: list, optional
207+ :return: embedded relationships as dict
208+ :rtype: dict
209+ """
210+
133211 # Created By Ref
134212 created_by_ref_id = None
135213 if "created_by_ref" in stix_object :
@@ -381,7 +459,19 @@ def extract_embedded_relationships(self, stix_object, types=None):
381459 "reports" : reports ,
382460 }
383461
384- def import_object (self , stix_object , update = False , types = None ):
462+ def import_object (self , stix_object , update = False , types = None ) -> list :
463+ """import a stix2 object
464+
465+ :param stix_object: valid stix2 object
466+ :type stix_object:
467+ :param update: whether to updated data in the database, defaults to False
468+ :type update: bool, optional
469+ :param types: list of stix2 types, defaults to None
470+ :type types: list, optional
471+ :return: list of imported stix2 objects
472+ :rtype: list
473+ """
474+
385475 self .opencti .log (
386476 "info" ,
387477 "Importing a " + stix_object ["type" ] + " (id: " + stix_object ["id" ] + ")" ,
0 commit comments