//!
//! 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_galaxy_cluster`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum AddGalaxyClusterError {
Status403(models::UnauthorizedApiError),
Status404(models::NotFoundApiError),
DefaultResponse(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`delete_galaxy_cluster`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum DeleteGalaxyClusterError {
Status403(models::UnauthorizedApiError),
Status404(models::NotFoundApiError),
DefaultResponse(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`edit_galaxy_cluster`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum EditGalaxyClusterError {
Status403(models::UnauthorizedApiError),
Status404(models::NotFoundApiError),
DefaultResponse(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_galaxy_cluster_by_id`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetGalaxyClusterByIdError {
Status403(models::UnauthorizedApiError),
Status404(models::NotFoundApiError),
DefaultResponse(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`get_galaxy_clusters`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GetGalaxyClustersError {
Status403(models::UnauthorizedApiError),
Status404(models::NotFoundApiError),
DefaultResponse(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`publish_galaxy_cluster`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PublishGalaxyClusterError {
Status403(models::UnauthorizedApiError),
Status404(models::NotFoundApiError),
DefaultResponse(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`restore_galaxy_cluster`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum RestoreGalaxyClusterError {
Status403(models::UnauthorizedApiError),
Status404(models::NotFoundApiError),
DefaultResponse(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`search_galaxy_clusters`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SearchGalaxyClustersError {
Status403(models::UnauthorizedApiError),
Status404(models::NotFoundApiError),
DefaultResponse(models::ApiError),
UnknownValue(serde_json::Value),
}
/// struct for typed errors of method [`unpublish_galaxy_cluster`]
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum UnpublishGalaxyClusterError {
Status403(models::UnauthorizedApiError),
Status404(models::NotFoundApiError),
DefaultResponse(models::ApiError),
UnknownValue(serde_json::Value),
}
pub async fn add_galaxy_cluster(configuration: &configuration::Configuration, galaxy_id: &str, galaxy_cluster: Option<models::GalaxyCluster>) -> Result<models::AddGalaxyCluster200Response, Error<AddGalaxyClusterError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_galaxy_id = galaxy_id;
let p_galaxy_cluster = galaxy_cluster;
let uri_str = format!("{}/galaxy_clusters/add/{galaxyId}", configuration.base_path, galaxyId=p_galaxy_id.to_string());
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_galaxy_cluster);
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::AddGalaxyCluster200Response`"))),
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::AddGalaxyCluster200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<AddGalaxyClusterError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn delete_galaxy_cluster(configuration: &configuration::Configuration, galaxy_cluster_id: &str) -> Result<models::DeleteGalaxyCluster200Response, Error<DeleteGalaxyClusterError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_galaxy_cluster_id = galaxy_cluster_id;
let uri_str = format!("{}/galaxy_clusters/delete/{galaxyClusterId}", configuration.base_path, galaxyClusterId=p_galaxy_cluster_id.to_string());
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);
};
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::DeleteGalaxyCluster200Response`"))),
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::DeleteGalaxyCluster200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<DeleteGalaxyClusterError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn edit_galaxy_cluster(configuration: &configuration::Configuration, galaxy_cluster_id: &str, galaxy_cluster: Option<models::GalaxyCluster>) -> Result<models::AddGalaxyCluster200Response, Error<EditGalaxyClusterError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_galaxy_cluster_id = galaxy_cluster_id;
let p_galaxy_cluster = galaxy_cluster;
let uri_str = format!("{}/galaxy_clusters/edit/{galaxyClusterId}", configuration.base_path, galaxyClusterId=p_galaxy_cluster_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_galaxy_cluster);
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::AddGalaxyCluster200Response`"))),
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::AddGalaxyCluster200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<EditGalaxyClusterError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_galaxy_cluster_by_id(configuration: &configuration::Configuration, galaxy_cluster_id: &str) -> Result<models::GetGalaxyClusterById200Response, Error<GetGalaxyClusterByIdError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_galaxy_cluster_id = galaxy_cluster_id;
let uri_str = format!("{}/galaxy_clusters/view/{galaxyClusterId}", configuration.base_path, galaxyClusterId=p_galaxy_cluster_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::GetGalaxyClusterById200Response`"))),
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::GetGalaxyClusterById200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetGalaxyClusterByIdError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn get_galaxy_clusters(configuration: &configuration::Configuration, galaxy_id: &str) -> Result<Vec<models::AddGalaxyCluster200Response>, Error<GetGalaxyClustersError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_galaxy_id = galaxy_id;
let uri_str = format!("{}/galaxy_clusters/index/{galaxyId}", configuration.base_path, galaxyId=p_galaxy_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 `Vec<models::AddGalaxyCluster200Response>`"))),
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::AddGalaxyCluster200Response>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<GetGalaxyClustersError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn publish_galaxy_cluster(configuration: &configuration::Configuration, galaxy_cluster_id: &str) -> Result<models::PublishGalaxyCluster200Response, Error<PublishGalaxyClusterError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_galaxy_cluster_id = galaxy_cluster_id;
let uri_str = format!("{}/galaxy_clusters/publish/{galaxyClusterId}", configuration.base_path, galaxyClusterId=p_galaxy_cluster_id.to_string());
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);
};
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::PublishGalaxyCluster200Response`"))),
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::PublishGalaxyCluster200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<PublishGalaxyClusterError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn restore_galaxy_cluster(configuration: &configuration::Configuration, galaxy_cluster_id: &str) -> Result<models::RestoreGalaxyCluster200Response, Error<RestoreGalaxyClusterError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_galaxy_cluster_id = galaxy_cluster_id;
let uri_str = format!("{}/galaxy_clusters/restore/{galaxyClusterId}", configuration.base_path, galaxyClusterId=p_galaxy_cluster_id.to_string());
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);
};
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::RestoreGalaxyCluster200Response`"))),
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::RestoreGalaxyCluster200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<RestoreGalaxyClusterError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn search_galaxy_clusters(configuration: &configuration::Configuration, galaxy_id: &str, search_galaxy_clusters_request: Option<models::SearchGalaxyClustersRequest>) -> Result<Vec<models::AddGalaxyCluster200Response>, Error<SearchGalaxyClustersError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_galaxy_id = galaxy_id;
let p_search_galaxy_clusters_request = search_galaxy_clusters_request;
let uri_str = format!("{}/galaxy_clusters/index/{galaxyId}", configuration.base_path, galaxyId=p_galaxy_id.to_string());
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_search_galaxy_clusters_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 `Vec<models::AddGalaxyCluster200Response>`"))),
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::AddGalaxyCluster200Response>`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<SearchGalaxyClustersError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}
pub async fn unpublish_galaxy_cluster(configuration: &configuration::Configuration, galaxy_cluster_id: &str) -> Result<models::UnpublishGalaxyCluster200Response, Error<UnpublishGalaxyClusterError>> {
// add a prefix to parameters to efficiently prevent name collisions
let p_galaxy_cluster_id = galaxy_cluster_id;
let uri_str = format!("{}/galaxy_clusters/unpublish/{galaxyClusterId}", configuration.base_path, galaxyClusterId=p_galaxy_cluster_id.to_string());
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);
};
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::UnpublishGalaxyCluster200Response`"))),
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::UnpublishGalaxyCluster200Response`")))),
}
} else {
let content = resp.text().await?;
let entity: Option<UnpublishGalaxyClusterError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent { status, content, entity }))
}
}