cortex_client/apis/
responder_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 [`create_responder_from_definition`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateResponderFromDefinitionError {
22    Status400(models::Error),
23    Status401(models::Error),
24    Status403(models::Error),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`delete_responder`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum DeleteResponderError {
32    Status401(models::Error),
33    Status403(models::Error),
34    Status404(models::Error),
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`find_responders`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum FindRespondersError {
42    Status401(models::Error),
43    Status403(models::Error),
44    UnknownValue(serde_json::Value),
45}
46
47/// struct for typed errors of method [`get_responder_by_id`]
48#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum GetResponderByIdError {
51    Status401(models::Error),
52    Status403(models::Error),
53    Status404(models::Error),
54    UnknownValue(serde_json::Value),
55}
56
57/// struct for typed errors of method [`list_responder_definitions`]
58#[derive(Debug, Clone, Serialize, Deserialize)]
59#[serde(untagged)]
60pub enum ListResponderDefinitionsError {
61    Status401(models::Error),
62    Status403(models::Error),
63    UnknownValue(serde_json::Value),
64}
65
66/// struct for typed errors of method [`list_responders_for_type`]
67#[derive(Debug, Clone, Serialize, Deserialize)]
68#[serde(untagged)]
69pub enum ListRespondersForTypeError {
70    Status401(models::Error),
71    Status403(models::Error),
72    UnknownValue(serde_json::Value),
73}
74
75/// struct for typed errors of method [`scan_responder_definitions`]
76#[derive(Debug, Clone, Serialize, Deserialize)]
77#[serde(untagged)]
78pub enum ScanResponderDefinitionsError {
79    Status401(models::Error),
80    Status403(models::Error),
81    UnknownValue(serde_json::Value),
82}
83
84/// struct for typed errors of method [`update_responder`]
85#[derive(Debug, Clone, Serialize, Deserialize)]
86#[serde(untagged)]
87pub enum UpdateResponderError {
88    Status400(models::Error),
89    Status401(models::Error),
90    Status403(models::Error),
91    Status404(models::Error),
92    UnknownValue(serde_json::Value),
93}
94
95
96pub async fn create_responder_from_definition(configuration: &configuration::Configuration, responder_definition_id: &str, responder_create_request: models::ResponderCreateRequest) -> Result<models::Worker, Error<CreateResponderFromDefinitionError>> {
97    // add a prefix to parameters to efficiently prevent name collisions
98    let p_responder_definition_id = responder_definition_id;
99    let p_responder_create_request = responder_create_request;
100
101    let uri_str = format!("{}/responder/definition/{responderDefinitionId}", configuration.base_path, responderDefinitionId=crate::apis::urlencode(p_responder_definition_id));
102    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
103
104    if let Some(ref user_agent) = configuration.user_agent {
105        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
106    }
107    if let Some(ref token) = configuration.bearer_access_token {
108        req_builder = req_builder.bearer_auth(token.to_owned());
109    };
110    req_builder = req_builder.json(&p_responder_create_request);
111
112    let req = req_builder.build()?;
113    let resp = configuration.client.execute(req).await?;
114
115    let status = resp.status();
116    let content_type = resp
117        .headers()
118        .get("content-type")
119        .and_then(|v| v.to_str().ok())
120        .unwrap_or("application/octet-stream");
121    let content_type = super::ContentType::from(content_type);
122
123    if !status.is_client_error() && !status.is_server_error() {
124        let content = resp.text().await?;
125        match content_type {
126            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
127            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Worker`"))),
128            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::Worker`")))),
129        }
130    } else {
131        let content = resp.text().await?;
132        let entity: Option<CreateResponderFromDefinitionError> = serde_json::from_str(&content).ok();
133        Err(Error::ResponseError(ResponseContent { status, content, entity }))
134    }
135}
136
137pub async fn delete_responder(configuration: &configuration::Configuration, responder_id: &str) -> Result<(), Error<DeleteResponderError>> {
138    // add a prefix to parameters to efficiently prevent name collisions
139    let p_responder_id = responder_id;
140
141    let uri_str = format!("{}/responder/{responderId}", configuration.base_path, responderId=crate::apis::urlencode(p_responder_id));
142    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
143
144    if let Some(ref user_agent) = configuration.user_agent {
145        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
146    }
147    if let Some(ref token) = configuration.bearer_access_token {
148        req_builder = req_builder.bearer_auth(token.to_owned());
149    };
150
151    let req = req_builder.build()?;
152    let resp = configuration.client.execute(req).await?;
153
154    let status = resp.status();
155
156    if !status.is_client_error() && !status.is_server_error() {
157        Ok(())
158    } else {
159        let content = resp.text().await?;
160        let entity: Option<DeleteResponderError> = serde_json::from_str(&content).ok();
161        Err(Error::ResponseError(ResponseContent { status, content, entity }))
162    }
163}
164
165pub async fn find_responders(configuration: &configuration::Configuration, responder_find_request: Option<models::ResponderFindRequest>) -> Result<models::ListAnalyzersForType200Response, Error<FindRespondersError>> {
166    // add a prefix to parameters to efficiently prevent name collisions
167    let p_responder_find_request = responder_find_request;
168
169    let uri_str = format!("{}/responder/_search", configuration.base_path);
170    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
171
172    if let Some(ref user_agent) = configuration.user_agent {
173        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
174    }
175    if let Some(ref token) = configuration.bearer_access_token {
176        req_builder = req_builder.bearer_auth(token.to_owned());
177    };
178    req_builder = req_builder.json(&p_responder_find_request);
179
180    let req = req_builder.build()?;
181    let resp = configuration.client.execute(req).await?;
182
183    let status = resp.status();
184    let content_type = resp
185        .headers()
186        .get("content-type")
187        .and_then(|v| v.to_str().ok())
188        .unwrap_or("application/octet-stream");
189    let content_type = super::ContentType::from(content_type);
190
191    if !status.is_client_error() && !status.is_server_error() {
192        let content = resp.text().await?;
193        match content_type {
194            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
195            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListAnalyzersForType200Response`"))),
196            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::ListAnalyzersForType200Response`")))),
197        }
198    } else {
199        let content = resp.text().await?;
200        let entity: Option<FindRespondersError> = serde_json::from_str(&content).ok();
201        Err(Error::ResponseError(ResponseContent { status, content, entity }))
202    }
203}
204
205pub async fn get_responder_by_id(configuration: &configuration::Configuration, responder_id: &str) -> Result<models::Worker, Error<GetResponderByIdError>> {
206    // add a prefix to parameters to efficiently prevent name collisions
207    let p_responder_id = responder_id;
208
209    let uri_str = format!("{}/responder/{responderId}", configuration.base_path, responderId=crate::apis::urlencode(p_responder_id));
210    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
211
212    if let Some(ref user_agent) = configuration.user_agent {
213        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
214    }
215    if let Some(ref token) = configuration.bearer_access_token {
216        req_builder = req_builder.bearer_auth(token.to_owned());
217    };
218
219    let req = req_builder.build()?;
220    let resp = configuration.client.execute(req).await?;
221
222    let status = resp.status();
223    let content_type = resp
224        .headers()
225        .get("content-type")
226        .and_then(|v| v.to_str().ok())
227        .unwrap_or("application/octet-stream");
228    let content_type = super::ContentType::from(content_type);
229
230    if !status.is_client_error() && !status.is_server_error() {
231        let content = resp.text().await?;
232        match content_type {
233            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
234            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Worker`"))),
235            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::Worker`")))),
236        }
237    } else {
238        let content = resp.text().await?;
239        let entity: Option<GetResponderByIdError> = serde_json::from_str(&content).ok();
240        Err(Error::ResponseError(ResponseContent { status, content, entity }))
241    }
242}
243
244pub async fn list_responder_definitions(configuration: &configuration::Configuration, ) -> Result<models::ListAnalyzerDefinitions200Response, Error<ListResponderDefinitionsError>> {
245
246    let uri_str = format!("{}/responder/definition", configuration.base_path);
247    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
248
249    if let Some(ref user_agent) = configuration.user_agent {
250        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
251    }
252    if let Some(ref token) = configuration.bearer_access_token {
253        req_builder = req_builder.bearer_auth(token.to_owned());
254    };
255
256    let req = req_builder.build()?;
257    let resp = configuration.client.execute(req).await?;
258
259    let status = resp.status();
260    let content_type = resp
261        .headers()
262        .get("content-type")
263        .and_then(|v| v.to_str().ok())
264        .unwrap_or("application/octet-stream");
265    let content_type = super::ContentType::from(content_type);
266
267    if !status.is_client_error() && !status.is_server_error() {
268        let content = resp.text().await?;
269        match content_type {
270            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
271            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListAnalyzerDefinitions200Response`"))),
272            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::ListAnalyzerDefinitions200Response`")))),
273        }
274    } else {
275        let content = resp.text().await?;
276        let entity: Option<ListResponderDefinitionsError> = serde_json::from_str(&content).ok();
277        Err(Error::ResponseError(ResponseContent { status, content, entity }))
278    }
279}
280
281pub async fn list_responders_for_type(configuration: &configuration::Configuration, data_type: &str) -> Result<models::ListAnalyzersForType200Response, Error<ListRespondersForTypeError>> {
282    // add a prefix to parameters to efficiently prevent name collisions
283    let p_data_type = data_type;
284
285    let uri_str = format!("{}/responder/type/{dataType}", configuration.base_path, dataType=crate::apis::urlencode(p_data_type));
286    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
287
288    if let Some(ref user_agent) = configuration.user_agent {
289        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
290    }
291    if let Some(ref token) = configuration.bearer_access_token {
292        req_builder = req_builder.bearer_auth(token.to_owned());
293    };
294
295    let req = req_builder.build()?;
296    let resp = configuration.client.execute(req).await?;
297
298    let status = resp.status();
299    let content_type = resp
300        .headers()
301        .get("content-type")
302        .and_then(|v| v.to_str().ok())
303        .unwrap_or("application/octet-stream");
304    let content_type = super::ContentType::from(content_type);
305
306    if !status.is_client_error() && !status.is_server_error() {
307        let content = resp.text().await?;
308        match content_type {
309            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
310            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListAnalyzersForType200Response`"))),
311            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::ListAnalyzersForType200Response`")))),
312        }
313    } else {
314        let content = resp.text().await?;
315        let entity: Option<ListRespondersForTypeError> = serde_json::from_str(&content).ok();
316        Err(Error::ResponseError(ResponseContent { status, content, entity }))
317    }
318}
319
320pub async fn scan_responder_definitions(configuration: &configuration::Configuration, ) -> Result<(), Error<ScanResponderDefinitionsError>> {
321
322    let uri_str = format!("{}/responder/scan", configuration.base_path);
323    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
324
325    if let Some(ref user_agent) = configuration.user_agent {
326        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
327    }
328    if let Some(ref token) = configuration.bearer_access_token {
329        req_builder = req_builder.bearer_auth(token.to_owned());
330    };
331
332    let req = req_builder.build()?;
333    let resp = configuration.client.execute(req).await?;
334
335    let status = resp.status();
336
337    if !status.is_client_error() && !status.is_server_error() {
338        Ok(())
339    } else {
340        let content = resp.text().await?;
341        let entity: Option<ScanResponderDefinitionsError> = serde_json::from_str(&content).ok();
342        Err(Error::ResponseError(ResponseContent { status, content, entity }))
343    }
344}
345
346pub async fn update_responder(configuration: &configuration::Configuration, responder_id: &str, request_body: std::collections::HashMap<String, serde_json::Value>) -> Result<models::Worker, Error<UpdateResponderError>> {
347    // add a prefix to parameters to efficiently prevent name collisions
348    let p_responder_id = responder_id;
349    let p_request_body = request_body;
350
351    let uri_str = format!("{}/responder/{responderId}", configuration.base_path, responderId=crate::apis::urlencode(p_responder_id));
352    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
353
354    if let Some(ref user_agent) = configuration.user_agent {
355        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
356    }
357    if let Some(ref token) = configuration.bearer_access_token {
358        req_builder = req_builder.bearer_auth(token.to_owned());
359    };
360    req_builder = req_builder.json(&p_request_body);
361
362    let req = req_builder.build()?;
363    let resp = configuration.client.execute(req).await?;
364
365    let status = resp.status();
366    let content_type = resp
367        .headers()
368        .get("content-type")
369        .and_then(|v| v.to_str().ok())
370        .unwrap_or("application/octet-stream");
371    let content_type = super::ContentType::from(content_type);
372
373    if !status.is_client_error() && !status.is_server_error() {
374        let content = resp.text().await?;
375        match content_type {
376            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
377            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Worker`"))),
378            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::Worker`")))),
379        }
380    } else {
381        let content = resp.text().await?;
382        let entity: Option<UpdateResponderError> = serde_json::from_str(&content).ok();
383        Err(Error::ResponseError(ResponseContent { status, content, entity }))
384    }
385}
386