Skip to main content

tapis_authenticator/apis/
clients_api.rs

1/*
2 * Authenticator
3 *
4 * REST API and web server providing authentication for a Tapis v3 instance.
5 *
6 * The version of the OpenAPI document: 1
7 * Contact: cicsupport@tacc.utexas.edu
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16/// struct for typed errors of method [`create_client`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum CreateClientError {
20    UnknownValue(serde_json::Value),
21}
22
23/// struct for typed errors of method [`delete_client`]
24#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(untagged)]
26pub enum DeleteClientError {
27    UnknownValue(serde_json::Value),
28}
29
30/// struct for typed errors of method [`get_client`]
31#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum GetClientError {
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`list_clients`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum ListClientsError {
41    UnknownValue(serde_json::Value),
42}
43
44/// struct for typed errors of method [`update_client`]
45#[derive(Debug, Clone, Serialize, Deserialize)]
46#[serde(untagged)]
47pub enum UpdateClientError {
48    UnknownValue(serde_json::Value),
49}
50
51pub async fn create_client(
52    configuration: &configuration::Configuration,
53    new_client: models::NewClient,
54) -> Result<models::CreateClient201Response, Error<CreateClientError>> {
55    // add a prefix to parameters to efficiently prevent name collisions
56    let p_body_new_client = new_client;
57
58    let uri_str = format!("{}/v3/oauth2/clients", configuration.base_path);
59    let mut req_builder = configuration
60        .client
61        .request(reqwest::Method::POST, &uri_str);
62
63    if let Some(ref user_agent) = configuration.user_agent {
64        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
65    }
66    if let Some(ref apikey) = configuration.api_key {
67        let key = apikey.key.clone();
68        let value = match apikey.prefix {
69            Some(ref prefix) => format!("{} {}", prefix, key),
70            None => key,
71        };
72        req_builder = req_builder.header("X-Tapis-Token", value);
73    };
74    req_builder = req_builder.json(&p_body_new_client);
75
76    let req = req_builder.build()?;
77    let resp = configuration.client.execute(req).await?;
78
79    let status = resp.status();
80    let content_type = resp
81        .headers()
82        .get("content-type")
83        .and_then(|v| v.to_str().ok())
84        .unwrap_or("application/octet-stream");
85    let content_type = super::ContentType::from(content_type);
86
87    if !status.is_client_error() && !status.is_server_error() {
88        let content = resp.text().await?;
89        match content_type {
90            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
91            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateClient201Response`"))),
92            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateClient201Response`")))),
93        }
94    } else {
95        let content = resp.text().await?;
96        let entity: Option<CreateClientError> = serde_json::from_str(&content).ok();
97        Err(Error::ResponseError(ResponseContent {
98            status,
99            content,
100            entity,
101        }))
102    }
103}
104
105/// Permanently set a client to inactive. Once set to inactive clients cannot be used.
106pub async fn delete_client(
107    configuration: &configuration::Configuration,
108    client_id: &str,
109) -> Result<models::DeleteClient200Response, Error<DeleteClientError>> {
110    // add a prefix to parameters to efficiently prevent name collisions
111    let p_path_client_id = client_id;
112
113    let uri_str = format!(
114        "{}/v3/oauth2/clients/{client_id}",
115        configuration.base_path,
116        client_id = crate::apis::urlencode(p_path_client_id)
117    );
118    let mut req_builder = configuration
119        .client
120        .request(reqwest::Method::DELETE, &uri_str);
121
122    if let Some(ref user_agent) = configuration.user_agent {
123        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
124    }
125    if let Some(ref apikey) = configuration.api_key {
126        let key = apikey.key.clone();
127        let value = match apikey.prefix {
128            Some(ref prefix) => format!("{} {}", prefix, key),
129            None => key,
130        };
131        req_builder = req_builder.header("X-Tapis-Token", value);
132    };
133
134    let req = req_builder.build()?;
135    let resp = configuration.client.execute(req).await?;
136
137    let status = resp.status();
138    let content_type = resp
139        .headers()
140        .get("content-type")
141        .and_then(|v| v.to_str().ok())
142        .unwrap_or("application/octet-stream");
143    let content_type = super::ContentType::from(content_type);
144
145    if !status.is_client_error() && !status.is_server_error() {
146        let content = resp.text().await?;
147        match content_type {
148            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
149            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::DeleteClient200Response`"))),
150            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::DeleteClient200Response`")))),
151        }
152    } else {
153        let content = resp.text().await?;
154        let entity: Option<DeleteClientError> = serde_json::from_str(&content).ok();
155        Err(Error::ResponseError(ResponseContent {
156            status,
157            content,
158            entity,
159        }))
160    }
161}
162
163/// Get details of a specific client by its id.
164pub async fn get_client(
165    configuration: &configuration::Configuration,
166    client_id: &str,
167) -> Result<models::CreateClient201Response, Error<GetClientError>> {
168    // add a prefix to parameters to efficiently prevent name collisions
169    let p_path_client_id = client_id;
170
171    let uri_str = format!(
172        "{}/v3/oauth2/clients/{client_id}",
173        configuration.base_path,
174        client_id = crate::apis::urlencode(p_path_client_id)
175    );
176    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
177
178    if let Some(ref user_agent) = configuration.user_agent {
179        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
180    }
181    if let Some(ref apikey) = configuration.api_key {
182        let key = apikey.key.clone();
183        let value = match apikey.prefix {
184            Some(ref prefix) => format!("{} {}", prefix, key),
185            None => key,
186        };
187        req_builder = req_builder.header("X-Tapis-Token", value);
188    };
189
190    let req = req_builder.build()?;
191    let resp = configuration.client.execute(req).await?;
192
193    let status = resp.status();
194    let content_type = resp
195        .headers()
196        .get("content-type")
197        .and_then(|v| v.to_str().ok())
198        .unwrap_or("application/octet-stream");
199    let content_type = super::ContentType::from(content_type);
200
201    if !status.is_client_error() && !status.is_server_error() {
202        let content = resp.text().await?;
203        match content_type {
204            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
205            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateClient201Response`"))),
206            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateClient201Response`")))),
207        }
208    } else {
209        let content = resp.text().await?;
210        let entity: Option<GetClientError> = serde_json::from_str(&content).ok();
211        Err(Error::ResponseError(ResponseContent {
212            status,
213            content,
214            entity,
215        }))
216    }
217}
218
219pub async fn list_clients(
220    configuration: &configuration::Configuration,
221    limit: Option<i32>,
222    offset: Option<i32>,
223) -> Result<models::ListClients200Response, Error<ListClientsError>> {
224    // add a prefix to parameters to efficiently prevent name collisions
225    let p_query_limit = limit;
226    let p_query_offset = offset;
227
228    let uri_str = format!("{}/v3/oauth2/clients", configuration.base_path);
229    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
230
231    if let Some(ref param_value) = p_query_limit {
232        req_builder = req_builder.query(&[("limit", &param_value.to_string())]);
233    }
234    if let Some(ref param_value) = p_query_offset {
235        req_builder = req_builder.query(&[("offset", &param_value.to_string())]);
236    }
237    if let Some(ref user_agent) = configuration.user_agent {
238        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
239    }
240    if let Some(ref apikey) = configuration.api_key {
241        let key = apikey.key.clone();
242        let value = match apikey.prefix {
243            Some(ref prefix) => format!("{} {}", prefix, key),
244            None => key,
245        };
246        req_builder = req_builder.header("X-Tapis-Token", value);
247    };
248
249    let req = req_builder.build()?;
250    let resp = configuration.client.execute(req).await?;
251
252    let status = resp.status();
253    let content_type = resp
254        .headers()
255        .get("content-type")
256        .and_then(|v| v.to_str().ok())
257        .unwrap_or("application/octet-stream");
258    let content_type = super::ContentType::from(content_type);
259
260    if !status.is_client_error() && !status.is_server_error() {
261        let content = resp.text().await?;
262        match content_type {
263            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
264            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListClients200Response`"))),
265            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListClients200Response`")))),
266        }
267    } else {
268        let content = resp.text().await?;
269        let entity: Option<ListClientsError> = serde_json::from_str(&content).ok();
270        Err(Error::ResponseError(ResponseContent {
271            status,
272            content,
273            entity,
274        }))
275    }
276}
277
278/// Update details of a specific client by its id.
279pub async fn update_client(
280    configuration: &configuration::Configuration,
281    client_id: &str,
282    update_client: models::UpdateClient,
283) -> Result<models::CreateClient201Response, Error<UpdateClientError>> {
284    // add a prefix to parameters to efficiently prevent name collisions
285    let p_path_client_id = client_id;
286    let p_body_update_client = update_client;
287
288    let uri_str = format!(
289        "{}/v3/oauth2/clients/{client_id}",
290        configuration.base_path,
291        client_id = crate::apis::urlencode(p_path_client_id)
292    );
293    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
294
295    if let Some(ref user_agent) = configuration.user_agent {
296        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
297    }
298    if let Some(ref apikey) = configuration.api_key {
299        let key = apikey.key.clone();
300        let value = match apikey.prefix {
301            Some(ref prefix) => format!("{} {}", prefix, key),
302            None => key,
303        };
304        req_builder = req_builder.header("X-Tapis-Token", value);
305    };
306    req_builder = req_builder.json(&p_body_update_client);
307
308    let req = req_builder.build()?;
309    let resp = configuration.client.execute(req).await?;
310
311    let status = resp.status();
312    let content_type = resp
313        .headers()
314        .get("content-type")
315        .and_then(|v| v.to_str().ok())
316        .unwrap_or("application/octet-stream");
317    let content_type = super::ContentType::from(content_type);
318
319    if !status.is_client_error() && !status.is_server_error() {
320        let content = resp.text().await?;
321        match content_type {
322            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
323            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::CreateClient201Response`"))),
324            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::CreateClient201Response`")))),
325        }
326    } else {
327        let content = resp.text().await?;
328        let entity: Option<UpdateClientError> = serde_json::from_str(&content).ok();
329        Err(Error::ResponseError(ResponseContent {
330            status,
331            content,
332            entity,
333        }))
334    }
335}