tembo_api_client/apis/
rbac_api.rs

1/*
2 * Tembo Cloud
3 *
4 * Platform API for Tembo Cloud             </br>             </br>             To find a Tembo Data API, please find it here:             </br>             </br>             [AWS US East 1](https://api.data-1.use1.tembo.io/swagger-ui/)
5 *
6 * The version of the OpenAPI document: v1.0.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize};
15
16/// struct for typed errors of method [`delete_policy`]
17#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum DeletePolicyError {
20    Status401(models::ErrorResponseSchema),
21    Status403(models::ErrorResponseSchema),
22    UnknownValue(serde_json::Value),
23}
24
25/// struct for typed errors of method [`get_actions`]
26#[derive(Debug, Clone, Serialize, Deserialize)]
27#[serde(untagged)]
28pub enum GetActionsError {
29    Status401(models::ErrorResponseSchema),
30    Status403(models::ErrorResponseSchema),
31    UnknownValue(serde_json::Value),
32}
33
34/// struct for typed errors of method [`get_policies`]
35#[derive(Debug, Clone, Serialize, Deserialize)]
36#[serde(untagged)]
37pub enum GetPoliciesError {
38    Status401(models::ErrorResponseSchema),
39    Status403(models::ErrorResponseSchema),
40    UnknownValue(serde_json::Value),
41}
42
43/// struct for typed errors of method [`get_roles`]
44#[derive(Debug, Clone, Serialize, Deserialize)]
45#[serde(untagged)]
46pub enum GetRolesError {
47    Status401(models::ErrorResponseSchema),
48    Status403(models::ErrorResponseSchema),
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`set_policy`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum SetPolicyError {
56    Status400(models::ErrorResponseSchema),
57    Status401(models::ErrorResponseSchema),
58    Status403(models::ErrorResponseSchema),
59    UnknownValue(serde_json::Value),
60}
61
62/// Delete a policy
63pub async fn delete_policy(
64    configuration: &configuration::Configuration,
65    org_id: &str,
66    policy_input: models::PolicyInput,
67) -> Result<String, Error<DeletePolicyError>> {
68    // add a prefix to parameters to efficiently prevent name collisions
69    let p_org_id = org_id;
70    let p_policy_input = policy_input;
71
72    let uri_str = format!(
73        "{}/api/v1/orgs/{org_id}/policies",
74        configuration.base_path,
75        org_id = crate::apis::urlencode(p_org_id)
76    );
77    let mut req_builder = configuration
78        .client
79        .request(reqwest::Method::DELETE, &uri_str);
80
81    if let Some(ref user_agent) = configuration.user_agent {
82        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
83    }
84    if let Some(ref token) = configuration.bearer_access_token {
85        req_builder = req_builder.bearer_auth(token.to_owned());
86    };
87    req_builder = req_builder.json(&p_policy_input);
88
89    let req = req_builder.build()?;
90    let resp = configuration.client.execute(req).await?;
91
92    let status = resp.status();
93
94    if !status.is_client_error() && !status.is_server_error() {
95        let content = resp.text().await?;
96        serde_json::from_str(&content).map_err(Error::from)
97    } else {
98        let content = resp.text().await?;
99        let entity: Option<DeletePolicyError> = serde_json::from_str(&content).ok();
100        Err(Error::ResponseError(ResponseContent {
101            status,
102            content,
103            entity,
104        }))
105    }
106}
107
108/// Get all actions
109pub async fn get_actions(
110    configuration: &configuration::Configuration,
111    org_id: &str,
112) -> Result<Vec<models::Action>, Error<GetActionsError>> {
113    // add a prefix to parameters to efficiently prevent name collisions
114    let p_org_id = org_id;
115
116    let uri_str = format!(
117        "{}/api/v1/orgs/{org_id}/actions",
118        configuration.base_path,
119        org_id = crate::apis::urlencode(p_org_id)
120    );
121    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
122
123    if let Some(ref user_agent) = configuration.user_agent {
124        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
125    }
126    if let Some(ref token) = configuration.bearer_access_token {
127        req_builder = req_builder.bearer_auth(token.to_owned());
128    };
129
130    let req = req_builder.build()?;
131    let resp = configuration.client.execute(req).await?;
132
133    let status = resp.status();
134
135    if !status.is_client_error() && !status.is_server_error() {
136        let content = resp.text().await?;
137        serde_json::from_str(&content).map_err(Error::from)
138    } else {
139        let content = resp.text().await?;
140        let entity: Option<GetActionsError> = serde_json::from_str(&content).ok();
141        Err(Error::ResponseError(ResponseContent {
142            status,
143            content,
144            entity,
145        }))
146    }
147}
148
149/// Get all policies
150pub async fn get_policies(
151    configuration: &configuration::Configuration,
152    org_id: &str,
153) -> Result<Vec<models::PolicyData>, Error<GetPoliciesError>> {
154    // add a prefix to parameters to efficiently prevent name collisions
155    let p_org_id = org_id;
156
157    let uri_str = format!(
158        "{}/api/v1/orgs/{org_id}/policies",
159        configuration.base_path,
160        org_id = crate::apis::urlencode(p_org_id)
161    );
162    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
163
164    if let Some(ref user_agent) = configuration.user_agent {
165        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
166    }
167    if let Some(ref token) = configuration.bearer_access_token {
168        req_builder = req_builder.bearer_auth(token.to_owned());
169    };
170
171    let req = req_builder.build()?;
172    let resp = configuration.client.execute(req).await?;
173
174    let status = resp.status();
175
176    if !status.is_client_error() && !status.is_server_error() {
177        let content = resp.text().await?;
178        serde_json::from_str(&content).map_err(Error::from)
179    } else {
180        let content = resp.text().await?;
181        let entity: Option<GetPoliciesError> = serde_json::from_str(&content).ok();
182        Err(Error::ResponseError(ResponseContent {
183            status,
184            content,
185            entity,
186        }))
187    }
188}
189
190/// Get all roles
191pub async fn get_roles(
192    configuration: &configuration::Configuration,
193    org_id: &str,
194) -> Result<Vec<models::Role>, Error<GetRolesError>> {
195    // add a prefix to parameters to efficiently prevent name collisions
196    let p_org_id = org_id;
197
198    let uri_str = format!(
199        "{}/api/v1/orgs/{org_id}/roles",
200        configuration.base_path,
201        org_id = crate::apis::urlencode(p_org_id)
202    );
203    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
204
205    if let Some(ref user_agent) = configuration.user_agent {
206        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
207    }
208    if let Some(ref token) = configuration.bearer_access_token {
209        req_builder = req_builder.bearer_auth(token.to_owned());
210    };
211
212    let req = req_builder.build()?;
213    let resp = configuration.client.execute(req).await?;
214
215    let status = resp.status();
216
217    if !status.is_client_error() && !status.is_server_error() {
218        let content = resp.text().await?;
219        serde_json::from_str(&content).map_err(Error::from)
220    } else {
221        let content = resp.text().await?;
222        let entity: Option<GetRolesError> = serde_json::from_str(&content).ok();
223        Err(Error::ResponseError(ResponseContent {
224            status,
225            content,
226            entity,
227        }))
228    }
229}
230
231/// Create or update a policy
232pub async fn set_policy(
233    configuration: &configuration::Configuration,
234    org_id: &str,
235    policy_input: models::PolicyInput,
236) -> Result<String, Error<SetPolicyError>> {
237    // add a prefix to parameters to efficiently prevent name collisions
238    let p_org_id = org_id;
239    let p_policy_input = policy_input;
240
241    let uri_str = format!(
242        "{}/api/v1/orgs/{org_id}/policies",
243        configuration.base_path,
244        org_id = crate::apis::urlencode(p_org_id)
245    );
246    let mut req_builder = configuration
247        .client
248        .request(reqwest::Method::POST, &uri_str);
249
250    if let Some(ref user_agent) = configuration.user_agent {
251        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
252    }
253    if let Some(ref token) = configuration.bearer_access_token {
254        req_builder = req_builder.bearer_auth(token.to_owned());
255    };
256    req_builder = req_builder.json(&p_policy_input);
257
258    let req = req_builder.build()?;
259    let resp = configuration.client.execute(req).await?;
260
261    let status = resp.status();
262
263    if !status.is_client_error() && !status.is_server_error() {
264        let content = resp.text().await?;
265        serde_json::from_str(&content).map_err(Error::from)
266    } else {
267        let content = resp.text().await?;
268        let entity: Option<SetPolicyError> = serde_json::from_str(&content).ok();
269        Err(Error::ResponseError(ResponseContent {
270            status,
271            content,
272            entity,
273        }))
274    }
275}