Skip to main content

bitwarden_api_api/apis/
counts_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 CountsApi: Send + Sync {
29    /// GET /organizations/{organizationId}/sm-counts
30    async fn get_by_organization<'a>(
31        &self,
32        organization_id: uuid::Uuid,
33    ) -> Result<models::OrganizationCountsResponseModel, Error<GetByOrganizationError>>;
34
35    /// GET /projects/{projectId}/sm-counts
36    async fn get_by_project<'a>(
37        &self,
38        project_id: uuid::Uuid,
39    ) -> Result<models::ProjectCountsResponseModel, Error<GetByProjectError>>;
40
41    /// GET /service-accounts/{serviceAccountId}/sm-counts
42    async fn get_by_service_account<'a>(
43        &self,
44        service_account_id: uuid::Uuid,
45    ) -> Result<models::ServiceAccountCountsResponseModel, Error<GetByServiceAccountError>>;
46}
47
48pub struct CountsApiClient {
49    configuration: Arc<configuration::Configuration>,
50}
51
52impl CountsApiClient {
53    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
54        Self { configuration }
55    }
56}
57
58#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
59#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
60impl CountsApi for CountsApiClient {
61    async fn get_by_organization<'a>(
62        &self,
63        organization_id: uuid::Uuid,
64    ) -> Result<models::OrganizationCountsResponseModel, Error<GetByOrganizationError>> {
65        let local_var_configuration = &self.configuration;
66
67        let local_var_client = &local_var_configuration.client;
68
69        let local_var_uri_str = format!(
70            "{}/organizations/{organizationId}/sm-counts",
71            local_var_configuration.base_path,
72            organizationId = organization_id
73        );
74        let mut local_var_req_builder =
75            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
76
77        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
78
79        let local_var_resp = local_var_req_builder.send().await?;
80
81        let local_var_status = local_var_resp.status();
82        let local_var_content_type = local_var_resp
83            .headers()
84            .get("content-type")
85            .and_then(|v| v.to_str().ok())
86            .unwrap_or("application/octet-stream");
87        let local_var_content_type = super::ContentType::from(local_var_content_type);
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            match local_var_content_type {
92                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
93                ContentType::Text => {
94                    return Err(Error::from(serde_json::Error::custom(
95                        "Received `text/plain` content type response that cannot be converted to `models::OrganizationCountsResponseModel`",
96                    )));
97                }
98                ContentType::Unsupported(local_var_unknown_type) => {
99                    return Err(Error::from(serde_json::Error::custom(format!(
100                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationCountsResponseModel`"
101                    ))));
102                }
103            }
104        } else {
105            let local_var_entity: Option<GetByOrganizationError> =
106                serde_json::from_str(&local_var_content).ok();
107            let local_var_error = ResponseContent {
108                status: local_var_status,
109                content: local_var_content,
110                entity: local_var_entity,
111            };
112            Err(Error::ResponseError(local_var_error))
113        }
114    }
115
116    async fn get_by_project<'a>(
117        &self,
118        project_id: uuid::Uuid,
119    ) -> Result<models::ProjectCountsResponseModel, Error<GetByProjectError>> {
120        let local_var_configuration = &self.configuration;
121
122        let local_var_client = &local_var_configuration.client;
123
124        let local_var_uri_str = format!(
125            "{}/projects/{projectId}/sm-counts",
126            local_var_configuration.base_path,
127            projectId = project_id
128        );
129        let mut local_var_req_builder =
130            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
131
132        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
133
134        let local_var_resp = local_var_req_builder.send().await?;
135
136        let local_var_status = local_var_resp.status();
137        let local_var_content_type = local_var_resp
138            .headers()
139            .get("content-type")
140            .and_then(|v| v.to_str().ok())
141            .unwrap_or("application/octet-stream");
142        let local_var_content_type = super::ContentType::from(local_var_content_type);
143        let local_var_content = local_var_resp.text().await?;
144
145        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
146            match local_var_content_type {
147                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
148                ContentType::Text => {
149                    return Err(Error::from(serde_json::Error::custom(
150                        "Received `text/plain` content type response that cannot be converted to `models::ProjectCountsResponseModel`",
151                    )));
152                }
153                ContentType::Unsupported(local_var_unknown_type) => {
154                    return Err(Error::from(serde_json::Error::custom(format!(
155                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProjectCountsResponseModel`"
156                    ))));
157                }
158            }
159        } else {
160            let local_var_entity: Option<GetByProjectError> =
161                serde_json::from_str(&local_var_content).ok();
162            let local_var_error = ResponseContent {
163                status: local_var_status,
164                content: local_var_content,
165                entity: local_var_entity,
166            };
167            Err(Error::ResponseError(local_var_error))
168        }
169    }
170
171    async fn get_by_service_account<'a>(
172        &self,
173        service_account_id: uuid::Uuid,
174    ) -> Result<models::ServiceAccountCountsResponseModel, Error<GetByServiceAccountError>> {
175        let local_var_configuration = &self.configuration;
176
177        let local_var_client = &local_var_configuration.client;
178
179        let local_var_uri_str = format!(
180            "{}/service-accounts/{serviceAccountId}/sm-counts",
181            local_var_configuration.base_path,
182            serviceAccountId = service_account_id
183        );
184        let mut local_var_req_builder =
185            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
186
187        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
188
189        let local_var_resp = local_var_req_builder.send().await?;
190
191        let local_var_status = local_var_resp.status();
192        let local_var_content_type = local_var_resp
193            .headers()
194            .get("content-type")
195            .and_then(|v| v.to_str().ok())
196            .unwrap_or("application/octet-stream");
197        let local_var_content_type = super::ContentType::from(local_var_content_type);
198        let local_var_content = local_var_resp.text().await?;
199
200        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
201            match local_var_content_type {
202                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
203                ContentType::Text => {
204                    return Err(Error::from(serde_json::Error::custom(
205                        "Received `text/plain` content type response that cannot be converted to `models::ServiceAccountCountsResponseModel`",
206                    )));
207                }
208                ContentType::Unsupported(local_var_unknown_type) => {
209                    return Err(Error::from(serde_json::Error::custom(format!(
210                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ServiceAccountCountsResponseModel`"
211                    ))));
212                }
213            }
214        } else {
215            let local_var_entity: Option<GetByServiceAccountError> =
216                serde_json::from_str(&local_var_content).ok();
217            let local_var_error = ResponseContent {
218                status: local_var_status,
219                content: local_var_content,
220                entity: local_var_entity,
221            };
222            Err(Error::ResponseError(local_var_error))
223        }
224    }
225}
226
227/// struct for typed errors of method [`CountsApi::get_by_organization`]
228#[derive(Debug, Clone, Serialize, Deserialize)]
229#[serde(untagged)]
230pub enum GetByOrganizationError {
231    UnknownValue(serde_json::Value),
232}
233/// struct for typed errors of method [`CountsApi::get_by_project`]
234#[derive(Debug, Clone, Serialize, Deserialize)]
235#[serde(untagged)]
236pub enum GetByProjectError {
237    UnknownValue(serde_json::Value),
238}
239/// struct for typed errors of method [`CountsApi::get_by_service_account`]
240#[derive(Debug, Clone, Serialize, Deserialize)]
241#[serde(untagged)]
242pub enum GetByServiceAccountError {
243    UnknownValue(serde_json::Value),
244}