1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateAnalyzerJobError {
22 Status400(models::Error),
23 Status401(models::Error),
24 Status403(models::Error),
25 Status404(models::Error),
26 UnknownValue(serde_json::Value),
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum CreateResponderJobError {
33 Status400(models::Error),
34 Status401(models::Error),
35 Status403(models::Error),
36 Status404(models::Error),
37 UnknownValue(serde_json::Value),
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42#[serde(untagged)]
43pub enum DeleteJobError {
44 Status401(models::Error),
45 Status403(models::Error),
46 Status404(models::Error),
47 UnknownValue(serde_json::Value),
48}
49
50#[derive(Debug, Clone, Serialize, Deserialize)]
52#[serde(untagged)]
53pub enum FindJobsError {
54 Status401(models::Error),
55 Status403(models::Error),
56 UnknownValue(serde_json::Value),
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61#[serde(untagged)]
62pub enum GetJobByIdError {
63 Status401(models::Error),
64 Status403(models::Error),
65 Status404(models::Error),
66 UnknownValue(serde_json::Value),
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum GetJobReportError {
73 Status401(models::Error),
74 Status403(models::Error),
75 Status404(models::Error),
76 UnknownValue(serde_json::Value),
77}
78
79#[derive(Debug, Clone, Serialize, Deserialize)]
81#[serde(untagged)]
82pub enum GetJobsStatusError {
83 Status401(models::Error),
84 Status403(models::Error),
85 UnknownValue(serde_json::Value),
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum ListJobArtifactsError {
92 Status401(models::Error),
93 Status403(models::Error),
94 UnknownValue(serde_json::Value),
95}
96
97#[derive(Debug, Clone, Serialize, Deserialize)]
99#[serde(untagged)]
100pub enum ListJobsError {
101 Status401(models::Error),
102 Status403(models::Error),
103 UnknownValue(serde_json::Value),
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
108#[serde(untagged)]
109pub enum WaitJobReportError {
110 Status401(models::Error),
111 Status403(models::Error),
112 Status404(models::Error),
113 UnknownValue(serde_json::Value),
114}
115
116
117pub async fn create_analyzer_job(configuration: &configuration::Configuration, worker_id: &str, job_create_request: models::JobCreateRequest) -> Result<models::Job, Error<CreateAnalyzerJobError>> {
118 let p_worker_id = worker_id;
120 let p_job_create_request = job_create_request;
121
122 let uri_str = format!("{}/analyzer/{workerId}/run", configuration.base_path, workerId=crate::apis::urlencode(p_worker_id));
123 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
124
125 if let Some(ref user_agent) = configuration.user_agent {
126 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
127 }
128 if let Some(ref token) = configuration.bearer_access_token {
129 req_builder = req_builder.bearer_auth(token.to_owned());
130 };
131 req_builder = req_builder.json(&p_job_create_request);
132
133 let req = req_builder.build()?;
134 let resp = configuration.client.execute(req).await?;
135
136 let status = resp.status();
137 let content_type = resp
138 .headers()
139 .get("content-type")
140 .and_then(|v| v.to_str().ok())
141 .unwrap_or("application/octet-stream");
142 let content_type = super::ContentType::from(content_type);
143
144 if !status.is_client_error() && !status.is_server_error() {
145 let content = resp.text().await?;
146 match content_type {
147 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
148 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Job`"))),
149 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::Job`")))),
150 }
151 } else {
152 let content = resp.text().await?;
153 let entity: Option<CreateAnalyzerJobError> = serde_json::from_str(&content).ok();
154 Err(Error::ResponseError(ResponseContent { status, content, entity }))
155 }
156}
157
158pub async fn create_responder_job(configuration: &configuration::Configuration, worker_id: &str, job_create_request: models::JobCreateRequest) -> Result<models::Job, Error<CreateResponderJobError>> {
159 let p_worker_id = worker_id;
161 let p_job_create_request = job_create_request;
162
163 let uri_str = format!("{}/responder/{workerId}/run", configuration.base_path, workerId=crate::apis::urlencode(p_worker_id));
164 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
165
166 if let Some(ref user_agent) = configuration.user_agent {
167 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
168 }
169 if let Some(ref token) = configuration.bearer_access_token {
170 req_builder = req_builder.bearer_auth(token.to_owned());
171 };
172 req_builder = req_builder.json(&p_job_create_request);
173
174 let req = req_builder.build()?;
175 let resp = configuration.client.execute(req).await?;
176
177 let status = resp.status();
178 let content_type = resp
179 .headers()
180 .get("content-type")
181 .and_then(|v| v.to_str().ok())
182 .unwrap_or("application/octet-stream");
183 let content_type = super::ContentType::from(content_type);
184
185 if !status.is_client_error() && !status.is_server_error() {
186 let content = resp.text().await?;
187 match content_type {
188 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
189 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Job`"))),
190 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::Job`")))),
191 }
192 } else {
193 let content = resp.text().await?;
194 let entity: Option<CreateResponderJobError> = serde_json::from_str(&content).ok();
195 Err(Error::ResponseError(ResponseContent { status, content, entity }))
196 }
197}
198
199pub async fn delete_job(configuration: &configuration::Configuration, job_id: &str) -> Result<(), Error<DeleteJobError>> {
200 let p_job_id = job_id;
202
203 let uri_str = format!("{}/job/{jobId}", configuration.base_path, jobId=crate::apis::urlencode(p_job_id));
204 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
205
206 if let Some(ref user_agent) = configuration.user_agent {
207 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
208 }
209 if let Some(ref token) = configuration.bearer_access_token {
210 req_builder = req_builder.bearer_auth(token.to_owned());
211 };
212
213 let req = req_builder.build()?;
214 let resp = configuration.client.execute(req).await?;
215
216 let status = resp.status();
217
218 if !status.is_client_error() && !status.is_server_error() {
219 Ok(())
220 } else {
221 let content = resp.text().await?;
222 let entity: Option<DeleteJobError> = serde_json::from_str(&content).ok();
223 Err(Error::ResponseError(ResponseContent { status, content, entity }))
224 }
225}
226
227pub async fn find_jobs(configuration: &configuration::Configuration, analyzer_find_request: Option<models::AnalyzerFindRequest>) -> Result<models::ListJobs200Response, Error<FindJobsError>> {
228 let p_analyzer_find_request = analyzer_find_request;
230
231 let uri_str = format!("{}/job/_search", configuration.base_path);
232 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
233
234 if let Some(ref user_agent) = configuration.user_agent {
235 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
236 }
237 if let Some(ref token) = configuration.bearer_access_token {
238 req_builder = req_builder.bearer_auth(token.to_owned());
239 };
240 req_builder = req_builder.json(&p_analyzer_find_request);
241
242 let req = req_builder.build()?;
243 let resp = configuration.client.execute(req).await?;
244
245 let status = resp.status();
246 let content_type = resp
247 .headers()
248 .get("content-type")
249 .and_then(|v| v.to_str().ok())
250 .unwrap_or("application/octet-stream");
251 let content_type = super::ContentType::from(content_type);
252
253 if !status.is_client_error() && !status.is_server_error() {
254 let content = resp.text().await?;
255 match content_type {
256 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
257 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListJobs200Response`"))),
258 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::ListJobs200Response`")))),
259 }
260 } else {
261 let content = resp.text().await?;
262 let entity: Option<FindJobsError> = serde_json::from_str(&content).ok();
263 Err(Error::ResponseError(ResponseContent { status, content, entity }))
264 }
265}
266
267pub async fn get_job_by_id(configuration: &configuration::Configuration, job_id: &str) -> Result<models::Job, Error<GetJobByIdError>> {
268 let p_job_id = job_id;
270
271 let uri_str = format!("{}/job/{jobId}", configuration.base_path, jobId=crate::apis::urlencode(p_job_id));
272 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
273
274 if let Some(ref user_agent) = configuration.user_agent {
275 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
276 }
277 if let Some(ref token) = configuration.bearer_access_token {
278 req_builder = req_builder.bearer_auth(token.to_owned());
279 };
280
281 let req = req_builder.build()?;
282 let resp = configuration.client.execute(req).await?;
283
284 let status = resp.status();
285 let content_type = resp
286 .headers()
287 .get("content-type")
288 .and_then(|v| v.to_str().ok())
289 .unwrap_or("application/octet-stream");
290 let content_type = super::ContentType::from(content_type);
291
292 if !status.is_client_error() && !status.is_server_error() {
293 let content = resp.text().await?;
294 match content_type {
295 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
296 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Job`"))),
297 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::Job`")))),
298 }
299 } else {
300 let content = resp.text().await?;
301 let entity: Option<GetJobByIdError> = serde_json::from_str(&content).ok();
302 Err(Error::ResponseError(ResponseContent { status, content, entity }))
303 }
304}
305
306pub async fn get_job_report(configuration: &configuration::Configuration, job_id: &str) -> Result<models::JobReportResponse, Error<GetJobReportError>> {
307 let p_job_id = job_id;
309
310 let uri_str = format!("{}/job/{jobId}/report", configuration.base_path, jobId=crate::apis::urlencode(p_job_id));
311 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
312
313 if let Some(ref user_agent) = configuration.user_agent {
314 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
315 }
316 if let Some(ref token) = configuration.bearer_access_token {
317 req_builder = req_builder.bearer_auth(token.to_owned());
318 };
319
320 let req = req_builder.build()?;
321 let resp = configuration.client.execute(req).await?;
322
323 let status = resp.status();
324 let content_type = resp
325 .headers()
326 .get("content-type")
327 .and_then(|v| v.to_str().ok())
328 .unwrap_or("application/octet-stream");
329 let content_type = super::ContentType::from(content_type);
330
331 if !status.is_client_error() && !status.is_server_error() {
332 let content = resp.text().await?;
333 match content_type {
334 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
335 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JobReportResponse`"))),
336 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::JobReportResponse`")))),
337 }
338 } else {
339 let content = resp.text().await?;
340 let entity: Option<GetJobReportError> = serde_json::from_str(&content).ok();
341 Err(Error::ResponseError(ResponseContent { status, content, entity }))
342 }
343}
344
345pub async fn get_jobs_status(configuration: &configuration::Configuration, job_status_request: models::JobStatusRequest) -> Result<std::collections::HashMap<String, String>, Error<GetJobsStatusError>> {
346 let p_job_status_request = job_status_request;
348
349 let uri_str = format!("{}/job/status", configuration.base_path);
350 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
351
352 if let Some(ref user_agent) = configuration.user_agent {
353 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
354 }
355 if let Some(ref token) = configuration.bearer_access_token {
356 req_builder = req_builder.bearer_auth(token.to_owned());
357 };
358 req_builder = req_builder.json(&p_job_status_request);
359
360 let req = req_builder.build()?;
361 let resp = configuration.client.execute(req).await?;
362
363 let status = resp.status();
364 let content_type = resp
365 .headers()
366 .get("content-type")
367 .and_then(|v| v.to_str().ok())
368 .unwrap_or("application/octet-stream");
369 let content_type = super::ContentType::from(content_type);
370
371 if !status.is_client_error() && !status.is_server_error() {
372 let content = resp.text().await?;
373 match content_type {
374 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
375 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, String>`"))),
376 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, String>`")))),
377 }
378 } else {
379 let content = resp.text().await?;
380 let entity: Option<GetJobsStatusError> = serde_json::from_str(&content).ok();
381 Err(Error::ResponseError(ResponseContent { status, content, entity }))
382 }
383}
384
385pub async fn list_job_artifacts(configuration: &configuration::Configuration, job_id: &str, analyzer_find_request: Option<models::AnalyzerFindRequest>) -> Result<models::ListJobArtifacts200Response, Error<ListJobArtifactsError>> {
386 let p_job_id = job_id;
388 let p_analyzer_find_request = analyzer_find_request;
389
390 let uri_str = format!("{}/job/{jobId}/artifacts/_search", configuration.base_path, jobId=crate::apis::urlencode(p_job_id));
391 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
392
393 if let Some(ref user_agent) = configuration.user_agent {
394 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
395 }
396 if let Some(ref token) = configuration.bearer_access_token {
397 req_builder = req_builder.bearer_auth(token.to_owned());
398 };
399 req_builder = req_builder.json(&p_analyzer_find_request);
400
401 let req = req_builder.build()?;
402 let resp = configuration.client.execute(req).await?;
403
404 let status = resp.status();
405 let content_type = resp
406 .headers()
407 .get("content-type")
408 .and_then(|v| v.to_str().ok())
409 .unwrap_or("application/octet-stream");
410 let content_type = super::ContentType::from(content_type);
411
412 if !status.is_client_error() && !status.is_server_error() {
413 let content = resp.text().await?;
414 match content_type {
415 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
416 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListJobArtifacts200Response`"))),
417 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::ListJobArtifacts200Response`")))),
418 }
419 } else {
420 let content = resp.text().await?;
421 let entity: Option<ListJobArtifactsError> = serde_json::from_str(&content).ok();
422 Err(Error::ResponseError(ResponseContent { status, content, entity }))
423 }
424}
425
426pub async fn list_jobs(configuration: &configuration::Configuration, data_type_filter: Option<&str>, data_filter: Option<&str>, worker_filter: Option<&str>, range: Option<&str>) -> Result<models::ListJobs200Response, Error<ListJobsError>> {
427 let p_data_type_filter = data_type_filter;
429 let p_data_filter = data_filter;
430 let p_worker_filter = worker_filter;
431 let p_range = range;
432
433 let uri_str = format!("{}/job", configuration.base_path);
434 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
435
436 if let Some(ref param_value) = p_data_type_filter {
437 req_builder = req_builder.query(&[("dataTypeFilter", ¶m_value.to_string())]);
438 }
439 if let Some(ref param_value) = p_data_filter {
440 req_builder = req_builder.query(&[("dataFilter", ¶m_value.to_string())]);
441 }
442 if let Some(ref param_value) = p_worker_filter {
443 req_builder = req_builder.query(&[("workerFilter", ¶m_value.to_string())]);
444 }
445 if let Some(ref param_value) = p_range {
446 req_builder = req_builder.query(&[("range", ¶m_value.to_string())]);
447 }
448 if let Some(ref user_agent) = configuration.user_agent {
449 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
450 }
451 if let Some(ref token) = configuration.bearer_access_token {
452 req_builder = req_builder.bearer_auth(token.to_owned());
453 };
454
455 let req = req_builder.build()?;
456 let resp = configuration.client.execute(req).await?;
457
458 let status = resp.status();
459 let content_type = resp
460 .headers()
461 .get("content-type")
462 .and_then(|v| v.to_str().ok())
463 .unwrap_or("application/octet-stream");
464 let content_type = super::ContentType::from(content_type);
465
466 if !status.is_client_error() && !status.is_server_error() {
467 let content = resp.text().await?;
468 match content_type {
469 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
470 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListJobs200Response`"))),
471 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::ListJobs200Response`")))),
472 }
473 } else {
474 let content = resp.text().await?;
475 let entity: Option<ListJobsError> = serde_json::from_str(&content).ok();
476 Err(Error::ResponseError(ResponseContent { status, content, entity }))
477 }
478}
479
480pub async fn wait_job_report(configuration: &configuration::Configuration, job_id: &str, at_most: &str) -> Result<models::JobReportResponse, Error<WaitJobReportError>> {
481 let p_job_id = job_id;
483 let p_at_most = at_most;
484
485 let uri_str = format!("{}/job/{jobId}/waitReport", configuration.base_path, jobId=crate::apis::urlencode(p_job_id));
486 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
487
488 req_builder = req_builder.query(&[("atMost", &p_at_most.to_string())]);
489 if let Some(ref user_agent) = configuration.user_agent {
490 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
491 }
492 if let Some(ref token) = configuration.bearer_access_token {
493 req_builder = req_builder.bearer_auth(token.to_owned());
494 };
495
496 let req = req_builder.build()?;
497 let resp = configuration.client.execute(req).await?;
498
499 let status = resp.status();
500 let content_type = resp
501 .headers()
502 .get("content-type")
503 .and_then(|v| v.to_str().ok())
504 .unwrap_or("application/octet-stream");
505 let content_type = super::ContentType::from(content_type);
506
507 if !status.is_client_error() && !status.is_server_error() {
508 let content = resp.text().await?;
509 match content_type {
510 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
511 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::JobReportResponse`"))),
512 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::JobReportResponse`")))),
513 }
514 } else {
515 let content = resp.text().await?;
516 let entity: Option<WaitJobReportError> = serde_json::from_str(&content).ok();
517 Err(Error::ResponseError(ResponseContent { status, content, entity }))
518 }
519}
520