cortex_client/apis/
misp_api.rs

1/*
2 * Cortex API
3 *
4 * API for Cortex, a powerful observable analysis and active response engine.
5 *
6 * The version of the OpenAPI document: 3.1.8
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 [`list_misp_modules`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ListMispModulesError {
22    Status401(models::Error),
23    Status403(models::Error),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`query_misp_module`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum QueryMispModuleError {
31    Status400(models::Error),
32    Status401(models::Error),
33    Status403(models::Error),
34    Status404(models::Error),
35    UnknownValue(serde_json::Value),
36}
37
38
39pub async fn list_misp_modules(configuration: &configuration::Configuration, request_body: Option<std::collections::HashMap<String, serde_json::Value>>) -> Result<models::ListMispModules200Response, Error<ListMispModulesError>> {
40    // add a prefix to parameters to efficiently prevent name collisions
41    let p_request_body = request_body;
42
43    let uri_str = format!("{}/misp/modules", configuration.base_path);
44    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
45
46    if let Some(ref user_agent) = configuration.user_agent {
47        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
48    }
49    if let Some(ref token) = configuration.bearer_access_token {
50        req_builder = req_builder.bearer_auth(token.to_owned());
51    };
52    req_builder = req_builder.json(&p_request_body);
53
54    let req = req_builder.build()?;
55    let resp = configuration.client.execute(req).await?;
56
57    let status = resp.status();
58    let content_type = resp
59        .headers()
60        .get("content-type")
61        .and_then(|v| v.to_str().ok())
62        .unwrap_or("application/octet-stream");
63    let content_type = super::ContentType::from(content_type);
64
65    if !status.is_client_error() && !status.is_server_error() {
66        let content = resp.text().await?;
67        match content_type {
68            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
69            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListMispModules200Response`"))),
70            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::ListMispModules200Response`")))),
71        }
72    } else {
73        let content = resp.text().await?;
74        let entity: Option<ListMispModulesError> = serde_json::from_str(&content).ok();
75        Err(Error::ResponseError(ResponseContent { status, content, entity }))
76    }
77}
78
79pub async fn query_misp_module(configuration: &configuration::Configuration, misp_query_request: models::MispQueryRequest) -> Result<models::MispQueryResponse, Error<QueryMispModuleError>> {
80    // add a prefix to parameters to efficiently prevent name collisions
81    let p_misp_query_request = misp_query_request;
82
83    let uri_str = format!("{}/misp/query", configuration.base_path);
84    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
85
86    if let Some(ref user_agent) = configuration.user_agent {
87        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
88    }
89    if let Some(ref token) = configuration.bearer_access_token {
90        req_builder = req_builder.bearer_auth(token.to_owned());
91    };
92    req_builder = req_builder.json(&p_misp_query_request);
93
94    let req = req_builder.build()?;
95    let resp = configuration.client.execute(req).await?;
96
97    let status = resp.status();
98    let content_type = resp
99        .headers()
100        .get("content-type")
101        .and_then(|v| v.to_str().ok())
102        .unwrap_or("application/octet-stream");
103    let content_type = super::ContentType::from(content_type);
104
105    if !status.is_client_error() && !status.is_server_error() {
106        let content = resp.text().await?;
107        match content_type {
108            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
109            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::MispQueryResponse`"))),
110            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::MispQueryResponse`")))),
111        }
112    } else {
113        let content = resp.text().await?;
114        let entity: Option<QueryMispModuleError> = serde_json::from_str(&content).ok();
115        Err(Error::ResponseError(ResponseContent { status, content, entity }))
116    }
117}
118