1use 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 GetUserPermsError {
20 Status400(models::RespBasic),
21 Status403(models::RespBasic),
22 Status404(models::RespBasic),
23 Status500(models::RespBasic),
24 UnknownValue(serde_json::Value),
25}
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum GrantUserPermsError {
31 Status400(models::RespBasic),
32 Status403(models::RespBasic),
33 Status500(models::RespBasic),
34 UnknownValue(serde_json::Value),
35}
36
37#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum RevokeUserPermError {
41 Status400(models::RespBasic),
42 Status403(models::RespBasic),
43 Status500(models::RespBasic),
44 UnknownValue(serde_json::Value),
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
49#[serde(untagged)]
50pub enum RevokeUserPermsError {
51 Status403(models::RespBasic),
52 Status500(models::RespBasic),
53 UnknownValue(serde_json::Value),
54}
55
56pub async fn get_user_perms(
58 configuration: &configuration::Configuration,
59 app_id: &str,
60 user_name: &str,
61) -> Result<models::RespNameArray, Error<GetUserPermsError>> {
62 let p_path_app_id = app_id;
64 let p_path_user_name = user_name;
65
66 let uri_str = format!(
67 "{}/v3/apps/perms/{appId}/user/{userName}",
68 configuration.base_path,
69 appId = crate::apis::urlencode(p_path_app_id),
70 userName = crate::apis::urlencode(p_path_user_name)
71 );
72 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
73
74 if let Some(ref user_agent) = configuration.user_agent {
75 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
76 }
77 if let Some(ref apikey) = configuration.api_key {
78 let key = apikey.key.clone();
79 let value = match apikey.prefix {
80 Some(ref prefix) => format!("{} {}", prefix, key),
81 None => key,
82 };
83 req_builder = req_builder.header("X-Tapis-Token", value);
84 };
85
86 let req = req_builder.build()?;
87 let resp = configuration.client.execute(req).await?;
88
89 let status = resp.status();
90 let content_type = resp
91 .headers()
92 .get("content-type")
93 .and_then(|v| v.to_str().ok())
94 .unwrap_or("application/octet-stream");
95 let content_type = super::ContentType::from(content_type);
96
97 if !status.is_client_error() && !status.is_server_error() {
98 let content = resp.text().await?;
99 match content_type {
100 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
101 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespNameArray`"))),
102 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespNameArray`")))),
103 }
104 } else {
105 let content = resp.text().await?;
106 let entity: Option<GetUserPermsError> = serde_json::from_str(&content).ok();
107 Err(Error::ResponseError(ResponseContent {
108 status,
109 content,
110 entity,
111 }))
112 }
113}
114
115pub async fn grant_user_perms(
117 configuration: &configuration::Configuration,
118 app_id: &str,
119 user_name: &str,
120 req_perms: models::ReqPerms,
121) -> Result<models::RespBasic, Error<GrantUserPermsError>> {
122 let p_path_app_id = app_id;
124 let p_path_user_name = user_name;
125 let p_body_req_perms = req_perms;
126
127 let uri_str = format!(
128 "{}/v3/apps/perms/{appId}/user/{userName}",
129 configuration.base_path,
130 appId = crate::apis::urlencode(p_path_app_id),
131 userName = crate::apis::urlencode(p_path_user_name)
132 );
133 let mut req_builder = configuration
134 .client
135 .request(reqwest::Method::POST, &uri_str);
136
137 if let Some(ref user_agent) = configuration.user_agent {
138 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
139 }
140 if let Some(ref apikey) = configuration.api_key {
141 let key = apikey.key.clone();
142 let value = match apikey.prefix {
143 Some(ref prefix) => format!("{} {}", prefix, key),
144 None => key,
145 };
146 req_builder = req_builder.header("X-Tapis-Token", value);
147 };
148 req_builder = req_builder.json(&p_body_req_perms);
149
150 let req = req_builder.build()?;
151 let resp = configuration.client.execute(req).await?;
152
153 let status = resp.status();
154 let content_type = resp
155 .headers()
156 .get("content-type")
157 .and_then(|v| v.to_str().ok())
158 .unwrap_or("application/octet-stream");
159 let content_type = super::ContentType::from(content_type);
160
161 if !status.is_client_error() && !status.is_server_error() {
162 let content = resp.text().await?;
163 match content_type {
164 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
165 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespBasic`"))),
166 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespBasic`")))),
167 }
168 } else {
169 let content = resp.text().await?;
170 let entity: Option<GrantUserPermsError> = serde_json::from_str(&content).ok();
171 Err(Error::ResponseError(ResponseContent {
172 status,
173 content,
174 entity,
175 }))
176 }
177}
178
179pub async fn revoke_user_perm(
181 configuration: &configuration::Configuration,
182 app_id: &str,
183 user_name: &str,
184 permission: &str,
185) -> Result<models::RespBasic, Error<RevokeUserPermError>> {
186 let p_path_app_id = app_id;
188 let p_path_user_name = user_name;
189 let p_path_permission = permission;
190
191 let uri_str = format!(
192 "{}/v3/apps/perms/{appId}/user/{userName}/{permission}",
193 configuration.base_path,
194 appId = crate::apis::urlencode(p_path_app_id),
195 userName = crate::apis::urlencode(p_path_user_name),
196 permission = crate::apis::urlencode(p_path_permission)
197 );
198 let mut req_builder = configuration
199 .client
200 .request(reqwest::Method::DELETE, &uri_str);
201
202 if let Some(ref user_agent) = configuration.user_agent {
203 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
204 }
205 if let Some(ref apikey) = configuration.api_key {
206 let key = apikey.key.clone();
207 let value = match apikey.prefix {
208 Some(ref prefix) => format!("{} {}", prefix, key),
209 None => key,
210 };
211 req_builder = req_builder.header("X-Tapis-Token", value);
212 };
213
214 let req = req_builder.build()?;
215 let resp = configuration.client.execute(req).await?;
216
217 let status = resp.status();
218 let content_type = resp
219 .headers()
220 .get("content-type")
221 .and_then(|v| v.to_str().ok())
222 .unwrap_or("application/octet-stream");
223 let content_type = super::ContentType::from(content_type);
224
225 if !status.is_client_error() && !status.is_server_error() {
226 let content = resp.text().await?;
227 match content_type {
228 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
229 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespBasic`"))),
230 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespBasic`")))),
231 }
232 } else {
233 let content = resp.text().await?;
234 let entity: Option<RevokeUserPermError> = serde_json::from_str(&content).ok();
235 Err(Error::ResponseError(ResponseContent {
236 status,
237 content,
238 entity,
239 }))
240 }
241}
242
243pub async fn revoke_user_perms(
245 configuration: &configuration::Configuration,
246 app_id: &str,
247 user_name: &str,
248 req_perms: models::ReqPerms,
249) -> Result<models::RespBasic, Error<RevokeUserPermsError>> {
250 let p_path_app_id = app_id;
252 let p_path_user_name = user_name;
253 let p_body_req_perms = req_perms;
254
255 let uri_str = format!(
256 "{}/v3/apps/perms/{appId}/user/{userName}/revoke",
257 configuration.base_path,
258 appId = crate::apis::urlencode(p_path_app_id),
259 userName = crate::apis::urlencode(p_path_user_name)
260 );
261 let mut req_builder = configuration
262 .client
263 .request(reqwest::Method::POST, &uri_str);
264
265 if let Some(ref user_agent) = configuration.user_agent {
266 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
267 }
268 if let Some(ref apikey) = configuration.api_key {
269 let key = apikey.key.clone();
270 let value = match apikey.prefix {
271 Some(ref prefix) => format!("{} {}", prefix, key),
272 None => key,
273 };
274 req_builder = req_builder.header("X-Tapis-Token", value);
275 };
276 req_builder = req_builder.json(&p_body_req_perms);
277
278 let req = req_builder.build()?;
279 let resp = configuration.client.execute(req).await?;
280
281 let status = resp.status();
282 let content_type = resp
283 .headers()
284 .get("content-type")
285 .and_then(|v| v.to_str().ok())
286 .unwrap_or("application/octet-stream");
287 let content_type = super::ContentType::from(content_type);
288
289 if !status.is_client_error() && !status.is_server_error() {
290 let content = resp.text().await?;
291 match content_type {
292 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
293 ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespBasic`"))),
294 ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespBasic`")))),
295 }
296 } else {
297 let content = resp.text().await?;
298 let entity: Option<RevokeUserPermsError> = serde_json::from_str(&content).ok();
299 Err(Error::ResponseError(ResponseContent {
300 status,
301 content,
302 entity,
303 }))
304 }
305}