Skip to main content

tapis_apps/apis/
sharing_api.rs

1/*
2 * Tapis Applications API
3 *
4 * The Tapis Applications API provides for management of Tapis applications including permissions.
5 *
6 * The version of the OpenAPI document: 25Q4.0
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_share_info`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum GetShareInfoError {
20    Status400(models::RespBasic),
21    Status403(models::RespBasic),
22    Status404(models::RespBasic),
23    Status500(models::RespBasic),
24    UnknownValue(serde_json::Value),
25}
26
27/// struct for typed errors of method [`share_app`]
28#[derive(Debug, Clone, Serialize, Deserialize)]
29#[serde(untagged)]
30pub enum ShareAppError {
31    Status400(models::RespBasic),
32    Status403(models::RespBasic),
33    Status500(models::RespBasic),
34    UnknownValue(serde_json::Value),
35}
36
37/// struct for typed errors of method [`share_app_public`]
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(untagged)]
40pub enum ShareAppPublicError {
41    Status403(models::RespBasic),
42    Status500(models::RespBasic),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`un_share_app`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum UnShareAppError {
50    Status400(models::RespBasic),
51    Status403(models::RespBasic),
52    Status500(models::RespBasic),
53    UnknownValue(serde_json::Value),
54}
55
56/// struct for typed errors of method [`un_share_app_public`]
57#[derive(Debug, Clone, Serialize, Deserialize)]
58#[serde(untagged)]
59pub enum UnShareAppPublicError {
60    Status403(models::RespBasic),
61    Status500(models::RespBasic),
62    UnknownValue(serde_json::Value),
63}
64
65/// Retrieve all sharing information for an app. This includes all users with whom the app has been shared and whether or not the app has been made publicly available.
66pub async fn get_share_info(
67    configuration: &configuration::Configuration,
68    app_id: &str,
69) -> Result<models::RespShareInfo, Error<GetShareInfoError>> {
70    // add a prefix to parameters to efficiently prevent name collisions
71    let p_path_app_id = app_id;
72
73    let uri_str = format!(
74        "{}/v3/apps/share/{appId}",
75        configuration.base_path,
76        appId = crate::apis::urlencode(p_path_app_id)
77    );
78    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
79
80    if let Some(ref user_agent) = configuration.user_agent {
81        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
82    }
83    if let Some(ref apikey) = configuration.api_key {
84        let key = apikey.key.clone();
85        let value = match apikey.prefix {
86            Some(ref prefix) => format!("{} {}", prefix, key),
87            None => key,
88        };
89        req_builder = req_builder.header("X-Tapis-Token", value);
90    };
91
92    let req = req_builder.build()?;
93    let resp = configuration.client.execute(req).await?;
94
95    let status = resp.status();
96    let content_type = resp
97        .headers()
98        .get("content-type")
99        .and_then(|v| v.to_str().ok())
100        .unwrap_or("application/octet-stream");
101    let content_type = super::ContentType::from(content_type);
102
103    if !status.is_client_error() && !status.is_server_error() {
104        let content = resp.text().await?;
105        match content_type {
106            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
107            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespShareInfo`"))),
108            ContentType::Unsupported(unknown_type) => Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::RespShareInfo`")))),
109        }
110    } else {
111        let content = resp.text().await?;
112        let entity: Option<GetShareInfoError> = serde_json::from_str(&content).ok();
113        Err(Error::ResponseError(ResponseContent {
114            status,
115            content,
116            entity,
117        }))
118    }
119}
120
121/// Create or update sharing information for an app. The app will be shared with the list of users provided in the request body. Requester must be owner of the app.
122pub async fn share_app(
123    configuration: &configuration::Configuration,
124    app_id: &str,
125    req_share_update: models::ReqShareUpdate,
126) -> Result<models::RespBasic, Error<ShareAppError>> {
127    // add a prefix to parameters to efficiently prevent name collisions
128    let p_path_app_id = app_id;
129    let p_body_req_share_update = req_share_update;
130
131    let uri_str = format!(
132        "{}/v3/apps/share/{appId}",
133        configuration.base_path,
134        appId = crate::apis::urlencode(p_path_app_id)
135    );
136    let mut req_builder = configuration
137        .client
138        .request(reqwest::Method::POST, &uri_str);
139
140    if let Some(ref user_agent) = configuration.user_agent {
141        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
142    }
143    if let Some(ref apikey) = configuration.api_key {
144        let key = apikey.key.clone();
145        let value = match apikey.prefix {
146            Some(ref prefix) => format!("{} {}", prefix, key),
147            None => key,
148        };
149        req_builder = req_builder.header("X-Tapis-Token", value);
150    };
151    req_builder = req_builder.json(&p_body_req_share_update);
152
153    let req = req_builder.build()?;
154    let resp = configuration.client.execute(req).await?;
155
156    let status = resp.status();
157    let content_type = resp
158        .headers()
159        .get("content-type")
160        .and_then(|v| v.to_str().ok())
161        .unwrap_or("application/octet-stream");
162    let content_type = super::ContentType::from(content_type);
163
164    if !status.is_client_error() && !status.is_server_error() {
165        let content = resp.text().await?;
166        match content_type {
167            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
168            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespBasic`"))),
169            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`")))),
170        }
171    } else {
172        let content = resp.text().await?;
173        let entity: Option<ShareAppError> = serde_json::from_str(&content).ok();
174        Err(Error::ResponseError(ResponseContent {
175            status,
176            content,
177            entity,
178        }))
179    }
180}
181
182/// Share an app with all users in the tenant. Requester must be owner of the app.
183pub async fn share_app_public(
184    configuration: &configuration::Configuration,
185    app_id: &str,
186) -> Result<models::RespBasic, Error<ShareAppPublicError>> {
187    // add a prefix to parameters to efficiently prevent name collisions
188    let p_path_app_id = app_id;
189
190    let uri_str = format!(
191        "{}/v3/apps/share_public/{appId}",
192        configuration.base_path,
193        appId = crate::apis::urlencode(p_path_app_id)
194    );
195    let mut req_builder = configuration
196        .client
197        .request(reqwest::Method::POST, &uri_str);
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 apikey) = configuration.api_key {
203        let key = apikey.key.clone();
204        let value = match apikey.prefix {
205            Some(ref prefix) => format!("{} {}", prefix, key),
206            None => key,
207        };
208        req_builder = req_builder.header("X-Tapis-Token", value);
209    };
210
211    let req = req_builder.build()?;
212    let resp = configuration.client.execute(req).await?;
213
214    let status = resp.status();
215    let content_type = resp
216        .headers()
217        .get("content-type")
218        .and_then(|v| v.to_str().ok())
219        .unwrap_or("application/octet-stream");
220    let content_type = super::ContentType::from(content_type);
221
222    if !status.is_client_error() && !status.is_server_error() {
223        let content = resp.text().await?;
224        match content_type {
225            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
226            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespBasic`"))),
227            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`")))),
228        }
229    } else {
230        let content = resp.text().await?;
231        let entity: Option<ShareAppPublicError> = serde_json::from_str(&content).ok();
232        Err(Error::ResponseError(ResponseContent {
233            status,
234            content,
235            entity,
236        }))
237    }
238}
239
240/// Create or update sharing information for an app. The app will be unshared with the list of users provided in the request body. Requester must be owner of the app.
241pub async fn un_share_app(
242    configuration: &configuration::Configuration,
243    app_id: &str,
244    req_share_update: models::ReqShareUpdate,
245) -> Result<models::RespBasic, Error<UnShareAppError>> {
246    // add a prefix to parameters to efficiently prevent name collisions
247    let p_path_app_id = app_id;
248    let p_body_req_share_update = req_share_update;
249
250    let uri_str = format!(
251        "{}/v3/apps/unshare/{appId}",
252        configuration.base_path,
253        appId = crate::apis::urlencode(p_path_app_id)
254    );
255    let mut req_builder = configuration
256        .client
257        .request(reqwest::Method::POST, &uri_str);
258
259    if let Some(ref user_agent) = configuration.user_agent {
260        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
261    }
262    if let Some(ref apikey) = configuration.api_key {
263        let key = apikey.key.clone();
264        let value = match apikey.prefix {
265            Some(ref prefix) => format!("{} {}", prefix, key),
266            None => key,
267        };
268        req_builder = req_builder.header("X-Tapis-Token", value);
269    };
270    req_builder = req_builder.json(&p_body_req_share_update);
271
272    let req = req_builder.build()?;
273    let resp = configuration.client.execute(req).await?;
274
275    let status = resp.status();
276    let content_type = resp
277        .headers()
278        .get("content-type")
279        .and_then(|v| v.to_str().ok())
280        .unwrap_or("application/octet-stream");
281    let content_type = super::ContentType::from(content_type);
282
283    if !status.is_client_error() && !status.is_server_error() {
284        let content = resp.text().await?;
285        match content_type {
286            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
287            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespBasic`"))),
288            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`")))),
289        }
290    } else {
291        let content = resp.text().await?;
292        let entity: Option<UnShareAppError> = serde_json::from_str(&content).ok();
293        Err(Error::ResponseError(ResponseContent {
294            status,
295            content,
296            entity,
297        }))
298    }
299}
300
301/// Remove public sharing for an app. Requester must be owner of the app.
302pub async fn un_share_app_public(
303    configuration: &configuration::Configuration,
304    app_id: &str,
305) -> Result<models::RespBasic, Error<UnShareAppPublicError>> {
306    // add a prefix to parameters to efficiently prevent name collisions
307    let p_path_app_id = app_id;
308
309    let uri_str = format!(
310        "{}/v3/apps/unshare_public/{appId}",
311        configuration.base_path,
312        appId = crate::apis::urlencode(p_path_app_id)
313    );
314    let mut req_builder = configuration
315        .client
316        .request(reqwest::Method::POST, &uri_str);
317
318    if let Some(ref user_agent) = configuration.user_agent {
319        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
320    }
321    if let Some(ref apikey) = configuration.api_key {
322        let key = apikey.key.clone();
323        let value = match apikey.prefix {
324            Some(ref prefix) => format!("{} {}", prefix, key),
325            None => key,
326        };
327        req_builder = req_builder.header("X-Tapis-Token", value);
328    };
329
330    let req = req_builder.build()?;
331    let resp = configuration.client.execute(req).await?;
332
333    let status = resp.status();
334    let content_type = resp
335        .headers()
336        .get("content-type")
337        .and_then(|v| v.to_str().ok())
338        .unwrap_or("application/octet-stream");
339    let content_type = super::ContentType::from(content_type);
340
341    if !status.is_client_error() && !status.is_server_error() {
342        let content = resp.text().await?;
343        match content_type {
344            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
345            ContentType::Text => Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::RespBasic`"))),
346            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`")))),
347        }
348    } else {
349        let content = resp.text().await?;
350        let entity: Option<UnShareAppPublicError> = serde_json::from_str(&content).ok();
351        Err(Error::ResponseError(ResponseContent {
352            status,
353            content,
354            entity,
355        }))
356    }
357}