cortex_client/apis/
responder_config_api.rs1use 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 GetResponderConfigurationError {
22 Status401(models::Error),
23 Status403(models::Error),
24 Status404(models::Error),
25 UnknownValue(serde_json::Value),
26}
27
28#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum ListResponderConfigurationsError {
32 Status401(models::Error),
33 Status403(models::Error),
34 UnknownValue(serde_json::Value),
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum UpdateResponderConfigurationError {
41 Status400(models::Error),
42 Status401(models::Error),
43 Status403(models::Error),
44 UnknownValue(serde_json::Value),
45}
46
47
48pub async fn get_responder_configuration(configuration: &configuration::Configuration, responder_config_name: &str) -> Result<models::BaseConfig, Error<GetResponderConfigurationError>> {
49 let p_responder_config_name = responder_config_name;
51
52 let uri_str = format!("{}/responder/config/{responderConfigName}", configuration.base_path, responderConfigName=crate::apis::urlencode(p_responder_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<GetResponderConfigurationError> = serde_json::from_str(&content).ok();
83 Err(Error::ResponseError(ResponseContent { status, content, entity }))
84 }
85}
86
87pub async fn list_responder_configurations(configuration: &configuration::Configuration, ) -> Result<Vec<models::BaseConfig>, Error<ListResponderConfigurationsError>> {
88
89 let uri_str = format!("{}/responder/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<models::BaseConfig>`"))),
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<models::BaseConfig>`")))),
116 }
117 } else {
118 let content = resp.text().await?;
119 let entity: Option<ListResponderConfigurationsError> = serde_json::from_str(&content).ok();
120 Err(Error::ResponseError(ResponseContent { status, content, entity }))
121 }
122}
123
124pub async fn update_responder_configuration(configuration: &configuration::Configuration, responder_config_name: &str, responder_config_update_request: models::ResponderConfigUpdateRequest) -> Result<models::BaseConfig, Error<UpdateResponderConfigurationError>> {
125 let p_responder_config_name = responder_config_name;
127 let p_responder_config_update_request = responder_config_update_request;
128
129 let uri_str = format!("{}/responder/config/{responderConfigName}", configuration.base_path, responderConfigName=crate::apis::urlencode(p_responder_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_responder_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<UpdateResponderConfigurationError> = serde_json::from_str(&content).ok();
161 Err(Error::ResponseError(ResponseContent { status, content, entity }))
162 }
163}
164