1515
1616
1717class ObservableEndpoint (EndpointBase ):
18- def create_in_alert (
18+ def create_in_case (
1919 self ,
20- alert_id : str ,
20+ case_id : str ,
2121 observable : InputObservable ,
2222 observable_path : Optional [str ] = None ,
2323 ) -> List [OutputObservable ]:
24+ """Create one or more observables in a case.
25+
26+ Args:
27+ case_id: The id of the case.
28+ observable: The fields of the observable to create.
29+ observable_path: Optional path in case of file based observables.
30+
31+ Returns:
32+ The created case observables.
33+ """
2434 kwargs = self ._build_observable_kwargs (
2535 observable = observable , observable_path = observable_path
2636 )
2737 return self ._session .make_request (
28- "POST" , path = f"/api/v1/alert/ { alert_id } /observable" , ** kwargs
38+ "POST" , path = f"/api/v1/case/ { case_id } /observable" , ** kwargs
2939 )
3040
31- def create_in_case (
41+ def create_in_alert (
3242 self ,
33- case_id : str ,
43+ alert_id : str ,
3444 observable : InputObservable ,
3545 observable_path : Optional [str ] = None ,
3646 ) -> List [OutputObservable ]:
47+ """Create one or more observables in an alert.
48+
49+ Args:
50+ alert_id: The id of the alert.
51+ observable: The fields of the observable to create.
52+ observable_path: Optional path in case of file based observables.
53+
54+ Returns:
55+ The created alert observables.
56+ """
3757 kwargs = self ._build_observable_kwargs (
3858 observable = observable , observable_path = observable_path
3959 )
4060 return self ._session .make_request (
41- "POST" , path = f"/api/v1/case/ { case_id } /observable" , ** kwargs
61+ "POST" , path = f"/api/v1/alert/ { alert_id } /observable" , ** kwargs
4262 )
4363
4464 def get (self , observable_id : str ) -> OutputObservable :
65+ """Get an observable by id.
66+
67+ Args:
68+ observable_id: The id of the observable.
69+
70+ Returns:
71+ The observable specified by the id.
72+ """
4573 return self ._session .make_request (
4674 "GET" , path = f"/api/v1/observable/{ observable_id } "
4775 )
4876
4977 def delete (self , observable_id : str ) -> None :
78+ """Delete an observable.
79+
80+ Args:
81+ observable_id: The id of the observable.
82+
83+ Returns:
84+ N/A
85+ """
5086 return self ._session .make_request (
5187 "DELETE" , path = f"/api/v1/observable/{ observable_id } "
5288 )
5389
5490 def update (self , observable_id : str , fields : InputUpdateObservable ) -> None :
91+ """Update an observable.
92+
93+ Args:
94+ observable_id: The id of the observable.
95+ fields: The fields of the observable to update.
96+
97+ Returns:
98+ N/A
99+ """
55100 return self ._session .make_request (
56101 "PATCH" , path = f"/api/v1/observable/{ observable_id } " , json = fields
57102 )
58103
59104 def bulk_update (self , fields : InputBulkUpdateObservable ) -> None :
105+ """Update multiple observables with the same values.
106+
107+ Args:
108+ fields: The ids and the fields of the observables to update.
109+
110+ Returns:
111+ N/A
112+ """
60113 return self ._session .make_request (
61114 "PATCH" , path = "/api/v1/observable/_bulk" , json = fields
62115 )
63116
117+ def download_attachment (
118+ self ,
119+ observable_id : str ,
120+ attachment_id : str ,
121+ observable_path : str ,
122+ as_zip : bool = False ,
123+ ) -> None :
124+ """Download an observable attachment.
125+
126+ Args:
127+ observable_id: The id of the observable.
128+ attachment_id: The id of the observable attachment.
129+ observable_path: The local path to download the observable attachment to.
130+ as_zip: If `True`, the attachment will be sent as a zip file with a
131+ password. Default password is 'malware'
132+
133+ Returns:
134+ N/A
135+ """
136+ return self ._session .make_request (
137+ "GET" ,
138+ path = (
139+ f"/api/v1/observable/{ observable_id } "
140+ f"/attachment/{ attachment_id } /download"
141+ ),
142+ params = {"asZip" : as_zip },
143+ download_path = observable_path ,
144+ )
145+
146+ def list_shares (self , observable_id : str ) -> List [OutputShare ]:
147+ """List all organisation shares of an observable.
148+
149+ Args:
150+ observable_id: The id of the observable.
151+
152+ Returns:
153+ The list of organisation shares of the observable.
154+ """
155+ return self ._session .make_request (
156+ "GET" , path = f"/api/v1/case/{ observable_id } /shares"
157+ )
158+
64159 def share (self , observable_id : str , organisations : List [str ]) -> None :
160+ """Share the observable with other organisations.
161+
162+ The case that owns the observable must already be shared with the target
163+ organisations.
164+
165+ Args:
166+ observable_id: The id of the observable.
167+ organisations: The list of organisation names or ids.
168+
169+ Returns:
170+ The list of organisation shares of the observable.
171+ """
65172 return self ._session .make_request (
66173 "POST" ,
67174 path = f"/api/v1/observable/{ observable_id } /shares" ,
68175 json = {"organisations" : organisations },
69176 )
70177
71178 def unshare (self , observable_id : str , organisations : List [str ]) -> None :
179+ """Unshare an observable from other organisations.
180+
181+ Args:
182+ observable_id: The id of the observable.
183+ organisations: The list of organisation names or ids.
184+
185+ Returns:
186+ N/A
187+ """
72188 return self ._session .make_request (
73189 "DELETE" ,
74190 path = f"/api/v1/observable/{ observable_id } /shares" ,
75191 json = {"organisations" : organisations },
76192 )
77193
78- def list_shares (self , observable_id : str ) -> List [OutputShare ]:
79- return self ._session .make_request (
80- "GET" , path = f"/api/v1/case/{ observable_id } /shares"
81- )
82-
83194 def find (
84195 self ,
85196 filters : Optional [FilterExpr ] = None ,
86197 sortby : Optional [SortExpr ] = None ,
87198 paginate : Optional [Paginate ] = None ,
88199 ) -> List [OutputObservable ]:
200+ """Find multiple observables.
201+
202+ Args:
203+ filters: The filter expressions to apply in the query.
204+ sortby: The sort expressions to apply in the query.
205+ paginate: The pagination experssion to apply in the query.
206+
207+ Returns:
208+ The list of observables matched by the query or an empty list.
209+ """
89210 query : QueryExpr = [
90211 {"_name" : "listObservable" },
91212 * self ._build_subquery (filters = filters , sortby = sortby , paginate = paginate ),
@@ -99,6 +220,14 @@ def find(
99220 )
100221
101222 def count (self , filters : Optional [FilterExpr ] = None ) -> int :
223+ """Count observables.
224+
225+ Args:
226+ filters: The filter expressions to apply in the query.
227+
228+ Returns:
229+ The count of observables matched by the query.
230+ """
102231 query : QueryExpr = [
103232 {"_name" : "listObservable" },
104233 * self ._build_subquery (filters = filters ),
@@ -111,20 +240,3 @@ def count(self, filters: Optional[FilterExpr] = None) -> int:
111240 params = {"name" : "observable.count" },
112241 json = {"query" : query },
113242 )
114-
115- def download_attachment (
116- self ,
117- observable_id : str ,
118- attachment_id : str ,
119- observable_path : str ,
120- as_zip = False ,
121- ) -> None :
122- return self ._session .make_request (
123- "GET" ,
124- path = (
125- f"/api/v1/observable/{ observable_id } "
126- f"/attachment/{ attachment_id } /download"
127- ),
128- params = {"asZip" : as_zip },
129- download_path = observable_path ,
130- )
0 commit comments