thehive_client/apis/
case_template_api.rs

1/*
2 * TheHive API
3 *
4 * Comprehensive OpenAPI specification inferred from the TheHive4py client library. This API allows interaction with TheHive platform for managing alerts, cases, observables, tasks, users, and other entities. 
5 *
6 * The version of the OpenAPI document: 2.1.0
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 [`create_case_template`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateCaseTemplateError {
22    Status400(models::ErrorResponse),
23    UnknownValue(serde_json::Value),
24}
25
26/// struct for typed errors of method [`delete_case_template`]
27#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum DeleteCaseTemplateError {
30    Status404(models::ErrorResponse),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`get_case_template_by_id`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetCaseTemplateByIdError {
38    Status404(models::ErrorResponse),
39    UnknownValue(serde_json::Value),
40}
41
42/// struct for typed errors of method [`update_case_template`]
43#[derive(Debug, Clone, Serialize, Deserialize)]
44#[serde(untagged)]
45pub enum UpdateCaseTemplateError {
46    Status400(models::ErrorResponse),
47    UnknownValue(serde_json::Value),
48}
49
50
51pub async fn create_case_template(configuration: &configuration::Configuration, input_case_template: models::InputCaseTemplate, x_organisation: Option<&str>) -> Result<models::OutputCaseTemplate, Error<CreateCaseTemplateError>> {
52    // add a prefix to parameters to efficiently prevent name collisions
53    let p_input_case_template = input_case_template;
54    let p_x_organisation = x_organisation;
55
56    let uri_str = format!("{}/v1/caseTemplate", configuration.base_path);
57    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
58
59    if let Some(ref user_agent) = configuration.user_agent {
60        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
61    }
62    if let Some(param_value) = p_x_organisation {
63        req_builder = req_builder.header("X-Organisation", param_value.to_string());
64    }
65    if let Some(ref auth_conf) = configuration.basic_auth {
66        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
67    };
68    if let Some(ref token) = configuration.bearer_access_token {
69        req_builder = req_builder.bearer_auth(token.to_owned());
70    };
71    req_builder = req_builder.json(&p_input_case_template);
72
73    let req = req_builder.build()?;
74    let resp = configuration.client.execute(req).await?;
75
76    let status = resp.status();
77    let content_type = resp
78        .headers()
79        .get("content-type")
80        .and_then(|v| v.to_str().ok())
81        .unwrap_or("application/octet-stream");
82    let content_type = super::ContentType::from(content_type);
83
84    if !status.is_client_error() && !status.is_server_error() {
85        let content = resp.text().await?;
86        match content_type {
87            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
88            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OutputCaseTemplate`"))),
89            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::OutputCaseTemplate`")))),
90        }
91    } else {
92        let content = resp.text().await?;
93        let entity: Option<CreateCaseTemplateError> = serde_json::from_str(&content).ok();
94        Err(Error::ResponseError(ResponseContent { status, content, entity }))
95    }
96}
97
98pub async fn delete_case_template(configuration: &configuration::Configuration, case_template_id: &str, x_organisation: Option<&str>) -> Result<(), Error<DeleteCaseTemplateError>> {
99    // add a prefix to parameters to efficiently prevent name collisions
100    let p_case_template_id = case_template_id;
101    let p_x_organisation = x_organisation;
102
103    let uri_str = format!("{}/v1/caseTemplate/{case_template_id}", configuration.base_path, case_template_id=crate::apis::urlencode(p_case_template_id));
104    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &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(param_value) = p_x_organisation {
110        req_builder = req_builder.header("X-Organisation", param_value.to_string());
111    }
112    if let Some(ref auth_conf) = configuration.basic_auth {
113        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
114    };
115    if let Some(ref token) = configuration.bearer_access_token {
116        req_builder = req_builder.bearer_auth(token.to_owned());
117    };
118
119    let req = req_builder.build()?;
120    let resp = configuration.client.execute(req).await?;
121
122    let status = resp.status();
123
124    if !status.is_client_error() && !status.is_server_error() {
125        Ok(())
126    } else {
127        let content = resp.text().await?;
128        let entity: Option<DeleteCaseTemplateError> = serde_json::from_str(&content).ok();
129        Err(Error::ResponseError(ResponseContent { status, content, entity }))
130    }
131}
132
133pub async fn get_case_template_by_id(configuration: &configuration::Configuration, case_template_id: &str, x_organisation: Option<&str>) -> Result<models::OutputCaseTemplate, Error<GetCaseTemplateByIdError>> {
134    // add a prefix to parameters to efficiently prevent name collisions
135    let p_case_template_id = case_template_id;
136    let p_x_organisation = x_organisation;
137
138    let uri_str = format!("{}/v1/caseTemplate/{case_template_id}", configuration.base_path, case_template_id=crate::apis::urlencode(p_case_template_id));
139    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
140
141    if let Some(ref user_agent) = configuration.user_agent {
142        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
143    }
144    if let Some(param_value) = p_x_organisation {
145        req_builder = req_builder.header("X-Organisation", param_value.to_string());
146    }
147    if let Some(ref auth_conf) = configuration.basic_auth {
148        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
149    };
150    if let Some(ref token) = configuration.bearer_access_token {
151        req_builder = req_builder.bearer_auth(token.to_owned());
152    };
153
154    let req = req_builder.build()?;
155    let resp = configuration.client.execute(req).await?;
156
157    let status = resp.status();
158    let content_type = resp
159        .headers()
160        .get("content-type")
161        .and_then(|v| v.to_str().ok())
162        .unwrap_or("application/octet-stream");
163    let content_type = super::ContentType::from(content_type);
164
165    if !status.is_client_error() && !status.is_server_error() {
166        let content = resp.text().await?;
167        match content_type {
168            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
169            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::OutputCaseTemplate`"))),
170            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::OutputCaseTemplate`")))),
171        }
172    } else {
173        let content = resp.text().await?;
174        let entity: Option<GetCaseTemplateByIdError> = serde_json::from_str(&content).ok();
175        Err(Error::ResponseError(ResponseContent { status, content, entity }))
176    }
177}
178
179pub async fn update_case_template(configuration: &configuration::Configuration, case_template_id: &str, input_case_template: models::InputCaseTemplate, x_organisation: Option<&str>) -> Result<(), Error<UpdateCaseTemplateError>> {
180    // add a prefix to parameters to efficiently prevent name collisions
181    let p_case_template_id = case_template_id;
182    let p_input_case_template = input_case_template;
183    let p_x_organisation = x_organisation;
184
185    let uri_str = format!("{}/v1/caseTemplate/{case_template_id}", configuration.base_path, case_template_id=crate::apis::urlencode(p_case_template_id));
186    let mut req_builder = configuration.client.request(reqwest::Method::PATCH, &uri_str);
187
188    if let Some(ref user_agent) = configuration.user_agent {
189        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
190    }
191    if let Some(param_value) = p_x_organisation {
192        req_builder = req_builder.header("X-Organisation", param_value.to_string());
193    }
194    if let Some(ref auth_conf) = configuration.basic_auth {
195        req_builder = req_builder.basic_auth(auth_conf.0.to_owned(), auth_conf.1.to_owned());
196    };
197    if let Some(ref token) = configuration.bearer_access_token {
198        req_builder = req_builder.bearer_auth(token.to_owned());
199    };
200    req_builder = req_builder.json(&p_input_case_template);
201
202    let req = req_builder.build()?;
203    let resp = configuration.client.execute(req).await?;
204
205    let status = resp.status();
206
207    if !status.is_client_error() && !status.is_server_error() {
208        Ok(())
209    } else {
210        let content = resp.text().await?;
211        let entity: Option<UpdateCaseTemplateError> = serde_json::from_str(&content).ok();
212        Err(Error::ResponseError(ResponseContent { status, content, entity }))
213    }
214}
215