//!
//! MISP Automation API
//!
//! ### 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)
//!
//! The version of the OpenAPI document: 2.4
//!
//! Generated by: https://openapi-generator.tech
//!
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
use crate::{apis::ResponseContent, models};
use super::{Error, configuration, ContentType};
/// struct for typed errors of method [`add_organisation`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AddOrganisationError {
Status403(models::UnauthorizedApiError),
Status404(models::NotFoundApiError),
DefaultResponse(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_organisation`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteOrganisationError {
Status403(models::UnauthorizedApiError),
Status404(models::NotFoundApiError),
DefaultResponse(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`edit_organisation`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EditOrganisationError {
Status403(models::UnauthorizedApiError),
Status404(models::NotFoundApiError),
DefaultResponse(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_organisation_by_id`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetOrganisationByIdError {
Status403(models::UnauthorizedApiError),
Status404(models::NotFoundApiError),
DefaultResponse(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_organisations`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetOrganisationsError {
Status403(models::UnauthorizedApiError),
Status404(models::NotFoundApiError),
DefaultResponse(models::ApiError),
UnknownValue(serde_json::Value),
}
pub async fn add_organisation(configuration: &configuration::Configuration, organisation_no_id: Option<models::OrganisationNoId>) -> Result<models::Organisation, Error<AddOrganisationError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_organisation_no_id = organisation_no_id;
let uri_str = format!("{}/admin/organisations/add", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
req_builder = req_builder.json(&p_organisation_no_id);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Organisation`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AddOrganisationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn delete_organisation(configuration: &configuration::Configuration, organisation_id: &str) -> Result<models::DeleteOrganisation200Response, Error<DeleteOrganisationError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_organisation_id = organisation_id;
let uri_str = format!("{}/admin/organisations/delete/{organisationId}", configuration.base_path, organisationId=p_organisation_id.to_string());
let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteOrganisation200Response`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<DeleteOrganisationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn edit_organisation(configuration: &configuration::Configuration, organisation_id: &str, edit_organisation_request: Option<models::EditOrganisationRequest>) -> Result<models::Organisation, Error<EditOrganisationError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_organisation_id = organisation_id;
let p_edit_organisation_request = edit_organisation_request;
let uri_str = format!("{}/admin/organisations/edit/{organisationId}", configuration.base_path, organisationId=p_organisation_id.to_string());
let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
req_builder = req_builder.json(&p_edit_organisation_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Organisation`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<EditOrganisationError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_organisation_by_id(configuration: &configuration::Configuration, organisation_id: &str) -> Result<models::Organisation, Error<GetOrganisationByIdError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_organisation_id = organisation_id;
let uri_str = format!("{}/organisations/view/{organisationId}", configuration.base_path, organisationId=p_organisation_id.to_string());
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Organisation`"))),
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`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetOrganisationByIdError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_organisations(configuration: &configuration::Configuration, ) -> Result<Vec<models::OrganisationListItem>, Error<GetOrganisationsError>> {
let uri_str = format!("{}/organisations", configuration.base_path);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref apikey) = configuration.api_key {
let key = apikey.key.clone();
let value = match apikey.prefix {
Some(ref prefix) => format!("{} {}", prefix, key),
None => key,
};
req_builder = req_builder.header("Authorization", value);
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec<models::OrganisationListItem>`"))),
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::OrganisationListItem>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetOrganisationsError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}