cortex_client/apis/
organization_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_organization`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum CreateOrganizationError {
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_organization`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum DeleteOrganizationError {
32    Status400(models::Error),
33    Status401(models::Error),
34    Status403(models::Error),
35    Status404(models::Error),
36    UnknownValue(serde_json::Value),
37}
38
39/// struct for typed errors of method [`find_organizations`]
40#[derive(Debug, Clone, Serialize, Deserialize)]
41#[serde(untagged)]
42pub enum FindOrganizationsError {
43    Status401(models::Error),
44    Status403(models::Error),
45    UnknownValue(serde_json::Value),
46}
47
48/// struct for typed errors of method [`get_organization_by_id`]
49#[derive(Debug, Clone, Serialize, Deserialize)]
50#[serde(untagged)]
51pub enum GetOrganizationByIdError {
52    Status401(models::Error),
53    Status403(models::Error),
54    Status404(models::Error),
55    UnknownValue(serde_json::Value),
56}
57
58/// struct for typed errors of method [`get_organization_stats`]
59#[derive(Debug, Clone, Serialize, Deserialize)]
60#[serde(untagged)]
61pub enum GetOrganizationStatsError {
62    Status400(models::Error),
63    Status401(models::Error),
64    Status403(models::Error),
65    UnknownValue(serde_json::Value),
66}
67
68/// struct for typed errors of method [`update_organization`]
69#[derive(Debug, Clone, Serialize, Deserialize)]
70#[serde(untagged)]
71pub enum UpdateOrganizationError {
72    Status400(models::Error),
73    Status401(models::Error),
74    Status403(models::Error),
75    Status404(models::Error),
76    UnknownValue(serde_json::Value),
77}
78
79
80pub async fn create_organization(configuration: &configuration::Configuration, organization_create_request: models::OrganizationCreateRequest) -> Result<models::Organization, Error<CreateOrganizationError>> {
81    // add a prefix to parameters to efficiently prevent name collisions
82    let p_organization_create_request = organization_create_request;
83
84    let uri_str = format!("{}/organization", configuration.base_path);
85    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
86
87    if let Some(ref user_agent) = configuration.user_agent {
88        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
89    }
90    if let Some(ref token) = configuration.bearer_access_token {
91        req_builder = req_builder.bearer_auth(token.to_owned());
92    };
93    req_builder = req_builder.json(&p_organization_create_request);
94
95    let req = req_builder.build()?;
96    let resp = configuration.client.execute(req).await?;
97
98    let status = resp.status();
99    let content_type = resp
100        .headers()
101        .get("content-type")
102        .and_then(|v| v.to_str().ok())
103        .unwrap_or("application/octet-stream");
104    let content_type = super::ContentType::from(content_type);
105
106    if !status.is_client_error() && !status.is_server_error() {
107        let content = resp.text().await?;
108        match content_type {
109            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
110            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Organization`"))),
111            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::Organization`")))),
112        }
113    } else {
114        let content = resp.text().await?;
115        let entity: Option<CreateOrganizationError> = serde_json::from_str(&content).ok();
116        Err(Error::ResponseError(ResponseContent { status, content, entity }))
117    }
118}
119
120pub async fn delete_organization(configuration: &configuration::Configuration, organization_id: &str) -> Result<(), Error<DeleteOrganizationError>> {
121    // add a prefix to parameters to efficiently prevent name collisions
122    let p_organization_id = organization_id;
123
124    let uri_str = format!("{}/organization/{organizationId}", configuration.base_path, organizationId=crate::apis::urlencode(p_organization_id));
125    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
126
127    if let Some(ref user_agent) = configuration.user_agent {
128        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
129    }
130    if let Some(ref token) = configuration.bearer_access_token {
131        req_builder = req_builder.bearer_auth(token.to_owned());
132    };
133
134    let req = req_builder.build()?;
135    let resp = configuration.client.execute(req).await?;
136
137    let status = resp.status();
138
139    if !status.is_client_error() && !status.is_server_error() {
140        Ok(())
141    } else {
142        let content = resp.text().await?;
143        let entity: Option<DeleteOrganizationError> = serde_json::from_str(&content).ok();
144        Err(Error::ResponseError(ResponseContent { status, content, entity }))
145    }
146}
147
148pub async fn find_organizations(configuration: &configuration::Configuration, organization_find_request: Option<models::OrganizationFindRequest>) -> Result<models::FindOrganizations200Response, Error<FindOrganizationsError>> {
149    // add a prefix to parameters to efficiently prevent name collisions
150    let p_organization_find_request = organization_find_request;
151
152    let uri_str = format!("{}/organization/_search", configuration.base_path);
153    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
154
155    if let Some(ref user_agent) = configuration.user_agent {
156        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
157    }
158    if let Some(ref token) = configuration.bearer_access_token {
159        req_builder = req_builder.bearer_auth(token.to_owned());
160    };
161    req_builder = req_builder.json(&p_organization_find_request);
162
163    let req = req_builder.build()?;
164    let resp = configuration.client.execute(req).await?;
165
166    let status = resp.status();
167    let content_type = resp
168        .headers()
169        .get("content-type")
170        .and_then(|v| v.to_str().ok())
171        .unwrap_or("application/octet-stream");
172    let content_type = super::ContentType::from(content_type);
173
174    if !status.is_client_error() && !status.is_server_error() {
175        let content = resp.text().await?;
176        match content_type {
177            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
178            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::FindOrganizations200Response`"))),
179            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::FindOrganizations200Response`")))),
180        }
181    } else {
182        let content = resp.text().await?;
183        let entity: Option<FindOrganizationsError> = serde_json::from_str(&content).ok();
184        Err(Error::ResponseError(ResponseContent { status, content, entity }))
185    }
186}
187
188pub async fn get_organization_by_id(configuration: &configuration::Configuration, organization_id: &str, nstats: Option<bool>) -> Result<models::Organization, Error<GetOrganizationByIdError>> {
189    // add a prefix to parameters to efficiently prevent name collisions
190    let p_organization_id = organization_id;
191    let p_nstats = nstats;
192
193    let uri_str = format!("{}/organization/{organizationId}", configuration.base_path, organizationId=crate::apis::urlencode(p_organization_id));
194    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
195
196    if let Some(ref param_value) = p_nstats {
197        req_builder = req_builder.query(&[("nstats", &param_value.to_string())]);
198    }
199    if let Some(ref user_agent) = configuration.user_agent {
200        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
201    }
202    if let Some(ref token) = configuration.bearer_access_token {
203        req_builder = req_builder.bearer_auth(token.to_owned());
204    };
205
206    let req = req_builder.build()?;
207    let resp = configuration.client.execute(req).await?;
208
209    let status = resp.status();
210    let content_type = resp
211        .headers()
212        .get("content-type")
213        .and_then(|v| v.to_str().ok())
214        .unwrap_or("application/octet-stream");
215    let content_type = super::ContentType::from(content_type);
216
217    if !status.is_client_error() && !status.is_server_error() {
218        let content = resp.text().await?;
219        match content_type {
220            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
221            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Organization`"))),
222            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::Organization`")))),
223        }
224    } else {
225        let content = resp.text().await?;
226        let entity: Option<GetOrganizationByIdError> = serde_json::from_str(&content).ok();
227        Err(Error::ResponseError(ResponseContent { status, content, entity }))
228    }
229}
230
231pub async fn get_organization_stats(configuration: &configuration::Configuration, organization_stats_request: models::OrganizationStatsRequest) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<GetOrganizationStatsError>> {
232    // add a prefix to parameters to efficiently prevent name collisions
233    let p_organization_stats_request = organization_stats_request;
234
235    let uri_str = format!("{}/organization/_stats", configuration.base_path);
236    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
237
238    if let Some(ref user_agent) = configuration.user_agent {
239        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
240    }
241    if let Some(ref token) = configuration.bearer_access_token {
242        req_builder = req_builder.bearer_auth(token.to_owned());
243    };
244    req_builder = req_builder.json(&p_organization_stats_request);
245
246    let req = req_builder.build()?;
247    let resp = configuration.client.execute(req).await?;
248
249    let status = resp.status();
250    let content_type = resp
251        .headers()
252        .get("content-type")
253        .and_then(|v| v.to_str().ok())
254        .unwrap_or("application/octet-stream");
255    let content_type = super::ContentType::from(content_type);
256
257    if !status.is_client_error() && !status.is_server_error() {
258        let content = resp.text().await?;
259        match content_type {
260            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
261            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap&lt;String, serde_json::Value&gt;`"))),
262            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&lt;String, serde_json::Value&gt;`")))),
263        }
264    } else {
265        let content = resp.text().await?;
266        let entity: Option<GetOrganizationStatsError> = serde_json::from_str(&content).ok();
267        Err(Error::ResponseError(ResponseContent { status, content, entity }))
268    }
269}
270
271pub async fn update_organization(configuration: &configuration::Configuration, organization_id: &str, organization_update_request: models::OrganizationUpdateRequest) -> Result<models::Organization, Error<UpdateOrganizationError>> {
272    // add a prefix to parameters to efficiently prevent name collisions
273    let p_organization_id = organization_id;
274    let p_organization_update_request = organization_update_request;
275
276    let uri_str = format!("{}/organization/{organizationId}", configuration.base_path, organizationId=crate::apis::urlencode(p_organization_id));
277    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
278
279    if let Some(ref user_agent) = configuration.user_agent {
280        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
281    }
282    if let Some(ref token) = configuration.bearer_access_token {
283        req_builder = req_builder.bearer_auth(token.to_owned());
284    };
285    req_builder = req_builder.json(&p_organization_update_request);
286
287    let req = req_builder.build()?;
288    let resp = configuration.client.execute(req).await?;
289
290    let status = resp.status();
291    let content_type = resp
292        .headers()
293        .get("content-type")
294        .and_then(|v| v.to_str().ok())
295        .unwrap_or("application/octet-stream");
296    let content_type = super::ContentType::from(content_type);
297
298    if !status.is_client_error() && !status.is_server_error() {
299        let content = resp.text().await?;
300        match content_type {
301            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
302            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::Organization`"))),
303            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::Organization`")))),
304        }
305    } else {
306        let content = resp.text().await?;
307        let entity: Option<UpdateOrganizationError> = serde_json::from_str(&content).ok();
308        Err(Error::ResponseError(ResponseContent { status, content, entity }))
309    }
310}
311