cortex_client/apis/
analyzer_config_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 [`get_analyzer_configuration`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetAnalyzerConfigurationError {
22    Status401(models::Error),
23    Status403(models::Error),
24    Status404(models::Error),
25    UnknownValue(serde_json::Value),
26}
27
28/// struct for typed errors of method [`list_analyzer_configurations`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum ListAnalyzerConfigurationsError {
32    Status401(models::Error),
33    Status403(models::Error),
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`update_analyzer_configuration`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum UpdateAnalyzerConfigurationError {
41    Status400(models::Error),
42    Status401(models::Error),
43    Status403(models::Error),
44    UnknownValue(serde_json::Value),
45}
46
47
48pub async fn get_analyzer_configuration(configuration: &configuration::Configuration, analyzer_config_name: &str) -> Result<models::BaseConfig, Error<GetAnalyzerConfigurationError>> {
49    // add a prefix to parameters to efficiently prevent name collisions
50    let p_analyzer_config_name = analyzer_config_name;
51
52    let uri_str = format!("{}/analyzer/config/{analyzerConfigName}", configuration.base_path, analyzerConfigName=crate::apis::urlencode(p_analyzer_config_name));
53    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
54
55    if let Some(ref user_agent) = configuration.user_agent {
56        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
57    }
58    if let Some(ref token) = configuration.bearer_access_token {
59        req_builder = req_builder.bearer_auth(token.to_owned());
60    };
61
62    let req = req_builder.build()?;
63    let resp = configuration.client.execute(req).await?;
64
65    let status = resp.status();
66    let content_type = resp
67        .headers()
68        .get("content-type")
69        .and_then(|v| v.to_str().ok())
70        .unwrap_or("application/octet-stream");
71    let content_type = super::ContentType::from(content_type);
72
73    if !status.is_client_error() && !status.is_server_error() {
74        let content = resp.text().await?;
75        match content_type {
76            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
77            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BaseConfig`"))),
78            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::BaseConfig`")))),
79        }
80    } else {
81        let content = resp.text().await?;
82        let entity: Option<GetAnalyzerConfigurationError> = serde_json::from_str(&content).ok();
83        Err(Error::ResponseError(ResponseContent { status, content, entity }))
84    }
85}
86
87pub async fn list_analyzer_configurations(configuration: &configuration::Configuration, ) -> Result<Vec<models::BaseConfig>, Error<ListAnalyzerConfigurationsError>> {
88
89    let uri_str = format!("{}/analyzer/config", configuration.base_path);
90    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
91
92    if let Some(ref user_agent) = configuration.user_agent {
93        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
94    }
95    if let Some(ref token) = configuration.bearer_access_token {
96        req_builder = req_builder.bearer_auth(token.to_owned());
97    };
98
99    let req = req_builder.build()?;
100    let resp = configuration.client.execute(req).await?;
101
102    let status = resp.status();
103    let content_type = resp
104        .headers()
105        .get("content-type")
106        .and_then(|v| v.to_str().ok())
107        .unwrap_or("application/octet-stream");
108    let content_type = super::ContentType::from(content_type);
109
110    if !status.is_client_error() && !status.is_server_error() {
111        let content = resp.text().await?;
112        match content_type {
113            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
114            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `Vec&lt;models::BaseConfig&gt;`"))),
115            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `Vec&lt;models::BaseConfig&gt;`")))),
116        }
117    } else {
118        let content = resp.text().await?;
119        let entity: Option<ListAnalyzerConfigurationsError> = serde_json::from_str(&content).ok();
120        Err(Error::ResponseError(ResponseContent { status, content, entity }))
121    }
122}
123
124pub async fn update_analyzer_configuration(configuration: &configuration::Configuration, analyzer_config_name: &str, analyzer_config_update_request: models::AnalyzerConfigUpdateRequest) -> Result<models::BaseConfig, Error<UpdateAnalyzerConfigurationError>> {
125    // add a prefix to parameters to efficiently prevent name collisions
126    let p_analyzer_config_name = analyzer_config_name;
127    let p_analyzer_config_update_request = analyzer_config_update_request;
128
129    let uri_str = format!("{}/analyzer/config/{analyzerConfigName}", configuration.base_path, analyzerConfigName=crate::apis::urlencode(p_analyzer_config_name));
130    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
131
132    if let Some(ref user_agent) = configuration.user_agent {
133        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
134    }
135    if let Some(ref token) = configuration.bearer_access_token {
136        req_builder = req_builder.bearer_auth(token.to_owned());
137    };
138    req_builder = req_builder.json(&p_analyzer_config_update_request);
139
140    let req = req_builder.build()?;
141    let resp = configuration.client.execute(req).await?;
142
143    let status = resp.status();
144    let content_type = resp
145        .headers()
146        .get("content-type")
147        .and_then(|v| v.to_str().ok())
148        .unwrap_or("application/octet-stream");
149    let content_type = super::ContentType::from(content_type);
150
151    if !status.is_client_error() && !status.is_server_error() {
152        let content = resp.text().await?;
153        match content_type {
154            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
155            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::BaseConfig`"))),
156            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::BaseConfig`")))),
157        }
158    } else {
159        let content = resp.text().await?;
160        let entity: Option<UpdateAnalyzerConfigurationError> = serde_json::from_str(&content).ok();
161        Err(Error::ResponseError(ResponseContent { status, content, entity }))
162    }
163}
164