misp_client_rs/apis/
user_settings_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 [`delete_user_setting_by_id`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum DeleteUserSettingByIdError {
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_user_setting_by_id`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum GetUserSettingByIdError {
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_user_setting_by_name`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum GetUserSettingByNameError {
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 [`get_user_settings`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetUserSettingsError {
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 [`search_user_settings`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum SearchUserSettingsError {
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 [`set_user_setting`]
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum SetUserSettingError {
72    Status403(models::UnauthorizedApiError),
73    Status404(models::NotFoundApiError),
74    DefaultResponse(models::ApiError),
75    UnknownValue(serde_json::Value),
76}
77
78
79pub async fn delete_user_setting_by_id(configuration: &configuration::Configuration, user_setting_id: &str) -> Result<models::DeleteUserSettingById200Response, Error<DeleteUserSettingByIdError>> {
80    // add a prefix to parameters to efficiently prevent name collisions
81    let p_user_setting_id = user_setting_id;
82
83    let uri_str = format!("{}/user_settings/delete/{userSettingId}", configuration.base_path, userSettingId=crate::apis::urlencode(p_user_setting_id));
84    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &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
98    let req = req_builder.build()?;
99    let resp = configuration.client.execute(req).await?;
100
101    let status = resp.status();
102    let content_type = resp
103        .headers()
104        .get("content-type")
105        .and_then(|v| v.to_str().ok())
106        .unwrap_or("application/octet-stream");
107    let content_type = super::ContentType::from(content_type);
108
109    if !status.is_client_error() && !status.is_server_error() {
110        let content = resp.text().await?;
111        match content_type {
112            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
113            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteUserSettingById200Response`"))),
114            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::DeleteUserSettingById200Response`")))),
115        }
116    } else {
117        let content = resp.text().await?;
118        let entity: Option<DeleteUserSettingByIdError> = serde_json::from_str(&content).ok();
119        Err(Error::ResponseError(ResponseContent { status, content, entity }))
120    }
121}
122
123pub async fn get_user_setting_by_id(configuration: &configuration::Configuration, user_setting_id: &str) -> Result<models::GetUserSettings200ResponseInner, Error<GetUserSettingByIdError>> {
124    // add a prefix to parameters to efficiently prevent name collisions
125    let p_user_setting_id = user_setting_id;
126
127    let uri_str = format!("{}/user_settings/view/{userSettingId}", configuration.base_path, userSettingId=crate::apis::urlencode(p_user_setting_id));
128    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
129
130    if let Some(ref user_agent) = configuration.user_agent {
131        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
132    }
133    if let Some(ref apikey) = configuration.api_key {
134        let key = apikey.key.clone();
135        let value = match apikey.prefix {
136            Some(ref prefix) => format!("{} {}", prefix, key),
137            None => key,
138        };
139        req_builder = req_builder.header("Authorization", value);
140    };
141
142    let req = req_builder.build()?;
143    let resp = configuration.client.execute(req).await?;
144
145    let status = resp.status();
146    let content_type = resp
147        .headers()
148        .get("content-type")
149        .and_then(|v| v.to_str().ok())
150        .unwrap_or("application/octet-stream");
151    let content_type = super::ContentType::from(content_type);
152
153    if !status.is_client_error() && !status.is_server_error() {
154        let content = resp.text().await?;
155        match content_type {
156            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
157            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetUserSettings200ResponseInner`"))),
158            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::GetUserSettings200ResponseInner`")))),
159        }
160    } else {
161        let content = resp.text().await?;
162        let entity: Option<GetUserSettingByIdError> = serde_json::from_str(&content).ok();
163        Err(Error::ResponseError(ResponseContent { status, content, entity }))
164    }
165}
166
167pub async fn get_user_setting_by_name(configuration: &configuration::Configuration, user_id: &str, user_setting_name: models::UserSettingName) -> Result<models::GetUserSettings200ResponseInner, Error<GetUserSettingByNameError>> {
168    // add a prefix to parameters to efficiently prevent name collisions
169    let p_user_id = user_id;
170    let p_user_setting_name = user_setting_name;
171
172    let uri_str = format!("{}/user_settings/getSetting/{userId}/{userSettingName}", configuration.base_path, userId=crate::apis::urlencode(p_user_id), userSettingName=p_user_setting_name.to_string());
173    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
174
175    if let Some(ref user_agent) = configuration.user_agent {
176        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
177    }
178    if let Some(ref apikey) = configuration.api_key {
179        let key = apikey.key.clone();
180        let value = match apikey.prefix {
181            Some(ref prefix) => format!("{} {}", prefix, key),
182            None => key,
183        };
184        req_builder = req_builder.header("Authorization", value);
185    };
186
187    let req = req_builder.build()?;
188    let resp = configuration.client.execute(req).await?;
189
190    let status = resp.status();
191    let content_type = resp
192        .headers()
193        .get("content-type")
194        .and_then(|v| v.to_str().ok())
195        .unwrap_or("application/octet-stream");
196    let content_type = super::ContentType::from(content_type);
197
198    if !status.is_client_error() && !status.is_server_error() {
199        let content = resp.text().await?;
200        match content_type {
201            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
202            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetUserSettings200ResponseInner`"))),
203            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::GetUserSettings200ResponseInner`")))),
204        }
205    } else {
206        let content = resp.text().await?;
207        let entity: Option<GetUserSettingByNameError> = serde_json::from_str(&content).ok();
208        Err(Error::ResponseError(ResponseContent { status, content, entity }))
209    }
210}
211
212pub async fn get_user_settings(configuration: &configuration::Configuration, ) -> Result<Vec<models::GetUserSettings200ResponseInner>, Error<GetUserSettingsError>> {
213
214    let uri_str = format!("{}/user_settings", configuration.base_path);
215    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
216
217    if let Some(ref user_agent) = configuration.user_agent {
218        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
219    }
220    if let Some(ref apikey) = configuration.api_key {
221        let key = apikey.key.clone();
222        let value = match apikey.prefix {
223            Some(ref prefix) => format!("{} {}", prefix, key),
224            None => key,
225        };
226        req_builder = req_builder.header("Authorization", value);
227    };
228
229    let req = req_builder.build()?;
230    let resp = configuration.client.execute(req).await?;
231
232    let status = resp.status();
233    let content_type = resp
234        .headers()
235        .get("content-type")
236        .and_then(|v| v.to_str().ok())
237        .unwrap_or("application/octet-stream");
238    let content_type = super::ContentType::from(content_type);
239
240    if !status.is_client_error() && !status.is_server_error() {
241        let content = resp.text().await?;
242        match content_type {
243            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
244            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::GetUserSettings200ResponseInner&gt;`"))),
245            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::GetUserSettings200ResponseInner&gt;`")))),
246        }
247    } else {
248        let content = resp.text().await?;
249        let entity: Option<GetUserSettingsError> = serde_json::from_str(&content).ok();
250        Err(Error::ResponseError(ResponseContent { status, content, entity }))
251    }
252}
253
254pub async fn search_user_settings(configuration: &configuration::Configuration, search_user_settings_request: Option<models::SearchUserSettingsRequest>) -> Result<Vec<models::GetUserSettings200ResponseInner>, Error<SearchUserSettingsError>> {
255    // add a prefix to parameters to efficiently prevent name collisions
256    let p_search_user_settings_request = search_user_settings_request;
257
258    let uri_str = format!("{}/user_settings", configuration.base_path);
259    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
260
261    if let Some(ref user_agent) = configuration.user_agent {
262        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
263    }
264    if let Some(ref apikey) = configuration.api_key {
265        let key = apikey.key.clone();
266        let value = match apikey.prefix {
267            Some(ref prefix) => format!("{} {}", prefix, key),
268            None => key,
269        };
270        req_builder = req_builder.header("Authorization", value);
271    };
272    req_builder = req_builder.json(&p_search_user_settings_request);
273
274    let req = req_builder.build()?;
275    let resp = configuration.client.execute(req).await?;
276
277    let status = resp.status();
278    let content_type = resp
279        .headers()
280        .get("content-type")
281        .and_then(|v| v.to_str().ok())
282        .unwrap_or("application/octet-stream");
283    let content_type = super::ContentType::from(content_type);
284
285    if !status.is_client_error() && !status.is_server_error() {
286        let content = resp.text().await?;
287        match content_type {
288            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
289            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::GetUserSettings200ResponseInner&gt;`"))),
290            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::GetUserSettings200ResponseInner&gt;`")))),
291        }
292    } else {
293        let content = resp.text().await?;
294        let entity: Option<SearchUserSettingsError> = serde_json::from_str(&content).ok();
295        Err(Error::ResponseError(ResponseContent { status, content, entity }))
296    }
297}
298
299pub async fn set_user_setting(configuration: &configuration::Configuration, user_id: &str, user_setting_name: models::UserSettingName, set_user_setting_request: Option<models::SetUserSettingRequest>) -> Result<models::GetUserSettings200ResponseInner, Error<SetUserSettingError>> {
300    // add a prefix to parameters to efficiently prevent name collisions
301    let p_user_id = user_id;
302    let p_user_setting_name = user_setting_name;
303    let p_set_user_setting_request = set_user_setting_request;
304
305    let uri_str = format!("{}/user_settings/setSetting/{userId}/{userSettingName}", configuration.base_path, userId=crate::apis::urlencode(p_user_id), userSettingName=p_user_setting_name.to_string());
306    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
307
308    if let Some(ref user_agent) = configuration.user_agent {
309        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
310    }
311    if let Some(ref apikey) = configuration.api_key {
312        let key = apikey.key.clone();
313        let value = match apikey.prefix {
314            Some(ref prefix) => format!("{} {}", prefix, key),
315            None => key,
316        };
317        req_builder = req_builder.header("Authorization", value);
318    };
319    req_builder = req_builder.json(&p_set_user_setting_request);
320
321    let req = req_builder.build()?;
322    let resp = configuration.client.execute(req).await?;
323
324    let status = resp.status();
325    let content_type = resp
326        .headers()
327        .get("content-type")
328        .and_then(|v| v.to_str().ok())
329        .unwrap_or("application/octet-stream");
330    let content_type = super::ContentType::from(content_type);
331
332    if !status.is_client_error() && !status.is_server_error() {
333        let content = resp.text().await?;
334        match content_type {
335            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
336            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetUserSettings200ResponseInner`"))),
337            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::GetUserSettings200ResponseInner`")))),
338        }
339    } else {
340        let content = resp.text().await?;
341        let entity: Option<SetUserSettingError> = serde_json::from_str(&content).ok();
342        Err(Error::ResponseError(ResponseContent { status, content, entity }))
343    }
344}
345