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: 26Q1.0
7 * Contact: cicsupport@tacc.utexas.edu
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{ContentType, Error, configuration};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize, de::Error as _};
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(
108                "Received `text/plain` content type response that cannot be converted to `models::RespShareInfo`",
109            ))),
110            ContentType::Unsupported(unknown_type) => {
111                Err(Error::from(serde_json::Error::custom(format!(
112                    "Received `{unknown_type}` content type response that cannot be converted to `models::RespShareInfo`"
113                ))))
114            }
115        }
116    } else {
117        let content = resp.text().await?;
118        let entity: Option<GetShareInfoError> = serde_json::from_str(&content).ok();
119        Err(Error::ResponseError(ResponseContent {
120            status,
121            content,
122            entity,
123        }))
124    }
125}
126
127/// 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.
128pub async fn share_app(
129    configuration: &configuration::Configuration,
130    app_id: &str,
131    req_share_update: models::ReqShareUpdate,
132) -> Result<models::RespBasic, Error<ShareAppError>> {
133    // add a prefix to parameters to efficiently prevent name collisions
134    let p_path_app_id = app_id;
135    let p_body_req_share_update = req_share_update;
136
137    let uri_str = format!(
138        "{}/v3/apps/share/{appId}",
139        configuration.base_path,
140        appId = crate::apis::urlencode(p_path_app_id)
141    );
142    let mut req_builder = configuration
143        .client
144        .request(reqwest::Method::POST, &uri_str);
145
146    if let Some(ref user_agent) = configuration.user_agent {
147        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
148    }
149    if let Some(ref apikey) = configuration.api_key {
150        let key = apikey.key.clone();
151        let value = match apikey.prefix {
152            Some(ref prefix) => format!("{} {}", prefix, key),
153            None => key,
154        };
155        req_builder = req_builder.header("X-Tapis-Token", value);
156    };
157    req_builder = req_builder.json(&p_body_req_share_update);
158
159    let req = req_builder.build()?;
160    let resp = configuration.client.execute(req).await?;
161
162    let status = resp.status();
163    let content_type = resp
164        .headers()
165        .get("content-type")
166        .and_then(|v| v.to_str().ok())
167        .unwrap_or("application/octet-stream");
168    let content_type = super::ContentType::from(content_type);
169
170    if !status.is_client_error() && !status.is_server_error() {
171        let content = resp.text().await?;
172        match content_type {
173            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
174            ContentType::Text => Err(Error::from(serde_json::Error::custom(
175                "Received `text/plain` content type response that cannot be converted to `models::RespBasic`",
176            ))),
177            ContentType::Unsupported(unknown_type) => {
178                Err(Error::from(serde_json::Error::custom(format!(
179                    "Received `{unknown_type}` content type response that cannot be converted to `models::RespBasic`"
180                ))))
181            }
182        }
183    } else {
184        let content = resp.text().await?;
185        let entity: Option<ShareAppError> = serde_json::from_str(&content).ok();
186        Err(Error::ResponseError(ResponseContent {
187            status,
188            content,
189            entity,
190        }))
191    }
192}
193
194/// Share an app with all users in the tenant. Requester must be owner of the app.
195pub async fn share_app_public(
196    configuration: &configuration::Configuration,
197    app_id: &str,
198) -> Result<models::RespBasic, Error<ShareAppPublicError>> {
199    // add a prefix to parameters to efficiently prevent name collisions
200    let p_path_app_id = app_id;
201
202    let uri_str = format!(
203        "{}/v3/apps/share_public/{appId}",
204        configuration.base_path,
205        appId = crate::apis::urlencode(p_path_app_id)
206    );
207    let mut req_builder = configuration
208        .client
209        .request(reqwest::Method::POST, &uri_str);
210
211    if let Some(ref user_agent) = configuration.user_agent {
212        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
213    }
214    if let Some(ref apikey) = configuration.api_key {
215        let key = apikey.key.clone();
216        let value = match apikey.prefix {
217            Some(ref prefix) => format!("{} {}", prefix, key),
218            None => key,
219        };
220        req_builder = req_builder.header("X-Tapis-Token", value);
221    };
222
223    let req = req_builder.build()?;
224    let resp = configuration.client.execute(req).await?;
225
226    let status = resp.status();
227    let content_type = resp
228        .headers()
229        .get("content-type")
230        .and_then(|v| v.to_str().ok())
231        .unwrap_or("application/octet-stream");
232    let content_type = super::ContentType::from(content_type);
233
234    if !status.is_client_error() && !status.is_server_error() {
235        let content = resp.text().await?;
236        match content_type {
237            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
238            ContentType::Text => Err(Error::from(serde_json::Error::custom(
239                "Received `text/plain` content type response that cannot be converted to `models::RespBasic`",
240            ))),
241            ContentType::Unsupported(unknown_type) => {
242                Err(Error::from(serde_json::Error::custom(format!(
243                    "Received `{unknown_type}` content type response that cannot be converted to `models::RespBasic`"
244                ))))
245            }
246        }
247    } else {
248        let content = resp.text().await?;
249        let entity: Option<ShareAppPublicError> = serde_json::from_str(&content).ok();
250        Err(Error::ResponseError(ResponseContent {
251            status,
252            content,
253            entity,
254        }))
255    }
256}
257
258/// 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.
259pub async fn un_share_app(
260    configuration: &configuration::Configuration,
261    app_id: &str,
262    req_share_update: models::ReqShareUpdate,
263) -> Result<models::RespBasic, Error<UnShareAppError>> {
264    // add a prefix to parameters to efficiently prevent name collisions
265    let p_path_app_id = app_id;
266    let p_body_req_share_update = req_share_update;
267
268    let uri_str = format!(
269        "{}/v3/apps/unshare/{appId}",
270        configuration.base_path,
271        appId = crate::apis::urlencode(p_path_app_id)
272    );
273    let mut req_builder = configuration
274        .client
275        .request(reqwest::Method::POST, &uri_str);
276
277    if let Some(ref user_agent) = configuration.user_agent {
278        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
279    }
280    if let Some(ref apikey) = configuration.api_key {
281        let key = apikey.key.clone();
282        let value = match apikey.prefix {
283            Some(ref prefix) => format!("{} {}", prefix, key),
284            None => key,
285        };
286        req_builder = req_builder.header("X-Tapis-Token", value);
287    };
288    req_builder = req_builder.json(&p_body_req_share_update);
289
290    let req = req_builder.build()?;
291    let resp = configuration.client.execute(req).await?;
292
293    let status = resp.status();
294    let content_type = resp
295        .headers()
296        .get("content-type")
297        .and_then(|v| v.to_str().ok())
298        .unwrap_or("application/octet-stream");
299    let content_type = super::ContentType::from(content_type);
300
301    if !status.is_client_error() && !status.is_server_error() {
302        let content = resp.text().await?;
303        match content_type {
304            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
305            ContentType::Text => Err(Error::from(serde_json::Error::custom(
306                "Received `text/plain` content type response that cannot be converted to `models::RespBasic`",
307            ))),
308            ContentType::Unsupported(unknown_type) => {
309                Err(Error::from(serde_json::Error::custom(format!(
310                    "Received `{unknown_type}` content type response that cannot be converted to `models::RespBasic`"
311                ))))
312            }
313        }
314    } else {
315        let content = resp.text().await?;
316        let entity: Option<UnShareAppError> = serde_json::from_str(&content).ok();
317        Err(Error::ResponseError(ResponseContent {
318            status,
319            content,
320            entity,
321        }))
322    }
323}
324
325/// Remove public sharing for an app. Requester must be owner of the app.
326pub async fn un_share_app_public(
327    configuration: &configuration::Configuration,
328    app_id: &str,
329) -> Result<models::RespBasic, Error<UnShareAppPublicError>> {
330    // add a prefix to parameters to efficiently prevent name collisions
331    let p_path_app_id = app_id;
332
333    let uri_str = format!(
334        "{}/v3/apps/unshare_public/{appId}",
335        configuration.base_path,
336        appId = crate::apis::urlencode(p_path_app_id)
337    );
338    let mut req_builder = configuration
339        .client
340        .request(reqwest::Method::POST, &uri_str);
341
342    if let Some(ref user_agent) = configuration.user_agent {
343        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
344    }
345    if let Some(ref apikey) = configuration.api_key {
346        let key = apikey.key.clone();
347        let value = match apikey.prefix {
348            Some(ref prefix) => format!("{} {}", prefix, key),
349            None => key,
350        };
351        req_builder = req_builder.header("X-Tapis-Token", value);
352    };
353
354    let req = req_builder.build()?;
355    let resp = configuration.client.execute(req).await?;
356
357    let status = resp.status();
358    let content_type = resp
359        .headers()
360        .get("content-type")
361        .and_then(|v| v.to_str().ok())
362        .unwrap_or("application/octet-stream");
363    let content_type = super::ContentType::from(content_type);
364
365    if !status.is_client_error() && !status.is_server_error() {
366        let content = resp.text().await?;
367        match content_type {
368            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
369            ContentType::Text => Err(Error::from(serde_json::Error::custom(
370                "Received `text/plain` content type response that cannot be converted to `models::RespBasic`",
371            ))),
372            ContentType::Unsupported(unknown_type) => {
373                Err(Error::from(serde_json::Error::custom(format!(
374                    "Received `{unknown_type}` content type response that cannot be converted to `models::RespBasic`"
375                ))))
376            }
377        }
378    } else {
379        let content = resp.text().await?;
380        let entity: Option<UnShareAppPublicError> = serde_json::from_str(&content).ok();
381        Err(Error::ResponseError(ResponseContent {
382            status,
383            content,
384            entity,
385        }))
386    }
387}