Skip to main content

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 std::sync::Arc;
12
13use async_trait::async_trait;
14#[cfg(feature = "mockall")]
15use mockall::automock;
16use reqwest;
17use serde::{Deserialize, Serialize, de::Error as _};
18
19use super::{Error, configuration};
20use crate::{
21    apis::{AuthRequired, ContentType, ResponseContent},
22    models,
23};
24
25#[cfg_attr(feature = "mockall", automock)]
26#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
27#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
28pub trait PoliciesApi: Send + Sync {
29    /// GET /organizations/{orgId}/policies/{type}
30    async fn get<'a>(
31        &self,
32        org_id: uuid::Uuid,
33        r#type: models::PolicyType,
34    ) -> Result<models::PolicyStatusResponseModel, Error<GetError>>;
35
36    /// GET /organizations/{orgId}/policies
37    async fn get_all<'a>(
38        &self,
39        org_id: &'a str,
40    ) -> Result<models::PolicyResponseModelListResponseModel, Error<GetAllError>>;
41
42    /// GET /organizations/{orgId}/policies/token
43    async fn get_by_token<'a>(
44        &self,
45        org_id: uuid::Uuid,
46        email: Option<&'a str>,
47        token: Option<&'a str>,
48        organization_user_id: Option<uuid::Uuid>,
49    ) -> Result<models::PolicyResponseModelListResponseModel, Error<GetByTokenError>>;
50
51    /// GET /organizations/{orgId}/policies/master-password
52    async fn get_master_password_policy<'a>(
53        &self,
54        org_id: uuid::Uuid,
55    ) -> Result<models::PolicyResponseModel, Error<GetMasterPasswordPolicyError>>;
56
57    /// PUT /organizations/{orgId}/policies/{type}
58    async fn put<'a>(
59        &self,
60        org_id: uuid::Uuid,
61        r#type: models::PolicyType,
62        policy_request_model: Option<models::PolicyRequestModel>,
63    ) -> Result<models::PolicyResponseModel, Error<PutError>>;
64
65    /// PUT /organizations/{orgId}/policies/{type}/vnext
66    async fn put_v_next<'a>(
67        &self,
68        org_id: uuid::Uuid,
69        r#type: models::PolicyType,
70        save_policy_request: Option<models::SavePolicyRequest>,
71    ) -> Result<models::PolicyResponseModel, Error<PutVNextError>>;
72}
73
74pub struct PoliciesApiClient {
75    configuration: Arc<configuration::Configuration>,
76}
77
78impl PoliciesApiClient {
79    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
80        Self { configuration }
81    }
82}
83
84#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
85#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
86impl PoliciesApi for PoliciesApiClient {
87    async fn get<'a>(
88        &self,
89        org_id: uuid::Uuid,
90        r#type: models::PolicyType,
91    ) -> Result<models::PolicyStatusResponseModel, Error<GetError>> {
92        let local_var_configuration = &self.configuration;
93
94        let local_var_client = &local_var_configuration.client;
95
96        let local_var_uri_str = format!("{}/organizations/{orgId}/policies/{type}", local_var_configuration.base_path, orgId=org_id, type=r#type.to_string());
97        let mut local_var_req_builder =
98            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
99
100        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
101
102        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
103    }
104
105    async fn get_all<'a>(
106        &self,
107        org_id: &'a str,
108    ) -> Result<models::PolicyResponseModelListResponseModel, Error<GetAllError>> {
109        let local_var_configuration = &self.configuration;
110
111        let local_var_client = &local_var_configuration.client;
112
113        let local_var_uri_str = format!(
114            "{}/organizations/{orgId}/policies",
115            local_var_configuration.base_path,
116            orgId = crate::apis::urlencode(org_id)
117        );
118        let mut local_var_req_builder =
119            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
120
121        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
122
123        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
124    }
125
126    async fn get_by_token<'a>(
127        &self,
128        org_id: uuid::Uuid,
129        email: Option<&'a str>,
130        token: Option<&'a str>,
131        organization_user_id: Option<uuid::Uuid>,
132    ) -> Result<models::PolicyResponseModelListResponseModel, Error<GetByTokenError>> {
133        let local_var_configuration = &self.configuration;
134
135        let local_var_client = &local_var_configuration.client;
136
137        let local_var_uri_str = format!(
138            "{}/organizations/{orgId}/policies/token",
139            local_var_configuration.base_path,
140            orgId = org_id
141        );
142        let mut local_var_req_builder =
143            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
144
145        if let Some(ref param_value) = email {
146            local_var_req_builder =
147                local_var_req_builder.query(&[("email", &param_value.to_string())]);
148        }
149        if let Some(ref param_value) = token {
150            local_var_req_builder =
151                local_var_req_builder.query(&[("token", &param_value.to_string())]);
152        }
153        if let Some(ref param_value) = organization_user_id {
154            local_var_req_builder =
155                local_var_req_builder.query(&[("organizationUserId", &param_value.to_string())]);
156        }
157        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
158
159        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
160    }
161
162    async fn get_master_password_policy<'a>(
163        &self,
164        org_id: uuid::Uuid,
165    ) -> Result<models::PolicyResponseModel, Error<GetMasterPasswordPolicyError>> {
166        let local_var_configuration = &self.configuration;
167
168        let local_var_client = &local_var_configuration.client;
169
170        let local_var_uri_str = format!(
171            "{}/organizations/{orgId}/policies/master-password",
172            local_var_configuration.base_path,
173            orgId = org_id
174        );
175        let mut local_var_req_builder =
176            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
177
178        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
179
180        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
181    }
182
183    async fn put<'a>(
184        &self,
185        org_id: uuid::Uuid,
186        r#type: models::PolicyType,
187        policy_request_model: Option<models::PolicyRequestModel>,
188    ) -> Result<models::PolicyResponseModel, Error<PutError>> {
189        let local_var_configuration = &self.configuration;
190
191        let local_var_client = &local_var_configuration.client;
192
193        let local_var_uri_str = format!("{}/organizations/{orgId}/policies/{type}", local_var_configuration.base_path, orgId=org_id, type=r#type.to_string());
194        let mut local_var_req_builder =
195            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
196
197        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
198        local_var_req_builder = local_var_req_builder.json(&policy_request_model);
199
200        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
201    }
202
203    async fn put_v_next<'a>(
204        &self,
205        org_id: uuid::Uuid,
206        r#type: models::PolicyType,
207        save_policy_request: Option<models::SavePolicyRequest>,
208    ) -> Result<models::PolicyResponseModel, Error<PutVNextError>> {
209        let local_var_configuration = &self.configuration;
210
211        let local_var_client = &local_var_configuration.client;
212
213        let local_var_uri_str = format!("{}/organizations/{orgId}/policies/{type}/vnext", local_var_configuration.base_path, orgId=org_id, type=r#type.to_string());
214        let mut local_var_req_builder =
215            local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
216
217        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
218        local_var_req_builder = local_var_req_builder.json(&save_policy_request);
219
220        bitwarden_api_base::process_with_json_response(local_var_req_builder).await
221    }
222}
223
224/// struct for typed errors of method [`PoliciesApi::get`]
225#[derive(Debug, Clone, Serialize, Deserialize)]
226#[serde(untagged)]
227pub enum GetError {
228    UnknownValue(serde_json::Value),
229}
230/// struct for typed errors of method [`PoliciesApi::get_all`]
231#[derive(Debug, Clone, Serialize, Deserialize)]
232#[serde(untagged)]
233pub enum GetAllError {
234    UnknownValue(serde_json::Value),
235}
236/// struct for typed errors of method [`PoliciesApi::get_by_token`]
237#[derive(Debug, Clone, Serialize, Deserialize)]
238#[serde(untagged)]
239pub enum GetByTokenError {
240    UnknownValue(serde_json::Value),
241}
242/// struct for typed errors of method [`PoliciesApi::get_master_password_policy`]
243#[derive(Debug, Clone, Serialize, Deserialize)]
244#[serde(untagged)]
245pub enum GetMasterPasswordPolicyError {
246    UnknownValue(serde_json::Value),
247}
248/// struct for typed errors of method [`PoliciesApi::put`]
249#[derive(Debug, Clone, Serialize, Deserialize)]
250#[serde(untagged)]
251pub enum PutError {
252    UnknownValue(serde_json::Value),
253}
254/// struct for typed errors of method [`PoliciesApi::put_v_next`]
255#[derive(Debug, Clone, Serialize, Deserialize)]
256#[serde(untagged)]
257pub enum PutVNextError {
258    UnknownValue(serde_json::Value),
259}