misp_client_rs/apis/
event_report_api.rs

1//!
2//! MISP Automation API
3//!
4//!  ### Getting Started  MISP API allows you to query, create, modify data models, such as [Events](https://www.circl.lu/doc/misp/GLOSSARY.html#misp-event), [Objects](https://www.circl.lu/doc/misp/misp-objects/), [Attributes](https://www.circl.lu/doc/misp/GLOSSARY.html#misp-attribute). This is extremly useful for interconnecting MISP with external tools and feeding other systems with threat intel data.  It also lets you perform administrative tasks such as creating users, organisations, altering MISP settings, and much more.  To get an API key there are several options: * **[UI]** Go to [My Profile -> Auth Keys](/auth_keys/index) section and click on `+ Add authentication key`  * **[UI]** As an admin go to the the [Administration -> List Users -> View](/admin/users/view/[id]) page of the user you want to create an auth key for and on the `Auth keys` section click on `+ Add authentication key`  * **[CLI]** Use the following command: `./app/Console/cake user change_authkey [e-mail/user_id]`  * **API** Provided you already have an admin level API key, you can create an API key for another user using the `[POST]/auth_keys/add/{{user_id}}` endpoint.  > **NOTE:** The authentication key will only be displayed once, so take note of it or store it properly in your application secrets.  #### Accept and Content-Type headers  When performing your request, depending on the type of request, you might need to explicitly specify in what content  type you want to get your results. This is done by setting one of the below `Accept` headers:      Accept: application/json     Accept: application/xml  When submitting data in a `POST`, `PUT` or `DELETE` operation you also need to specify in what content-type you encoded the payload.  This is done by setting one of the below `Content-Type` headers:      Content-Type: application/json     Content-Type: application/xml  Example: ``` curl  --header \"Authorization: YOUR_API_KEY\" \\       --header \"Accept: application/json\" \\       --header \"Content-Type: application/json\" https://<misp url>/  ```  > **NOTE**: By appending .json or .xml the content type can also be set without the need for a header.  #### Automation using PyMISP  [PyMISP](https://github.com/MISP/PyMISP) is a Python library to access MISP platforms via their REST [API](https://www.circl.lu/doc/misp/GLOSSARY.html#api). It allows you to fetch events, add or update events/attributes, add or update samples or search for attributes.  ### FAQ * [Dev FAQ](https://www.circl.lu/doc/misp/dev-faq/) * [GitHub project FAQ](https://github.com/MISP/MISP/wiki/Frequently-Asked-Questions) 
5//!
6//! The version of the OpenAPI document: 2.4
7//! 
8//! Generated by: https://openapi-generator.tech
9//! 
10
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`add_event_report`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddEventReportError {
22    Status403(models::UnauthorizedApiError),
23    DefaultResponse(models::ApiError),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`delete_event_report`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum DeleteEventReportError {
31    Status403(models::UnauthorizedApiError),
32    DefaultResponse(models::ApiError),
33    UnknownValue(serde_json::Value),
34}
35
36/// struct for typed errors of method [`edit_event_report`]
37#[derive(Debug, Clone, Serialize, Deserialize)]
38#[serde(untagged)]
39pub enum EditEventReportError {
40    Status403(models::UnauthorizedApiError),
41    DefaultResponse(models::ApiError),
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`hard_delete_event_report`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum HardDeleteEventReportError {
49    Status403(models::UnauthorizedApiError),
50    DefaultResponse(models::ApiError),
51    UnknownValue(serde_json::Value),
52}
53
54/// struct for typed errors of method [`import_from_url_event_report`]
55#[derive(Debug, Clone, Serialize, Deserialize)]
56#[serde(untagged)]
57pub enum ImportFromUrlEventReportError {
58    Status403(models::UnauthorizedApiError),
59    DefaultResponse(models::ApiError),
60    UnknownValue(serde_json::Value),
61}
62
63/// struct for typed errors of method [`index_event_report`]
64#[derive(Debug, Clone, Serialize, Deserialize)]
65#[serde(untagged)]
66pub enum IndexEventReportError {
67    Status403(models::UnauthorizedApiError),
68    DefaultResponse(models::ApiError),
69    UnknownValue(serde_json::Value),
70}
71
72/// struct for typed errors of method [`restore_event_report`]
73#[derive(Debug, Clone, Serialize, Deserialize)]
74#[serde(untagged)]
75pub enum RestoreEventReportError {
76    Status403(models::UnauthorizedApiError),
77    DefaultResponse(models::ApiError),
78    UnknownValue(serde_json::Value),
79}
80
81/// struct for typed errors of method [`view_event_report`]
82#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(untagged)]
84pub enum ViewEventReportError {
85    Status403(models::UnauthorizedApiError),
86    DefaultResponse(models::ApiError),
87    UnknownValue(serde_json::Value),
88}
89
90
91pub async fn add_event_report(configuration: &configuration::Configuration, event_id: &str, event_report_no_id: models::EventReportNoId) -> Result<models::ViewEventReport200Response, Error<AddEventReportError>> {
92    // add a prefix to parameters to efficiently prevent name collisions
93    let p_event_id = event_id;
94    let p_event_report_no_id = event_report_no_id;
95
96    let uri_str = format!("{}/eventReports/add/{eventId}", configuration.base_path, eventId=p_event_id.to_string());
97    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
98
99    if let Some(ref user_agent) = configuration.user_agent {
100        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
101    }
102    if let Some(ref apikey) = configuration.api_key {
103        let key = apikey.key.clone();
104        let value = match apikey.prefix {
105            Some(ref prefix) => format!("{} {}", prefix, key),
106            None => key,
107        };
108        req_builder = req_builder.header("Authorization", value);
109    };
110    req_builder = req_builder.json(&p_event_report_no_id);
111
112    let req = req_builder.build()?;
113    let resp = configuration.client.execute(req).await?;
114
115    let status = resp.status();
116    let content_type = resp
117        .headers()
118        .get("content-type")
119        .and_then(|v| v.to_str().ok())
120        .unwrap_or("application/octet-stream");
121    let content_type = super::ContentType::from(content_type);
122
123    if !status.is_client_error() && !status.is_server_error() {
124        let content = resp.text().await?;
125        match content_type {
126            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
127            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ViewEventReport200Response`"))),
128            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ViewEventReport200Response`")))),
129        }
130    } else {
131        let content = resp.text().await?;
132        let entity: Option<AddEventReportError> = serde_json::from_str(&content).ok();
133        Err(Error::ResponseError(ResponseContent { status, content, entity }))
134    }
135}
136
137pub async fn delete_event_report(configuration: &configuration::Configuration, event_report_id: &str) -> Result<models::DeleteEventReport200Response, Error<DeleteEventReportError>> {
138    // add a prefix to parameters to efficiently prevent name collisions
139    let p_event_report_id = event_report_id;
140
141    let uri_str = format!("{}/eventReports/delete/{eventReportId}", configuration.base_path, eventReportId=p_event_report_id.to_string());
142    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
143
144    if let Some(ref user_agent) = configuration.user_agent {
145        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
146    }
147    if let Some(ref apikey) = configuration.api_key {
148        let key = apikey.key.clone();
149        let value = match apikey.prefix {
150            Some(ref prefix) => format!("{} {}", prefix, key),
151            None => key,
152        };
153        req_builder = req_builder.header("Authorization", value);
154    };
155
156    let req = req_builder.build()?;
157    let resp = configuration.client.execute(req).await?;
158
159    let status = resp.status();
160    let content_type = resp
161        .headers()
162        .get("content-type")
163        .and_then(|v| v.to_str().ok())
164        .unwrap_or("application/octet-stream");
165    let content_type = super::ContentType::from(content_type);
166
167    if !status.is_client_error() && !status.is_server_error() {
168        let content = resp.text().await?;
169        match content_type {
170            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
171            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteEventReport200Response`"))),
172            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DeleteEventReport200Response`")))),
173        }
174    } else {
175        let content = resp.text().await?;
176        let entity: Option<DeleteEventReportError> = serde_json::from_str(&content).ok();
177        Err(Error::ResponseError(ResponseContent { status, content, entity }))
178    }
179}
180
181pub async fn edit_event_report(configuration: &configuration::Configuration, event_report_id: &str) -> Result<models::ViewEventReport200Response, Error<EditEventReportError>> {
182    // add a prefix to parameters to efficiently prevent name collisions
183    let p_event_report_id = event_report_id;
184
185    let uri_str = format!("{}/eventReports/edit/{eventReportId}", configuration.base_path, eventReportId=p_event_report_id.to_string());
186    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
187
188    if let Some(ref user_agent) = configuration.user_agent {
189        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
190    }
191    if let Some(ref apikey) = configuration.api_key {
192        let key = apikey.key.clone();
193        let value = match apikey.prefix {
194            Some(ref prefix) => format!("{} {}", prefix, key),
195            None => key,
196        };
197        req_builder = req_builder.header("Authorization", value);
198    };
199
200    let req = req_builder.build()?;
201    let resp = configuration.client.execute(req).await?;
202
203    let status = resp.status();
204    let content_type = resp
205        .headers()
206        .get("content-type")
207        .and_then(|v| v.to_str().ok())
208        .unwrap_or("application/octet-stream");
209    let content_type = super::ContentType::from(content_type);
210
211    if !status.is_client_error() && !status.is_server_error() {
212        let content = resp.text().await?;
213        match content_type {
214            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
215            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ViewEventReport200Response`"))),
216            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ViewEventReport200Response`")))),
217        }
218    } else {
219        let content = resp.text().await?;
220        let entity: Option<EditEventReportError> = serde_json::from_str(&content).ok();
221        Err(Error::ResponseError(ResponseContent { status, content, entity }))
222    }
223}
224
225pub async fn hard_delete_event_report(configuration: &configuration::Configuration, event_report_id: &str, hard_delete: &str) -> Result<models::DeleteEventReport200Response, Error<HardDeleteEventReportError>> {
226    // add a prefix to parameters to efficiently prevent name collisions
227    let p_event_report_id = event_report_id;
228    let p_hard_delete = hard_delete;
229
230    let uri_str = format!("{}/eventReports/delete/{eventReportId}/{hardDelete}", configuration.base_path, eventReportId=p_event_report_id.to_string(), hardDelete=crate::apis::urlencode(p_hard_delete));
231    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
232
233    if let Some(ref user_agent) = configuration.user_agent {
234        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
235    }
236    if let Some(ref apikey) = configuration.api_key {
237        let key = apikey.key.clone();
238        let value = match apikey.prefix {
239            Some(ref prefix) => format!("{} {}", prefix, key),
240            None => key,
241        };
242        req_builder = req_builder.header("Authorization", value);
243    };
244
245    let req = req_builder.build()?;
246    let resp = configuration.client.execute(req).await?;
247
248    let status = resp.status();
249    let content_type = resp
250        .headers()
251        .get("content-type")
252        .and_then(|v| v.to_str().ok())
253        .unwrap_or("application/octet-stream");
254    let content_type = super::ContentType::from(content_type);
255
256    if !status.is_client_error() && !status.is_server_error() {
257        let content = resp.text().await?;
258        match content_type {
259            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
260            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteEventReport200Response`"))),
261            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DeleteEventReport200Response`")))),
262        }
263    } else {
264        let content = resp.text().await?;
265        let entity: Option<HardDeleteEventReportError> = serde_json::from_str(&content).ok();
266        Err(Error::ResponseError(ResponseContent { status, content, entity }))
267    }
268}
269
270pub async fn import_from_url_event_report(configuration: &configuration::Configuration, event_id: &str, import_from_url_event_report_request: models::ImportFromUrlEventReportRequest) -> Result<models::ImportFromUrlEventReport200Response, Error<ImportFromUrlEventReportError>> {
271    // add a prefix to parameters to efficiently prevent name collisions
272    let p_event_id = event_id;
273    let p_import_from_url_event_report_request = import_from_url_event_report_request;
274
275    let uri_str = format!("{}/eventReports/importReportFromUrl/{eventId}", configuration.base_path, eventId=p_event_id.to_string());
276    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
277
278    if let Some(ref user_agent) = configuration.user_agent {
279        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
280    }
281    if let Some(ref apikey) = configuration.api_key {
282        let key = apikey.key.clone();
283        let value = match apikey.prefix {
284            Some(ref prefix) => format!("{} {}", prefix, key),
285            None => key,
286        };
287        req_builder = req_builder.header("Authorization", value);
288    };
289    req_builder = req_builder.json(&p_import_from_url_event_report_request);
290
291    let req = req_builder.build()?;
292    let resp = configuration.client.execute(req).await?;
293
294    let status = resp.status();
295    let content_type = resp
296        .headers()
297        .get("content-type")
298        .and_then(|v| v.to_str().ok())
299        .unwrap_or("application/octet-stream");
300    let content_type = super::ContentType::from(content_type);
301
302    if !status.is_client_error() && !status.is_server_error() {
303        let content = resp.text().await?;
304        match content_type {
305            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
306            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ImportFromUrlEventReport200Response`"))),
307            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ImportFromUrlEventReport200Response`")))),
308        }
309    } else {
310        let content = resp.text().await?;
311        let entity: Option<ImportFromUrlEventReportError> = serde_json::from_str(&content).ok();
312        Err(Error::ResponseError(ResponseContent { status, content, entity }))
313    }
314}
315
316pub async fn index_event_report(configuration: &configuration::Configuration, ) -> Result<Vec<models::ViewEventReport200Response>, Error<IndexEventReportError>> {
317
318    let uri_str = format!("{}/eventReports/index", configuration.base_path);
319    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
320
321    if let Some(ref user_agent) = configuration.user_agent {
322        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
323    }
324    if let Some(ref apikey) = configuration.api_key {
325        let key = apikey.key.clone();
326        let value = match apikey.prefix {
327            Some(ref prefix) => format!("{} {}", prefix, key),
328            None => key,
329        };
330        req_builder = req_builder.header("Authorization", value);
331    };
332
333    let req = req_builder.build()?;
334    let resp = configuration.client.execute(req).await?;
335
336    let status = resp.status();
337    let content_type = resp
338        .headers()
339        .get("content-type")
340        .and_then(|v| v.to_str().ok())
341        .unwrap_or("application/octet-stream");
342    let content_type = super::ContentType::from(content_type);
343
344    if !status.is_client_error() && !status.is_server_error() {
345        let content = resp.text().await?;
346        match content_type {
347            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
348            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::ViewEventReport200Response&gt;`"))),
349            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::ViewEventReport200Response&gt;`")))),
350        }
351    } else {
352        let content = resp.text().await?;
353        let entity: Option<IndexEventReportError> = serde_json::from_str(&content).ok();
354        Err(Error::ResponseError(ResponseContent { status, content, entity }))
355    }
356}
357
358pub async fn restore_event_report(configuration: &configuration::Configuration, event_report_id: &str) -> Result<models::RestoreEventReport200Response, Error<RestoreEventReportError>> {
359    // add a prefix to parameters to efficiently prevent name collisions
360    let p_event_report_id = event_report_id;
361
362    let uri_str = format!("{}/eventReports/restore/{eventReportId}", configuration.base_path, eventReportId=p_event_report_id.to_string());
363    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
364
365    if let Some(ref user_agent) = configuration.user_agent {
366        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
367    }
368    if let Some(ref apikey) = configuration.api_key {
369        let key = apikey.key.clone();
370        let value = match apikey.prefix {
371            Some(ref prefix) => format!("{} {}", prefix, key),
372            None => key,
373        };
374        req_builder = req_builder.header("Authorization", value);
375    };
376
377    let req = req_builder.build()?;
378    let resp = configuration.client.execute(req).await?;
379
380    let status = resp.status();
381    let content_type = resp
382        .headers()
383        .get("content-type")
384        .and_then(|v| v.to_str().ok())
385        .unwrap_or("application/octet-stream");
386    let content_type = super::ContentType::from(content_type);
387
388    if !status.is_client_error() && !status.is_server_error() {
389        let content = resp.text().await?;
390        match content_type {
391            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
392            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RestoreEventReport200Response`"))),
393            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RestoreEventReport200Response`")))),
394        }
395    } else {
396        let content = resp.text().await?;
397        let entity: Option<RestoreEventReportError> = serde_json::from_str(&content).ok();
398        Err(Error::ResponseError(ResponseContent { status, content, entity }))
399    }
400}
401
402pub async fn view_event_report(configuration: &configuration::Configuration, event_report_id: &str) -> Result<models::ViewEventReport200Response, Error<ViewEventReportError>> {
403    // add a prefix to parameters to efficiently prevent name collisions
404    let p_event_report_id = event_report_id;
405
406    let uri_str = format!("{}/eventReports/view/{eventReportId}", configuration.base_path, eventReportId=p_event_report_id.to_string());
407    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
408
409    if let Some(ref user_agent) = configuration.user_agent {
410        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
411    }
412    if let Some(ref apikey) = configuration.api_key {
413        let key = apikey.key.clone();
414        let value = match apikey.prefix {
415            Some(ref prefix) => format!("{} {}", prefix, key),
416            None => key,
417        };
418        req_builder = req_builder.header("Authorization", value);
419    };
420
421    let req = req_builder.build()?;
422    let resp = configuration.client.execute(req).await?;
423
424    let status = resp.status();
425    let content_type = resp
426        .headers()
427        .get("content-type")
428        .and_then(|v| v.to_str().ok())
429        .unwrap_or("application/octet-stream");
430    let content_type = super::ContentType::from(content_type);
431
432    if !status.is_client_error() && !status.is_server_error() {
433        let content = resp.text().await?;
434        match content_type {
435            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
436            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ViewEventReport200Response`"))),
437            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ViewEventReport200Response`")))),
438        }
439    } else {
440        let content = resp.text().await?;
441        let entity: Option<ViewEventReportError> = serde_json::from_str(&content).ok();
442        Err(Error::ResponseError(ResponseContent { status, content, entity }))
443    }
444}
445