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