misp_client_rs/apis/
galaxies_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 [`attach_galaxy_cluster`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum AttachGalaxyClusterError {
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_galaxy`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum DeleteGalaxyError {
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 [`export_galaxy_clusters`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum ExportGalaxyClustersError {
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_galaxies`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetGalaxiesError {
52    Status403(models::UnauthorizedApiError),
53    DefaultResponse(models::ApiError),
54    UnknownValue(serde_json::Value),
55}
56
57/// struct for typed errors of method [`get_galaxy_by_id`]
58#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum GetGalaxyByIdError {
61    Status403(models::UnauthorizedApiError),
62    DefaultResponse(models::ApiError),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`import_galaxy_cluster`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum ImportGalaxyClusterError {
70    Status403(models::UnauthorizedApiError),
71    Status404(models::NotFoundApiError),
72    DefaultResponse(models::ApiError),
73    UnknownValue(serde_json::Value),
74}
75
76/// struct for typed errors of method [`search_galaxies`]
77#[derive(Debug, Clone, Serialize, Deserialize)]
78#[serde(untagged)]
79pub enum SearchGalaxiesError {
80    Status403(models::UnauthorizedApiError),
81    DefaultResponse(models::ApiError),
82    UnknownValue(serde_json::Value),
83}
84
85/// struct for typed errors of method [`update_galaxies`]
86#[derive(Debug, Clone, Serialize, Deserialize)]
87#[serde(untagged)]
88pub enum UpdateGalaxiesError {
89    Status403(models::UnauthorizedApiError),
90    Status404(models::NotFoundApiError),
91    DefaultResponse(models::ApiError),
92    UnknownValue(serde_json::Value),
93}
94
95
96pub async fn attach_galaxy_cluster(configuration: &configuration::Configuration, attach_target_id: &str, attach_target_type: &str, local: bool, attach_galaxy_cluster_request: Option<models::AttachGalaxyClusterRequest>) -> Result<models::AttachGalaxyCluster200Response, Error<AttachGalaxyClusterError>> {
97    // add a prefix to parameters to efficiently prevent name collisions
98    let p_attach_target_id = attach_target_id;
99    let p_attach_target_type = attach_target_type;
100    let p_local = local;
101    let p_attach_galaxy_cluster_request = attach_galaxy_cluster_request;
102
103    let uri_str = format!("{}/galaxies/attachCluster/{attachTargetId}/{attachTargetType}/local:{local}", configuration.base_path, attachTargetId=p_attach_target_id.to_string(), attachTargetType=crate::apis::urlencode(p_attach_target_type), local=p_local);
104    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
105
106    if let Some(ref user_agent) = configuration.user_agent {
107        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
108    }
109    if let Some(ref apikey) = configuration.api_key {
110        let key = apikey.key.clone();
111        let value = match apikey.prefix {
112            Some(ref prefix) => format!("{} {}", prefix, key),
113            None => key,
114        };
115        req_builder = req_builder.header("Authorization", value);
116    };
117    req_builder = req_builder.json(&p_attach_galaxy_cluster_request);
118
119    let req = req_builder.build()?;
120    let resp = configuration.client.execute(req).await?;
121
122    let status = resp.status();
123    let content_type = resp
124        .headers()
125        .get("content-type")
126        .and_then(|v| v.to_str().ok())
127        .unwrap_or("application/octet-stream");
128    let content_type = super::ContentType::from(content_type);
129
130    if !status.is_client_error() && !status.is_server_error() {
131        let content = resp.text().await?;
132        match content_type {
133            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
134            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::AttachGalaxyCluster200Response`"))),
135            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::AttachGalaxyCluster200Response`")))),
136        }
137    } else {
138        let content = resp.text().await?;
139        let entity: Option<AttachGalaxyClusterError> = serde_json::from_str(&content).ok();
140        Err(Error::ResponseError(ResponseContent { status, content, entity }))
141    }
142}
143
144pub async fn delete_galaxy(configuration: &configuration::Configuration, galaxy_id: &str) -> Result<models::DeleteGalaxy200Response, Error<DeleteGalaxyError>> {
145    // add a prefix to parameters to efficiently prevent name collisions
146    let p_galaxy_id = galaxy_id;
147
148    let uri_str = format!("{}/galaxies/delete/{galaxyId}", configuration.base_path, galaxyId=p_galaxy_id.to_string());
149    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
150
151    if let Some(ref user_agent) = configuration.user_agent {
152        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
153    }
154    if let Some(ref apikey) = configuration.api_key {
155        let key = apikey.key.clone();
156        let value = match apikey.prefix {
157            Some(ref prefix) => format!("{} {}", prefix, key),
158            None => key,
159        };
160        req_builder = req_builder.header("Authorization", value);
161    };
162
163    let req = req_builder.build()?;
164    let resp = configuration.client.execute(req).await?;
165
166    let status = resp.status();
167    let content_type = resp
168        .headers()
169        .get("content-type")
170        .and_then(|v| v.to_str().ok())
171        .unwrap_or("application/octet-stream");
172    let content_type = super::ContentType::from(content_type);
173
174    if !status.is_client_error() && !status.is_server_error() {
175        let content = resp.text().await?;
176        match content_type {
177            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
178            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteGalaxy200Response`"))),
179            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::DeleteGalaxy200Response`")))),
180        }
181    } else {
182        let content = resp.text().await?;
183        let entity: Option<DeleteGalaxyError> = serde_json::from_str(&content).ok();
184        Err(Error::ResponseError(ResponseContent { status, content, entity }))
185    }
186}
187
188pub async fn export_galaxy_clusters(configuration: &configuration::Configuration, galaxy_id: &str, export_galaxy_clusters_request: Option<models::ExportGalaxyClustersRequest>) -> Result<models::ExportGalaxyClusters200Response, Error<ExportGalaxyClustersError>> {
189    // add a prefix to parameters to efficiently prevent name collisions
190    let p_galaxy_id = galaxy_id;
191    let p_export_galaxy_clusters_request = export_galaxy_clusters_request;
192
193    let uri_str = format!("{}/galaxies/export/{galaxyId}", configuration.base_path, galaxyId=p_galaxy_id.to_string());
194    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
195
196    if let Some(ref user_agent) = configuration.user_agent {
197        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
198    }
199    if let Some(ref apikey) = configuration.api_key {
200        let key = apikey.key.clone();
201        let value = match apikey.prefix {
202            Some(ref prefix) => format!("{} {}", prefix, key),
203            None => key,
204        };
205        req_builder = req_builder.header("Authorization", value);
206    };
207    req_builder = req_builder.json(&p_export_galaxy_clusters_request);
208
209    let req = req_builder.build()?;
210    let resp = configuration.client.execute(req).await?;
211
212    let status = resp.status();
213    let content_type = resp
214        .headers()
215        .get("content-type")
216        .and_then(|v| v.to_str().ok())
217        .unwrap_or("application/octet-stream");
218    let content_type = super::ContentType::from(content_type);
219
220    if !status.is_client_error() && !status.is_server_error() {
221        let content = resp.text().await?;
222        match content_type {
223            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
224            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ExportGalaxyClusters200Response`"))),
225            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::ExportGalaxyClusters200Response`")))),
226        }
227    } else {
228        let content = resp.text().await?;
229        let entity: Option<ExportGalaxyClustersError> = serde_json::from_str(&content).ok();
230        Err(Error::ResponseError(ResponseContent { status, content, entity }))
231    }
232}
233
234pub async fn get_galaxies(configuration: &configuration::Configuration, ) -> Result<Vec<models::GetGalaxies200ResponseInner>, Error<GetGalaxiesError>> {
235
236    let uri_str = format!("{}/galaxies", configuration.base_path);
237    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
238
239    if let Some(ref user_agent) = configuration.user_agent {
240        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
241    }
242    if let Some(ref apikey) = configuration.api_key {
243        let key = apikey.key.clone();
244        let value = match apikey.prefix {
245            Some(ref prefix) => format!("{} {}", prefix, key),
246            None => key,
247        };
248        req_builder = req_builder.header("Authorization", value);
249    };
250
251    let req = req_builder.build()?;
252    let resp = configuration.client.execute(req).await?;
253
254    let status = resp.status();
255    let content_type = resp
256        .headers()
257        .get("content-type")
258        .and_then(|v| v.to_str().ok())
259        .unwrap_or("application/octet-stream");
260    let content_type = super::ContentType::from(content_type);
261
262    if !status.is_client_error() && !status.is_server_error() {
263        let content = resp.text().await?;
264        match content_type {
265            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
266            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::GetGalaxies200ResponseInner&gt;`"))),
267            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::GetGalaxies200ResponseInner&gt;`")))),
268        }
269    } else {
270        let content = resp.text().await?;
271        let entity: Option<GetGalaxiesError> = serde_json::from_str(&content).ok();
272        Err(Error::ResponseError(ResponseContent { status, content, entity }))
273    }
274}
275
276pub async fn get_galaxy_by_id(configuration: &configuration::Configuration, galaxy_id: &str) -> Result<models::ExtendedGalaxy, Error<GetGalaxyByIdError>> {
277    // add a prefix to parameters to efficiently prevent name collisions
278    let p_galaxy_id = galaxy_id;
279
280    let uri_str = format!("{}/galaxies/view/{galaxyId}", configuration.base_path, galaxyId=p_galaxy_id.to_string());
281    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
282
283    if let Some(ref user_agent) = configuration.user_agent {
284        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
285    }
286    if let Some(ref apikey) = configuration.api_key {
287        let key = apikey.key.clone();
288        let value = match apikey.prefix {
289            Some(ref prefix) => format!("{} {}", prefix, key),
290            None => key,
291        };
292        req_builder = req_builder.header("Authorization", value);
293    };
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::ExtendedGalaxy`"))),
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::ExtendedGalaxy`")))),
312        }
313    } else {
314        let content = resp.text().await?;
315        let entity: Option<GetGalaxyByIdError> = serde_json::from_str(&content).ok();
316        Err(Error::ResponseError(ResponseContent { status, content, entity }))
317    }
318}
319
320pub async fn import_galaxy_cluster(configuration: &configuration::Configuration, import_galaxy_cluster_item: Vec<models::ImportGalaxyClusterItem>) -> Result<models::ImportGalaxyCluster200Response, Error<ImportGalaxyClusterError>> {
321    // add a prefix to parameters to efficiently prevent name collisions
322    let p_import_galaxy_cluster_item = import_galaxy_cluster_item;
323
324    let uri_str = format!("{}/galaxies/import", configuration.base_path);
325    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
326
327    if let Some(ref user_agent) = configuration.user_agent {
328        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
329    }
330    if let Some(ref apikey) = configuration.api_key {
331        let key = apikey.key.clone();
332        let value = match apikey.prefix {
333            Some(ref prefix) => format!("{} {}", prefix, key),
334            None => key,
335        };
336        req_builder = req_builder.header("Authorization", value);
337    };
338    req_builder = req_builder.json(&p_import_galaxy_cluster_item);
339
340    let req = req_builder.build()?;
341    let resp = configuration.client.execute(req).await?;
342
343    let status = resp.status();
344    let content_type = resp
345        .headers()
346        .get("content-type")
347        .and_then(|v| v.to_str().ok())
348        .unwrap_or("application/octet-stream");
349    let content_type = super::ContentType::from(content_type);
350
351    if !status.is_client_error() && !status.is_server_error() {
352        let content = resp.text().await?;
353        match content_type {
354            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
355            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ImportGalaxyCluster200Response`"))),
356            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::ImportGalaxyCluster200Response`")))),
357        }
358    } else {
359        let content = resp.text().await?;
360        let entity: Option<ImportGalaxyClusterError> = serde_json::from_str(&content).ok();
361        Err(Error::ResponseError(ResponseContent { status, content, entity }))
362    }
363}
364
365pub async fn search_galaxies(configuration: &configuration::Configuration, search_galaxies_request: models::SearchGalaxiesRequest) -> Result<Vec<models::GetGalaxies200ResponseInner>, Error<SearchGalaxiesError>> {
366    // add a prefix to parameters to efficiently prevent name collisions
367    let p_search_galaxies_request = search_galaxies_request;
368
369    let uri_str = format!("{}/galaxies", configuration.base_path);
370    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
371
372    if let Some(ref user_agent) = configuration.user_agent {
373        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
374    }
375    if let Some(ref apikey) = configuration.api_key {
376        let key = apikey.key.clone();
377        let value = match apikey.prefix {
378            Some(ref prefix) => format!("{} {}", prefix, key),
379            None => key,
380        };
381        req_builder = req_builder.header("Authorization", value);
382    };
383    req_builder = req_builder.json(&p_search_galaxies_request);
384
385    let req = req_builder.build()?;
386    let resp = configuration.client.execute(req).await?;
387
388    let status = resp.status();
389    let content_type = resp
390        .headers()
391        .get("content-type")
392        .and_then(|v| v.to_str().ok())
393        .unwrap_or("application/octet-stream");
394    let content_type = super::ContentType::from(content_type);
395
396    if !status.is_client_error() && !status.is_server_error() {
397        let content = resp.text().await?;
398        match content_type {
399            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
400            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::GetGalaxies200ResponseInner&gt;`"))),
401            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::GetGalaxies200ResponseInner&gt;`")))),
402        }
403    } else {
404        let content = resp.text().await?;
405        let entity: Option<SearchGalaxiesError> = serde_json::from_str(&content).ok();
406        Err(Error::ResponseError(ResponseContent { status, content, entity }))
407    }
408}
409
410pub async fn update_galaxies(configuration: &configuration::Configuration, ) -> Result<models::UpdateGalaxies200Response, Error<UpdateGalaxiesError>> {
411
412    let uri_str = format!("{}/galaxies/update", configuration.base_path);
413    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
414
415    if let Some(ref user_agent) = configuration.user_agent {
416        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
417    }
418    if let Some(ref apikey) = configuration.api_key {
419        let key = apikey.key.clone();
420        let value = match apikey.prefix {
421            Some(ref prefix) => format!("{} {}", prefix, key),
422            None => key,
423        };
424        req_builder = req_builder.header("Authorization", value);
425    };
426
427    let req = req_builder.build()?;
428    let resp = configuration.client.execute(req).await?;
429
430    let status = resp.status();
431    let content_type = resp
432        .headers()
433        .get("content-type")
434        .and_then(|v| v.to_str().ok())
435        .unwrap_or("application/octet-stream");
436    let content_type = super::ContentType::from(content_type);
437
438    if !status.is_client_error() && !status.is_server_error() {
439        let content = resp.text().await?;
440        match content_type {
441            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
442            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UpdateGalaxies200Response`"))),
443            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::UpdateGalaxies200Response`")))),
444        }
445    } else {
446        let content = resp.text().await?;
447        let entity: Option<UpdateGalaxiesError> = serde_json::from_str(&content).ok();
448        Err(Error::ResponseError(ResponseContent { status, content, entity }))
449    }
450}
451