misp_client_rs/apis/
warninglists_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 [`check_value_warninglists_matches`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CheckValueWarninglistsMatchesError {
22    Status403(models::UnauthorizedApiError),
23    Status404(models::NotFoundApiError),
24    DefaultResponse(models::ApiError),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`get_warninglist_by_id`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum GetWarninglistByIdError {
32    Status403(models::UnauthorizedApiError),
33    Status404(models::NotFoundApiError),
34    DefaultResponse(models::ApiError),
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`get_warninglists`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum GetWarninglistsError {
42    Status403(models::UnauthorizedApiError),
43    Status404(models::NotFoundApiError),
44    DefaultResponse(models::ApiError),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`search_warninglists`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum SearchWarninglistsError {
52    Status403(models::UnauthorizedApiError),
53    Status404(models::NotFoundApiError),
54    DefaultResponse(models::ApiError),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`toggle_enable_warninglist`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum ToggleEnableWarninglistError {
62    Status403(models::UnauthorizedApiError),
63    Status404(models::NotFoundApiError),
64    DefaultResponse(models::ApiError),
65    UnknownValue(serde_json::Value),
66}
67
68/// struct for typed errors of method [`update_warninglists`]
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum UpdateWarninglistsError {
72    Status403(models::UnauthorizedApiError),
73    Status404(models::NotFoundApiError),
74    DefaultResponse(models::ApiError),
75    UnknownValue(serde_json::Value),
76}
77
78
79pub async fn check_value_warninglists_matches(configuration: &configuration::Configuration, request_body: Option<Vec<String>>) -> Result<serde_json::Value, Error<CheckValueWarninglistsMatchesError>> {
80    // add a prefix to parameters to efficiently prevent name collisions
81    let p_request_body = request_body;
82
83    let uri_str = format!("{}/warninglists/checkValue", configuration.base_path);
84    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
85
86    if let Some(ref user_agent) = configuration.user_agent {
87        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
88    }
89    if let Some(ref apikey) = configuration.api_key {
90        let key = apikey.key.clone();
91        let value = match apikey.prefix {
92            Some(ref prefix) => format!("{} {}", prefix, key),
93            None => key,
94        };
95        req_builder = req_builder.header("Authorization", value);
96    };
97    req_builder = req_builder.json(&p_request_body);
98
99    let req = req_builder.build()?;
100    let resp = configuration.client.execute(req).await?;
101
102    let status = resp.status();
103    let content_type = resp
104        .headers()
105        .get("content-type")
106        .and_then(|v| v.to_str().ok())
107        .unwrap_or("application/octet-stream");
108    let content_type = super::ContentType::from(content_type);
109
110    if !status.is_client_error() && !status.is_server_error() {
111        let content = resp.text().await?;
112        match content_type {
113            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
114            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `serde_json::Value`"))),
115            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `serde_json::Value`")))),
116        }
117    } else {
118        let content = resp.text().await?;
119        let entity: Option<CheckValueWarninglistsMatchesError> = serde_json::from_str(&content).ok();
120        Err(Error::ResponseError(ResponseContent { status, content, entity }))
121    }
122}
123
124pub async fn get_warninglist_by_id(configuration: &configuration::Configuration, warninglist_id: &str) -> Result<models::GetWarninglists200ResponseWarninglistsInner, Error<GetWarninglistByIdError>> {
125    // add a prefix to parameters to efficiently prevent name collisions
126    let p_warninglist_id = warninglist_id;
127
128    let uri_str = format!("{}/warninglists/view/{warninglistId}", configuration.base_path, warninglistId=crate::apis::urlencode(p_warninglist_id));
129    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
130
131    if let Some(ref user_agent) = configuration.user_agent {
132        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
133    }
134    if let Some(ref apikey) = configuration.api_key {
135        let key = apikey.key.clone();
136        let value = match apikey.prefix {
137            Some(ref prefix) => format!("{} {}", prefix, key),
138            None => key,
139        };
140        req_builder = req_builder.header("Authorization", value);
141    };
142
143    let req = req_builder.build()?;
144    let resp = configuration.client.execute(req).await?;
145
146    let status = resp.status();
147    let content_type = resp
148        .headers()
149        .get("content-type")
150        .and_then(|v| v.to_str().ok())
151        .unwrap_or("application/octet-stream");
152    let content_type = super::ContentType::from(content_type);
153
154    if !status.is_client_error() && !status.is_server_error() {
155        let content = resp.text().await?;
156        match content_type {
157            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
158            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetWarninglists200ResponseWarninglistsInner`"))),
159            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::GetWarninglists200ResponseWarninglistsInner`")))),
160        }
161    } else {
162        let content = resp.text().await?;
163        let entity: Option<GetWarninglistByIdError> = serde_json::from_str(&content).ok();
164        Err(Error::ResponseError(ResponseContent { status, content, entity }))
165    }
166}
167
168pub async fn get_warninglists(configuration: &configuration::Configuration, ) -> Result<models::GetWarninglists200Response, Error<GetWarninglistsError>> {
169
170    let uri_str = format!("{}/warninglists", configuration.base_path);
171    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
172
173    if let Some(ref user_agent) = configuration.user_agent {
174        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
175    }
176    if let Some(ref apikey) = configuration.api_key {
177        let key = apikey.key.clone();
178        let value = match apikey.prefix {
179            Some(ref prefix) => format!("{} {}", prefix, key),
180            None => key,
181        };
182        req_builder = req_builder.header("Authorization", value);
183    };
184
185    let req = req_builder.build()?;
186    let resp = configuration.client.execute(req).await?;
187
188    let status = resp.status();
189    let content_type = resp
190        .headers()
191        .get("content-type")
192        .and_then(|v| v.to_str().ok())
193        .unwrap_or("application/octet-stream");
194    let content_type = super::ContentType::from(content_type);
195
196    if !status.is_client_error() && !status.is_server_error() {
197        let content = resp.text().await?;
198        match content_type {
199            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
200            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetWarninglists200Response`"))),
201            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::GetWarninglists200Response`")))),
202        }
203    } else {
204        let content = resp.text().await?;
205        let entity: Option<GetWarninglistsError> = serde_json::from_str(&content).ok();
206        Err(Error::ResponseError(ResponseContent { status, content, entity }))
207    }
208}
209
210pub async fn search_warninglists(configuration: &configuration::Configuration, value: Option<&str>, enabled: Option<bool>) -> Result<models::GetWarninglists200Response, Error<SearchWarninglistsError>> {
211    // add a prefix to parameters to efficiently prevent name collisions
212    let p_value = value;
213    let p_enabled = enabled;
214
215    let uri_str = format!("{}/warninglists", configuration.base_path);
216    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
217
218    if let Some(ref user_agent) = configuration.user_agent {
219        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
220    }
221    if let Some(ref apikey) = configuration.api_key {
222        let key = apikey.key.clone();
223        let value = match apikey.prefix {
224            Some(ref prefix) => format!("{} {}", prefix, key),
225            None => key,
226        };
227        req_builder = req_builder.header("Authorization", value);
228    };
229    let mut multipart_form_params = std::collections::HashMap::new();
230    if let Some(param_value) = p_value {
231        multipart_form_params.insert("value", param_value.to_string());
232    }
233    if let Some(param_value) = p_enabled {
234        multipart_form_params.insert("enabled", param_value.to_string());
235    }
236    req_builder = req_builder.form(&multipart_form_params);
237
238    let req = req_builder.build()?;
239    let resp = configuration.client.execute(req).await?;
240
241    let status = resp.status();
242    let content_type = resp
243        .headers()
244        .get("content-type")
245        .and_then(|v| v.to_str().ok())
246        .unwrap_or("application/octet-stream");
247    let content_type = super::ContentType::from(content_type);
248
249    if !status.is_client_error() && !status.is_server_error() {
250        let content = resp.text().await?;
251        match content_type {
252            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
253            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetWarninglists200Response`"))),
254            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::GetWarninglists200Response`")))),
255        }
256    } else {
257        let content = resp.text().await?;
258        let entity: Option<SearchWarninglistsError> = serde_json::from_str(&content).ok();
259        Err(Error::ResponseError(ResponseContent { status, content, entity }))
260    }
261}
262
263pub async fn toggle_enable_warninglist(configuration: &configuration::Configuration, id: Option<Vec<String>>, name: Option<Vec<String>>, enabled: Option<bool>) -> Result<models::ToggleEnableWarninglist200Response, Error<ToggleEnableWarninglistError>> {
264    // add a prefix to parameters to efficiently prevent name collisions
265    let p_id = id;
266    let p_name = name;
267    let p_enabled = enabled;
268
269    let uri_str = format!("{}/warninglists/toggleEnable", configuration.base_path);
270    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
271
272    if let Some(ref user_agent) = configuration.user_agent {
273        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
274    }
275    if let Some(ref apikey) = configuration.api_key {
276        let key = apikey.key.clone();
277        let value = match apikey.prefix {
278            Some(ref prefix) => format!("{} {}", prefix, key),
279            None => key,
280        };
281        req_builder = req_builder.header("Authorization", value);
282    };
283    let mut multipart_form_params = std::collections::HashMap::new();
284    if let Some(param_value) = p_id {
285        multipart_form_params.insert("id", param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string());
286    }
287    if let Some(param_value) = p_name {
288        multipart_form_params.insert("name", param_value.into_iter().map(|p| p.to_string()).collect::<Vec<String>>().join(",").to_string());
289    }
290    if let Some(param_value) = p_enabled {
291        multipart_form_params.insert("enabled", param_value.to_string());
292    }
293    req_builder = req_builder.form(&multipart_form_params);
294
295    let req = req_builder.build()?;
296    let resp = configuration.client.execute(req).await?;
297
298    let status = resp.status();
299    let content_type = resp
300        .headers()
301        .get("content-type")
302        .and_then(|v| v.to_str().ok())
303        .unwrap_or("application/octet-stream");
304    let content_type = super::ContentType::from(content_type);
305
306    if !status.is_client_error() && !status.is_server_error() {
307        let content = resp.text().await?;
308        match content_type {
309            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
310            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ToggleEnableWarninglist200Response`"))),
311            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::ToggleEnableWarninglist200Response`")))),
312        }
313    } else {
314        let content = resp.text().await?;
315        let entity: Option<ToggleEnableWarninglistError> = serde_json::from_str(&content).ok();
316        Err(Error::ResponseError(ResponseContent { status, content, entity }))
317    }
318}
319
320pub async fn update_warninglists(configuration: &configuration::Configuration, ) -> Result<models::UpdateWarninglists200Response, Error<UpdateWarninglistsError>> {
321
322    let uri_str = format!("{}/warninglists/update", configuration.base_path);
323    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
324
325    if let Some(ref user_agent) = configuration.user_agent {
326        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
327    }
328    if let Some(ref apikey) = configuration.api_key {
329        let key = apikey.key.clone();
330        let value = match apikey.prefix {
331            Some(ref prefix) => format!("{} {}", prefix, key),
332            None => key,
333        };
334        req_builder = req_builder.header("Authorization", value);
335    };
336
337    let req = req_builder.build()?;
338    let resp = configuration.client.execute(req).await?;
339
340    let status = resp.status();
341    let content_type = resp
342        .headers()
343        .get("content-type")
344        .and_then(|v| v.to_str().ok())
345        .unwrap_or("application/octet-stream");
346    let content_type = super::ContentType::from(content_type);
347
348    if !status.is_client_error() && !status.is_server_error() {
349        let content = resp.text().await?;
350        match content_type {
351            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
352            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpdateWarninglists200Response`"))),
353            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::UpdateWarninglists200Response`")))),
354        }
355    } else {
356        let content = resp.text().await?;
357        let entity: Option<UpdateWarninglistsError> = serde_json::from_str(&content).ok();
358        Err(Error::ResponseError(ResponseContent { status, content, entity }))
359    }
360}
361