spatio_sdk/apis/
resources_api.rs1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ListResourcePermissionGrantsError {
22 Status401(models::ApiError),
23 UnknownValue(serde_json::Value),
24}
25
26#[derive(Debug, Clone, Serialize, Deserialize)]
28#[serde(untagged)]
29pub enum RevokeResourcePermissionGrantError {
30 Status401(models::ApiError),
31 UnknownValue(serde_json::Value),
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum SetResourcePermissionGrantError {
38 Status401(models::ApiError),
39 UnknownValue(serde_json::Value),
40}
41
42
43pub async fn list_resource_permission_grants(configuration: &configuration::Configuration, platform: &str, resource_id: &str) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<ListResourcePermissionGrantsError>> {
44 let p_path_platform = platform;
46 let p_path_resource_id = resource_id;
47
48 let uri_str = format!("{}/v1/resources/{platform}/{resourceId}/permissions", configuration.base_path, platform=crate::apis::urlencode(p_path_platform), resourceId=crate::apis::urlencode(p_path_resource_id));
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 token) = configuration.bearer_access_token {
55 req_builder = req_builder.bearer_auth(token.to_owned());
56 };
57
58 let req = req_builder.build()?;
59 let resp = configuration.client.execute(req).await?;
60
61 let status = resp.status();
62 let content_type = resp
63 .headers()
64 .get("content-type")
65 .and_then(|v| v.to_str().ok())
66 .unwrap_or("application/octet-stream");
67 let content_type = super::ContentType::from(content_type);
68
69 if !status.is_client_error() && !status.is_server_error() {
70 let content = resp.text().await?;
71 match content_type {
72 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
73 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`"))),
74 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
75 }
76 } else {
77 let content = resp.text().await?;
78 let entity: Option<ListResourcePermissionGrantsError> = serde_json::from_str(&content).ok();
79 Err(Error::ResponseError(ResponseContent { status, content, entity }))
80 }
81}
82
83pub async fn revoke_resource_permission_grant(configuration: &configuration::Configuration, platform: &str, resource_id: &str, grant_id: &str) -> Result<(), Error<RevokeResourcePermissionGrantError>> {
84 let p_path_platform = platform;
86 let p_path_resource_id = resource_id;
87 let p_path_grant_id = grant_id;
88
89 let uri_str = format!("{}/v1/resources/{platform}/{resourceId}/permissions/{grantId}", configuration.base_path, platform=crate::apis::urlencode(p_path_platform), resourceId=crate::apis::urlencode(p_path_resource_id), grantId=crate::apis::urlencode(p_path_grant_id));
90 let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
91
92 if let Some(ref user_agent) = configuration.user_agent {
93 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
94 }
95 if let Some(ref token) = configuration.bearer_access_token {
96 req_builder = req_builder.bearer_auth(token.to_owned());
97 };
98
99 let req = req_builder.build()?;
100 let resp = configuration.client.execute(req).await?;
101
102 let status = resp.status();
103
104 if !status.is_client_error() && !status.is_server_error() {
105 Ok(())
106 } else {
107 let content = resp.text().await?;
108 let entity: Option<RevokeResourcePermissionGrantError> = serde_json::from_str(&content).ok();
109 Err(Error::ResponseError(ResponseContent { status, content, entity }))
110 }
111}
112
113pub async fn set_resource_permission_grant(configuration: &configuration::Configuration, platform: &str, resource_id: &str, request_body: std::collections::HashMap<String, serde_json::Value>) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<SetResourcePermissionGrantError>> {
114 let p_path_platform = platform;
116 let p_path_resource_id = resource_id;
117 let p_body_request_body = request_body;
118
119 let uri_str = format!("{}/v1/resources/{platform}/{resourceId}/permissions", configuration.base_path, platform=crate::apis::urlencode(p_path_platform), resourceId=crate::apis::urlencode(p_path_resource_id));
120 let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
121
122 if let Some(ref user_agent) = configuration.user_agent {
123 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
124 }
125 if let Some(ref token) = configuration.bearer_access_token {
126 req_builder = req_builder.bearer_auth(token.to_owned());
127 };
128 req_builder = req_builder.json(&p_body_request_body);
129
130 let req = req_builder.build()?;
131 let resp = configuration.client.execute(req).await?;
132
133 let status = resp.status();
134 let content_type = resp
135 .headers()
136 .get("content-type")
137 .and_then(|v| v.to_str().ok())
138 .unwrap_or("application/octet-stream");
139 let content_type = super::ContentType::from(content_type);
140
141 if !status.is_client_error() && !status.is_server_error() {
142 let content = resp.text().await?;
143 match content_type {
144 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
145 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`"))),
146 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`")))),
147 }
148 } else {
149 let content = resp.text().await?;
150 let entity: Option<SetResourcePermissionGrantError> = serde_json::from_str(&content).ok();
151 Err(Error::ResponseError(ResponseContent { status, content, entity }))
152 }
153}
154