Skip to main content

tapis_authenticator/apis/
admin_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 [`get_config`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum GetConfigError {
20    UnknownValue(serde_json::Value),
21}
22
23/// struct for typed errors of method [`update_config`]
24#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(untagged)]
26pub enum UpdateConfigError {
27    UnknownValue(serde_json::Value),
28}
29
30/// Get the authenticator configuraion for the tenant; restricted to Tenant admins.
31pub async fn get_config(
32    configuration: &configuration::Configuration,
33) -> Result<models::GetConfig200Response, Error<GetConfigError>> {
34    let uri_str = format!("{}/v3/oauth2/admin/config", configuration.base_path);
35    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
36
37    if let Some(ref user_agent) = configuration.user_agent {
38        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
39    }
40    if let Some(ref apikey) = configuration.api_key {
41        let key = apikey.key.clone();
42        let value = match apikey.prefix {
43            Some(ref prefix) => format!("{} {}", prefix, key),
44            None => key,
45        };
46        req_builder = req_builder.header("X-Tapis-Token", value);
47    };
48
49    let req = req_builder.build()?;
50    let resp = configuration.client.execute(req).await?;
51
52    let status = resp.status();
53    let content_type = resp
54        .headers()
55        .get("content-type")
56        .and_then(|v| v.to_str().ok())
57        .unwrap_or("application/octet-stream");
58    let content_type = super::ContentType::from(content_type);
59
60    if !status.is_client_error() && !status.is_server_error() {
61        let content = resp.text().await?;
62        match content_type {
63            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
64            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetConfig200Response`"))),
65            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetConfig200Response`")))),
66        }
67    } else {
68        let content = resp.text().await?;
69        let entity: Option<GetConfigError> = serde_json::from_str(&content).ok();
70        Err(Error::ResponseError(ResponseContent {
71            status,
72            content,
73            entity,
74        }))
75    }
76}
77
78/// Update the authenticator configuraion for the tenant; restricted to Tenant admins.
79pub async fn update_config(
80    configuration: &configuration::Configuration,
81    new_tenant_config: models::NewTenantConfig,
82) -> Result<models::GetConfig200Response, Error<UpdateConfigError>> {
83    // add a prefix to parameters to efficiently prevent name collisions
84    let p_body_new_tenant_config = new_tenant_config;
85
86    let uri_str = format!("{}/v3/oauth2/admin/config", configuration.base_path);
87    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
88
89    if let Some(ref user_agent) = configuration.user_agent {
90        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
91    }
92    if let Some(ref apikey) = configuration.api_key {
93        let key = apikey.key.clone();
94        let value = match apikey.prefix {
95            Some(ref prefix) => format!("{} {}", prefix, key),
96            None => key,
97        };
98        req_builder = req_builder.header("X-Tapis-Token", value);
99    };
100    req_builder = req_builder.json(&p_body_new_tenant_config);
101
102    let req = req_builder.build()?;
103    let resp = configuration.client.execute(req).await?;
104
105    let status = resp.status();
106    let content_type = resp
107        .headers()
108        .get("content-type")
109        .and_then(|v| v.to_str().ok())
110        .unwrap_or("application/octet-stream");
111    let content_type = super::ContentType::from(content_type);
112
113    if !status.is_client_error() && !status.is_server_error() {
114        let content = resp.text().await?;
115        match content_type {
116            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
117            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetConfig200Response`"))),
118            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetConfig200Response`")))),
119        }
120    } else {
121        let content = resp.text().await?;
122        let entity: Option<UpdateConfigError> = serde_json::from_str(&content).ok();
123        Err(Error::ResponseError(ResponseContent {
124            status,
125            content,
126            entity,
127        }))
128    }
129}