bitwarden_api_api/apis/
policies_api.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use reqwest;
12use serde::{Deserialize, Serialize};
13
14use super::{configuration, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`organizations_org_id_policies_get`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum OrganizationsOrgIdPoliciesGetError {
21    UnknownValue(serde_json::Value),
22}
23
24/// struct for typed errors of method [`organizations_org_id_policies_invited_user_get`]
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(untagged)]
27pub enum OrganizationsOrgIdPoliciesInvitedUserGetError {
28    UnknownValue(serde_json::Value),
29}
30
31/// struct for typed errors of method [`organizations_org_id_policies_master_password_get`]
32#[derive(Debug, Clone, Serialize, Deserialize)]
33#[serde(untagged)]
34pub enum OrganizationsOrgIdPoliciesMasterPasswordGetError {
35    UnknownValue(serde_json::Value),
36}
37
38/// struct for typed errors of method [`organizations_org_id_policies_token_get`]
39#[derive(Debug, Clone, Serialize, Deserialize)]
40#[serde(untagged)]
41pub enum OrganizationsOrgIdPoliciesTokenGetError {
42    UnknownValue(serde_json::Value),
43}
44
45/// struct for typed errors of method [`organizations_org_id_policies_type_get`]
46#[derive(Debug, Clone, Serialize, Deserialize)]
47#[serde(untagged)]
48pub enum OrganizationsOrgIdPoliciesTypeGetError {
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method [`organizations_org_id_policies_type_put`]
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum OrganizationsOrgIdPoliciesTypePutError {
56    UnknownValue(serde_json::Value),
57}
58
59pub async fn organizations_org_id_policies_get(
60    configuration: &configuration::Configuration,
61    org_id: &str,
62) -> Result<models::PolicyResponseModelListResponseModel, Error<OrganizationsOrgIdPoliciesGetError>>
63{
64    let local_var_configuration = configuration;
65
66    let local_var_client = &local_var_configuration.client;
67
68    let local_var_uri_str = format!(
69        "{}/organizations/{orgId}/policies",
70        local_var_configuration.base_path,
71        orgId = crate::apis::urlencode(org_id)
72    );
73    let mut local_var_req_builder =
74        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
75
76    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
77        local_var_req_builder =
78            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
79    }
80    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
81        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
82    };
83
84    let local_var_req = local_var_req_builder.build()?;
85    let local_var_resp = local_var_client.execute(local_var_req).await?;
86
87    let local_var_status = local_var_resp.status();
88    let local_var_content = local_var_resp.text().await?;
89
90    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
91        serde_json::from_str(&local_var_content).map_err(Error::from)
92    } else {
93        let local_var_entity: Option<OrganizationsOrgIdPoliciesGetError> =
94            serde_json::from_str(&local_var_content).ok();
95        let local_var_error = ResponseContent {
96            status: local_var_status,
97            content: local_var_content,
98            entity: local_var_entity,
99        };
100        Err(Error::ResponseError(local_var_error))
101    }
102}
103
104pub async fn organizations_org_id_policies_invited_user_get(
105    configuration: &configuration::Configuration,
106    org_id: uuid::Uuid,
107    user_id: Option<uuid::Uuid>,
108) -> Result<
109    models::PolicyResponseModelListResponseModel,
110    Error<OrganizationsOrgIdPoliciesInvitedUserGetError>,
111> {
112    let local_var_configuration = configuration;
113
114    let local_var_client = &local_var_configuration.client;
115
116    let local_var_uri_str = format!(
117        "{}/organizations/{orgId}/policies/invited-user",
118        local_var_configuration.base_path,
119        orgId = crate::apis::urlencode(org_id.to_string())
120    );
121    let mut local_var_req_builder =
122        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
123
124    if let Some(ref local_var_str) = user_id {
125        local_var_req_builder =
126            local_var_req_builder.query(&[("userId", &local_var_str.to_string())]);
127    }
128    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
129        local_var_req_builder =
130            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
131    }
132    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
133        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
134    };
135
136    let local_var_req = local_var_req_builder.build()?;
137    let local_var_resp = local_var_client.execute(local_var_req).await?;
138
139    let local_var_status = local_var_resp.status();
140    let local_var_content = local_var_resp.text().await?;
141
142    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
143        serde_json::from_str(&local_var_content).map_err(Error::from)
144    } else {
145        let local_var_entity: Option<OrganizationsOrgIdPoliciesInvitedUserGetError> =
146            serde_json::from_str(&local_var_content).ok();
147        let local_var_error = ResponseContent {
148            status: local_var_status,
149            content: local_var_content,
150            entity: local_var_entity,
151        };
152        Err(Error::ResponseError(local_var_error))
153    }
154}
155
156pub async fn organizations_org_id_policies_master_password_get(
157    configuration: &configuration::Configuration,
158    org_id: uuid::Uuid,
159) -> Result<models::PolicyResponseModel, Error<OrganizationsOrgIdPoliciesMasterPasswordGetError>> {
160    let local_var_configuration = configuration;
161
162    let local_var_client = &local_var_configuration.client;
163
164    let local_var_uri_str = format!(
165        "{}/organizations/{orgId}/policies/master-password",
166        local_var_configuration.base_path,
167        orgId = crate::apis::urlencode(org_id.to_string())
168    );
169    let mut local_var_req_builder =
170        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
171
172    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
173        local_var_req_builder =
174            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
175    }
176    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
177        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
178    };
179
180    let local_var_req = local_var_req_builder.build()?;
181    let local_var_resp = local_var_client.execute(local_var_req).await?;
182
183    let local_var_status = local_var_resp.status();
184    let local_var_content = local_var_resp.text().await?;
185
186    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
187        serde_json::from_str(&local_var_content).map_err(Error::from)
188    } else {
189        let local_var_entity: Option<OrganizationsOrgIdPoliciesMasterPasswordGetError> =
190            serde_json::from_str(&local_var_content).ok();
191        let local_var_error = ResponseContent {
192            status: local_var_status,
193            content: local_var_content,
194            entity: local_var_entity,
195        };
196        Err(Error::ResponseError(local_var_error))
197    }
198}
199
200pub async fn organizations_org_id_policies_token_get(
201    configuration: &configuration::Configuration,
202    org_id: uuid::Uuid,
203    email: Option<&str>,
204    token: Option<&str>,
205    organization_user_id: Option<uuid::Uuid>,
206) -> Result<
207    models::PolicyResponseModelListResponseModel,
208    Error<OrganizationsOrgIdPoliciesTokenGetError>,
209> {
210    let local_var_configuration = configuration;
211
212    let local_var_client = &local_var_configuration.client;
213
214    let local_var_uri_str = format!(
215        "{}/organizations/{orgId}/policies/token",
216        local_var_configuration.base_path,
217        orgId = crate::apis::urlencode(org_id.to_string())
218    );
219    let mut local_var_req_builder =
220        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
221
222    if let Some(ref local_var_str) = email {
223        local_var_req_builder =
224            local_var_req_builder.query(&[("email", &local_var_str.to_string())]);
225    }
226    if let Some(ref local_var_str) = token {
227        local_var_req_builder =
228            local_var_req_builder.query(&[("token", &local_var_str.to_string())]);
229    }
230    if let Some(ref local_var_str) = organization_user_id {
231        local_var_req_builder =
232            local_var_req_builder.query(&[("organizationUserId", &local_var_str.to_string())]);
233    }
234    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
235        local_var_req_builder =
236            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
237    }
238    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
239        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
240    };
241
242    let local_var_req = local_var_req_builder.build()?;
243    let local_var_resp = local_var_client.execute(local_var_req).await?;
244
245    let local_var_status = local_var_resp.status();
246    let local_var_content = local_var_resp.text().await?;
247
248    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
249        serde_json::from_str(&local_var_content).map_err(Error::from)
250    } else {
251        let local_var_entity: Option<OrganizationsOrgIdPoliciesTokenGetError> =
252            serde_json::from_str(&local_var_content).ok();
253        let local_var_error = ResponseContent {
254            status: local_var_status,
255            content: local_var_content,
256            entity: local_var_entity,
257        };
258        Err(Error::ResponseError(local_var_error))
259    }
260}
261
262pub async fn organizations_org_id_policies_type_get(
263    configuration: &configuration::Configuration,
264    org_id: uuid::Uuid,
265    r#type: i32,
266) -> Result<models::PolicyDetailResponseModel, Error<OrganizationsOrgIdPoliciesTypeGetError>> {
267    let local_var_configuration = configuration;
268
269    let local_var_client = &local_var_configuration.client;
270
271    let local_var_uri_str = format!("{}/organizations/{orgId}/policies/{type}", local_var_configuration.base_path, orgId=crate::apis::urlencode(org_id.to_string()), type=r#type);
272    let mut local_var_req_builder =
273        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
274
275    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
276        local_var_req_builder =
277            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
278    }
279    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
280        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
281    };
282
283    let local_var_req = local_var_req_builder.build()?;
284    let local_var_resp = local_var_client.execute(local_var_req).await?;
285
286    let local_var_status = local_var_resp.status();
287    let local_var_content = local_var_resp.text().await?;
288
289    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
290        serde_json::from_str(&local_var_content).map_err(Error::from)
291    } else {
292        let local_var_entity: Option<OrganizationsOrgIdPoliciesTypeGetError> =
293            serde_json::from_str(&local_var_content).ok();
294        let local_var_error = ResponseContent {
295            status: local_var_status,
296            content: local_var_content,
297            entity: local_var_entity,
298        };
299        Err(Error::ResponseError(local_var_error))
300    }
301}
302
303pub async fn organizations_org_id_policies_type_put(
304    configuration: &configuration::Configuration,
305    org_id: uuid::Uuid,
306    r#type: models::PolicyType,
307    policy_request_model: Option<models::PolicyRequestModel>,
308) -> Result<models::PolicyResponseModel, Error<OrganizationsOrgIdPoliciesTypePutError>> {
309    let local_var_configuration = configuration;
310
311    let local_var_client = &local_var_configuration.client;
312
313    let local_var_uri_str = format!("{}/organizations/{orgId}/policies/{type}", local_var_configuration.base_path, orgId=crate::apis::urlencode(org_id.to_string()), type=r#type.to_string());
314    let mut local_var_req_builder =
315        local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
316
317    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
318        local_var_req_builder =
319            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
320    }
321    if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
322        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
323    };
324    local_var_req_builder = local_var_req_builder.json(&policy_request_model);
325
326    let local_var_req = local_var_req_builder.build()?;
327    let local_var_resp = local_var_client.execute(local_var_req).await?;
328
329    let local_var_status = local_var_resp.status();
330    let local_var_content = local_var_resp.text().await?;
331
332    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
333        serde_json::from_str(&local_var_content).map_err(Error::from)
334    } else {
335        let local_var_entity: Option<OrganizationsOrgIdPoliciesTypePutError> =
336            serde_json::from_str(&local_var_content).ok();
337        let local_var_error = ResponseContent {
338            status: local_var_status,
339            content: local_var_content,
340            entity: local_var_entity,
341        };
342        Err(Error::ResponseError(local_var_error))
343    }
344}