misp_client_rs/apis/logs_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 [`get_logs`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetLogsError {
22 Status403(models::UnauthorizedApiError),
23 Status404(models::NotFoundApiError),
24 DefaultResponse(models::ApiError),
25 UnknownValue(serde_json::Value),
26}
27
28
29pub async fn get_logs(configuration: &configuration::Configuration, get_logs_request: Option<models::GetLogsRequest>) -> Result<Vec<models::GetLogs200ResponseInner>, Error<GetLogsError>> {
30 // add a prefix to parameters to efficiently prevent name collisions
31 let p_get_logs_request = get_logs_request;
32
33 let uri_str = format!("{}/admin/logs", configuration.base_path);
34 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
35
36 if let Some(ref user_agent) = configuration.user_agent {
37 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
38 }
39 if let Some(ref apikey) = configuration.api_key {
40 let key = apikey.key.clone();
41 let value = match apikey.prefix {
42 Some(ref prefix) => format!("{} {}", prefix, key),
43 None => key,
44 };
45 req_builder = req_builder.header("Authorization", value);
46 };
47 req_builder = req_builder.json(&p_get_logs_request);
48
49 let req = req_builder.build()?;
50 let resp = configuration.client.execute(req).await?;
51
52 let status = resp.status();
53 let content_type = resp
54 .headers()
55 .get("content-type")
56 .and_then(|v| v.to_str().ok())
57 .unwrap_or("application/octet-stream");
58 let content_type = super::ContentType::from(content_type);
59
60 if !status.is_client_error() && !status.is_server_error() {
61 let content = resp.text().await?;
62 match content_type {
63 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
64 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::GetLogs200ResponseInner>`"))),
65 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<models::GetLogs200ResponseInner>`")))),
66 }
67 } else {
68 let content = resp.text().await?;
69 let entity: Option<GetLogsError> = serde_json::from_str(&content).ok();
70 Err(Error::ResponseError(ResponseContent { status, content, entity }))
71 }
72}
73