cortex_client/apis/
artifact_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_job_artifacts`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ListJobArtifactsError {
22    Status401(models::Error),
23    Status403(models::Error),
24    UnknownValue(serde_json::Value),
25}
26
27
28pub async fn list_job_artifacts(configuration: &configuration::Configuration, job_id: &str, analyzer_find_request: Option<models::AnalyzerFindRequest>) -> Result<models::ListJobArtifacts200Response, Error<ListJobArtifactsError>> {
29    // add a prefix to parameters to efficiently prevent name collisions
30    let p_job_id = job_id;
31    let p_analyzer_find_request = analyzer_find_request;
32
33    let uri_str = format!("{}/job/{jobId}/artifacts/_search", configuration.base_path, jobId=crate::apis::urlencode(p_job_id));
34    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
35
36    if let Some(ref user_agent) = configuration.user_agent {
37        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
38    }
39    if let Some(ref token) = configuration.bearer_access_token {
40        req_builder = req_builder.bearer_auth(token.to_owned());
41    };
42    req_builder = req_builder.json(&p_analyzer_find_request);
43
44    let req = req_builder.build()?;
45    let resp = configuration.client.execute(req).await?;
46
47    let status = resp.status();
48    let content_type = resp
49        .headers()
50        .get("content-type")
51        .and_then(|v| v.to_str().ok())
52        .unwrap_or("application/octet-stream");
53    let content_type = super::ContentType::from(content_type);
54
55    if !status.is_client_error() && !status.is_server_error() {
56        let content = resp.text().await?;
57        match content_type {
58            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
59            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListJobArtifacts200Response`"))),
60            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`")))),
61        }
62    } else {
63        let content = resp.text().await?;
64        let entity: Option<ListJobArtifactsError> = serde_json::from_str(&content).ok();
65        Err(Error::ResponseError(ResponseContent { status, content, entity }))
66    }
67}
68