misp_client_rs/apis/
organisations_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_organisation`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AddOrganisationError {
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 [`delete_organisation`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum DeleteOrganisationError {
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 [`edit_organisation`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum EditOrganisationError {
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_organisation_by_id`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetOrganisationByIdError {
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 [`get_organisations`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum GetOrganisationsError {
62    Status403(models::UnauthorizedApiError),
63    Status404(models::NotFoundApiError),
64    DefaultResponse(models::ApiError),
65    UnknownValue(serde_json::Value),
66}
67
68
69pub async fn add_organisation(configuration: &configuration::Configuration, organisation_no_id: Option<models::OrganisationNoId>) -> Result<models::Organisation, Error<AddOrganisationError>> {
70    // add a prefix to parameters to efficiently prevent name collisions
71    let p_organisation_no_id = organisation_no_id;
72
73    let uri_str = format!("{}/admin/organisations/add", configuration.base_path);
74    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
75
76    if let Some(ref user_agent) = configuration.user_agent {
77        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
78    }
79    if let Some(ref apikey) = configuration.api_key {
80        let key = apikey.key.clone();
81        let value = match apikey.prefix {
82            Some(ref prefix) => format!("{} {}", prefix, key),
83            None => key,
84        };
85        req_builder = req_builder.header("Authorization", value);
86    };
87    req_builder = req_builder.json(&p_organisation_no_id);
88
89    let req = req_builder.build()?;
90    let resp = configuration.client.execute(req).await?;
91
92    let status = resp.status();
93    let content_type = resp
94        .headers()
95        .get("content-type")
96        .and_then(|v| v.to_str().ok())
97        .unwrap_or("application/octet-stream");
98    let content_type = super::ContentType::from(content_type);
99
100    if !status.is_client_error() && !status.is_server_error() {
101        let content = resp.text().await?;
102        match content_type {
103            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
104            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Organisation`"))),
105            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::Organisation`")))),
106        }
107    } else {
108        let content = resp.text().await?;
109        let entity: Option<AddOrganisationError> = serde_json::from_str(&content).ok();
110        Err(Error::ResponseError(ResponseContent { status, content, entity }))
111    }
112}
113
114pub async fn delete_organisation(configuration: &configuration::Configuration, organisation_id: &str) -> Result<models::DeleteOrganisation200Response, Error<DeleteOrganisationError>> {
115    // add a prefix to parameters to efficiently prevent name collisions
116    let p_organisation_id = organisation_id;
117
118    let uri_str = format!("{}/admin/organisations/delete/{organisationId}", configuration.base_path, organisationId=p_organisation_id.to_string());
119    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
120
121    if let Some(ref user_agent) = configuration.user_agent {
122        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
123    }
124    if let Some(ref apikey) = configuration.api_key {
125        let key = apikey.key.clone();
126        let value = match apikey.prefix {
127            Some(ref prefix) => format!("{} {}", prefix, key),
128            None => key,
129        };
130        req_builder = req_builder.header("Authorization", value);
131    };
132
133    let req = req_builder.build()?;
134    let resp = configuration.client.execute(req).await?;
135
136    let status = resp.status();
137    let content_type = resp
138        .headers()
139        .get("content-type")
140        .and_then(|v| v.to_str().ok())
141        .unwrap_or("application/octet-stream");
142    let content_type = super::ContentType::from(content_type);
143
144    if !status.is_client_error() && !status.is_server_error() {
145        let content = resp.text().await?;
146        match content_type {
147            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
148            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteOrganisation200Response`"))),
149            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::DeleteOrganisation200Response`")))),
150        }
151    } else {
152        let content = resp.text().await?;
153        let entity: Option<DeleteOrganisationError> = serde_json::from_str(&content).ok();
154        Err(Error::ResponseError(ResponseContent { status, content, entity }))
155    }
156}
157
158pub async fn edit_organisation(configuration: &configuration::Configuration, organisation_id: &str, edit_organisation_request: Option<models::EditOrganisationRequest>) -> Result<models::Organisation, Error<EditOrganisationError>> {
159    // add a prefix to parameters to efficiently prevent name collisions
160    let p_organisation_id = organisation_id;
161    let p_edit_organisation_request = edit_organisation_request;
162
163    let uri_str = format!("{}/admin/organisations/edit/{organisationId}", configuration.base_path, organisationId=p_organisation_id.to_string());
164    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
165
166    if let Some(ref user_agent) = configuration.user_agent {
167        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
168    }
169    if let Some(ref apikey) = configuration.api_key {
170        let key = apikey.key.clone();
171        let value = match apikey.prefix {
172            Some(ref prefix) => format!("{} {}", prefix, key),
173            None => key,
174        };
175        req_builder = req_builder.header("Authorization", value);
176    };
177    req_builder = req_builder.json(&p_edit_organisation_request);
178
179    let req = req_builder.build()?;
180    let resp = configuration.client.execute(req).await?;
181
182    let status = resp.status();
183    let content_type = resp
184        .headers()
185        .get("content-type")
186        .and_then(|v| v.to_str().ok())
187        .unwrap_or("application/octet-stream");
188    let content_type = super::ContentType::from(content_type);
189
190    if !status.is_client_error() && !status.is_server_error() {
191        let content = resp.text().await?;
192        match content_type {
193            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
194            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Organisation`"))),
195            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::Organisation`")))),
196        }
197    } else {
198        let content = resp.text().await?;
199        let entity: Option<EditOrganisationError> = serde_json::from_str(&content).ok();
200        Err(Error::ResponseError(ResponseContent { status, content, entity }))
201    }
202}
203
204pub async fn get_organisation_by_id(configuration: &configuration::Configuration, organisation_id: &str) -> Result<models::Organisation, Error<GetOrganisationByIdError>> {
205    // add a prefix to parameters to efficiently prevent name collisions
206    let p_organisation_id = organisation_id;
207
208    let uri_str = format!("{}/organisations/view/{organisationId}", configuration.base_path, organisationId=p_organisation_id.to_string());
209    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
210
211    if let Some(ref user_agent) = configuration.user_agent {
212        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
213    }
214    if let Some(ref apikey) = configuration.api_key {
215        let key = apikey.key.clone();
216        let value = match apikey.prefix {
217            Some(ref prefix) => format!("{} {}", prefix, key),
218            None => key,
219        };
220        req_builder = req_builder.header("Authorization", value);
221    };
222
223    let req = req_builder.build()?;
224    let resp = configuration.client.execute(req).await?;
225
226    let status = resp.status();
227    let content_type = resp
228        .headers()
229        .get("content-type")
230        .and_then(|v| v.to_str().ok())
231        .unwrap_or("application/octet-stream");
232    let content_type = super::ContentType::from(content_type);
233
234    if !status.is_client_error() && !status.is_server_error() {
235        let content = resp.text().await?;
236        match content_type {
237            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
238            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Organisation`"))),
239            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::Organisation`")))),
240        }
241    } else {
242        let content = resp.text().await?;
243        let entity: Option<GetOrganisationByIdError> = serde_json::from_str(&content).ok();
244        Err(Error::ResponseError(ResponseContent { status, content, entity }))
245    }
246}
247
248pub async fn get_organisations(configuration: &configuration::Configuration, ) -> Result<Vec<models::OrganisationListItem>, Error<GetOrganisationsError>> {
249
250    let uri_str = format!("{}/organisations", configuration.base_path);
251    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
252
253    if let Some(ref user_agent) = configuration.user_agent {
254        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
255    }
256    if let Some(ref apikey) = configuration.api_key {
257        let key = apikey.key.clone();
258        let value = match apikey.prefix {
259            Some(ref prefix) => format!("{} {}", prefix, key),
260            None => key,
261        };
262        req_builder = req_builder.header("Authorization", value);
263    };
264
265    let req = req_builder.build()?;
266    let resp = configuration.client.execute(req).await?;
267
268    let status = resp.status();
269    let content_type = resp
270        .headers()
271        .get("content-type")
272        .and_then(|v| v.to_str().ok())
273        .unwrap_or("application/octet-stream");
274    let content_type = super::ContentType::from(content_type);
275
276    if !status.is_client_error() && !status.is_server_error() {
277        let content = resp.text().await?;
278        match content_type {
279            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
280            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::OrganisationListItem&gt;`"))),
281            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::OrganisationListItem&gt;`")))),
282        }
283    } else {
284        let content = resp.text().await?;
285        let entity: Option<GetOrganisationsError> = serde_json::from_str(&content).ok();
286        Err(Error::ResponseError(ResponseContent { status, content, entity }))
287    }
288}
289