tapis_authenticator/apis/
profiles_api.rs1use super::{configuration, ContentType, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{de::Error as _, Deserialize, Serialize};
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum GetProfileError {
20 UnknownValue(serde_json::Value),
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(untagged)]
26pub enum GetUserinfoError {
27 UnknownValue(serde_json::Value),
28}
29
30#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(untagged)]
33pub enum ListProfilesError {
34 UnknownValue(serde_json::Value),
35}
36
37pub async fn get_profile(
38 configuration: &configuration::Configuration,
39 username: &str,
40) -> Result<models::GetUserinfo200Response, Error<GetProfileError>> {
41 let p_path_username = username;
43
44 let uri_str = format!(
45 "{}/v3/oauth2/profiles/{username}",
46 configuration.base_path,
47 username = crate::apis::urlencode(p_path_username)
48 );
49 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
50
51 if let Some(ref user_agent) = configuration.user_agent {
52 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
53 }
54 if let Some(ref apikey) = configuration.api_key {
55 let key = apikey.key.clone();
56 let value = match apikey.prefix {
57 Some(ref prefix) => format!("{} {}", prefix, key),
58 None => key,
59 };
60 req_builder = req_builder.header("X-Tapis-Token", value);
61 };
62
63 let req = req_builder.build()?;
64 let resp = configuration.client.execute(req).await?;
65
66 let status = resp.status();
67 let content_type = resp
68 .headers()
69 .get("content-type")
70 .and_then(|v| v.to_str().ok())
71 .unwrap_or("application/octet-stream");
72 let content_type = super::ContentType::from(content_type);
73
74 if !status.is_client_error() && !status.is_server_error() {
75 let content = resp.text().await?;
76 match content_type {
77 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
78 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetUserinfo200Response`"))),
79 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetUserinfo200Response`")))),
80 }
81 } else {
82 let content = resp.text().await?;
83 let entity: Option<GetProfileError> = serde_json::from_str(&content).ok();
84 Err(Error::ResponseError(ResponseContent {
85 status,
86 content,
87 entity,
88 }))
89 }
90}
91
92pub async fn get_userinfo(
94 configuration: &configuration::Configuration,
95) -> Result<models::GetUserinfo200Response, Error<GetUserinfoError>> {
96 let uri_str = format!("{}/v3/oauth2/userinfo", configuration.base_path);
97 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
98
99 if let Some(ref user_agent) = configuration.user_agent {
100 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
101 }
102 if let Some(ref apikey) = configuration.api_key {
103 let key = apikey.key.clone();
104 let value = match apikey.prefix {
105 Some(ref prefix) => format!("{} {}", prefix, key),
106 None => key,
107 };
108 req_builder = req_builder.header("X-Tapis-Token", value);
109 };
110
111 let req = req_builder.build()?;
112 let resp = configuration.client.execute(req).await?;
113
114 let status = resp.status();
115 let content_type = resp
116 .headers()
117 .get("content-type")
118 .and_then(|v| v.to_str().ok())
119 .unwrap_or("application/octet-stream");
120 let content_type = super::ContentType::from(content_type);
121
122 if !status.is_client_error() && !status.is_server_error() {
123 let content = resp.text().await?;
124 match content_type {
125 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
126 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::GetUserinfo200Response`"))),
127 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::GetUserinfo200Response`")))),
128 }
129 } else {
130 let content = resp.text().await?;
131 let entity: Option<GetUserinfoError> = serde_json::from_str(&content).ok();
132 Err(Error::ResponseError(ResponseContent {
133 status,
134 content,
135 entity,
136 }))
137 }
138}
139
140pub async fn list_profiles(
141 configuration: &configuration::Configuration,
142 limit: Option<i32>,
143 offset: Option<i32>,
144) -> Result<models::ListProfiles200Response, Error<ListProfilesError>> {
145 let p_query_limit = limit;
147 let p_query_offset = offset;
148
149 let uri_str = format!("{}/v3/oauth2/profiles", configuration.base_path);
150 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
151
152 if let Some(ref param_value) = p_query_limit {
153 req_builder = req_builder.query(&[("limit", ¶m_value.to_string())]);
154 }
155 if let Some(ref param_value) = p_query_offset {
156 req_builder = req_builder.query(&[("offset", ¶m_value.to_string())]);
157 }
158 if let Some(ref user_agent) = configuration.user_agent {
159 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
160 }
161 if let Some(ref apikey) = configuration.api_key {
162 let key = apikey.key.clone();
163 let value = match apikey.prefix {
164 Some(ref prefix) => format!("{} {}", prefix, key),
165 None => key,
166 };
167 req_builder = req_builder.header("X-Tapis-Token", value);
168 };
169
170 let req = req_builder.build()?;
171 let resp = configuration.client.execute(req).await?;
172
173 let status = resp.status();
174 let content_type = resp
175 .headers()
176 .get("content-type")
177 .and_then(|v| v.to_str().ok())
178 .unwrap_or("application/octet-stream");
179 let content_type = super::ContentType::from(content_type);
180
181 if !status.is_client_error() && !status.is_server_error() {
182 let content = resp.text().await?;
183 match content_type {
184 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
185 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ListProfiles200Response`"))),
186 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ListProfiles200Response`")))),
187 }
188 } else {
189 let content = resp.text().await?;
190 let entity: Option<ListProfilesError> = serde_json::from_str(&content).ok();
191 Err(Error::ResponseError(ResponseContent {
192 status,
193 content,
194 entity,
195 }))
196 }
197}