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::{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        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
78            local_var_req_builder = local_var_req_builder
79                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
80        }
81        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
82            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
83        };
84
85        let local_var_req = local_var_req_builder.build()?;
86        let local_var_resp = local_var_client.execute(local_var_req).await?;
87
88        let local_var_status = local_var_resp.status();
89        let local_var_content_type = local_var_resp
90            .headers()
91            .get("content-type")
92            .and_then(|v| v.to_str().ok())
93            .unwrap_or("application/octet-stream");
94        let local_var_content_type = super::ContentType::from(local_var_content_type);
95        let local_var_content = local_var_resp.text().await?;
96
97        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
98            match local_var_content_type {
99                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
100                ContentType::Text => {
101                    return Err(Error::from(serde_json::Error::custom(
102                        "Received `text/plain` content type response that cannot be converted to `models::OrganizationCountsResponseModel`",
103                    )));
104                }
105                ContentType::Unsupported(local_var_unknown_type) => {
106                    return Err(Error::from(serde_json::Error::custom(format!(
107                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::OrganizationCountsResponseModel`"
108                    ))));
109                }
110            }
111        } else {
112            let local_var_entity: Option<GetByOrganizationError> =
113                serde_json::from_str(&local_var_content).ok();
114            let local_var_error = ResponseContent {
115                status: local_var_status,
116                content: local_var_content,
117                entity: local_var_entity,
118            };
119            Err(Error::ResponseError(local_var_error))
120        }
121    }
122
123    async fn get_by_project<'a>(
124        &self,
125        project_id: uuid::Uuid,
126    ) -> Result<models::ProjectCountsResponseModel, Error<GetByProjectError>> {
127        let local_var_configuration = &self.configuration;
128
129        let local_var_client = &local_var_configuration.client;
130
131        let local_var_uri_str = format!(
132            "{}/projects/{projectId}/sm-counts",
133            local_var_configuration.base_path,
134            projectId = project_id
135        );
136        let mut local_var_req_builder =
137            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
138
139        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
140            local_var_req_builder = local_var_req_builder
141                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
142        }
143        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
144            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
145        };
146
147        let local_var_req = local_var_req_builder.build()?;
148        let local_var_resp = local_var_client.execute(local_var_req).await?;
149
150        let local_var_status = local_var_resp.status();
151        let local_var_content_type = local_var_resp
152            .headers()
153            .get("content-type")
154            .and_then(|v| v.to_str().ok())
155            .unwrap_or("application/octet-stream");
156        let local_var_content_type = super::ContentType::from(local_var_content_type);
157        let local_var_content = local_var_resp.text().await?;
158
159        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
160            match local_var_content_type {
161                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
162                ContentType::Text => {
163                    return Err(Error::from(serde_json::Error::custom(
164                        "Received `text/plain` content type response that cannot be converted to `models::ProjectCountsResponseModel`",
165                    )));
166                }
167                ContentType::Unsupported(local_var_unknown_type) => {
168                    return Err(Error::from(serde_json::Error::custom(format!(
169                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ProjectCountsResponseModel`"
170                    ))));
171                }
172            }
173        } else {
174            let local_var_entity: Option<GetByProjectError> =
175                serde_json::from_str(&local_var_content).ok();
176            let local_var_error = ResponseContent {
177                status: local_var_status,
178                content: local_var_content,
179                entity: local_var_entity,
180            };
181            Err(Error::ResponseError(local_var_error))
182        }
183    }
184
185    async fn get_by_service_account<'a>(
186        &self,
187        service_account_id: uuid::Uuid,
188    ) -> Result<models::ServiceAccountCountsResponseModel, Error<GetByServiceAccountError>> {
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!(
194            "{}/service-accounts/{serviceAccountId}/sm-counts",
195            local_var_configuration.base_path,
196            serviceAccountId = service_account_id
197        );
198        let mut local_var_req_builder =
199            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
200
201        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
202            local_var_req_builder = local_var_req_builder
203                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
204        }
205        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
206            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
207        };
208
209        let local_var_req = local_var_req_builder.build()?;
210        let local_var_resp = local_var_client.execute(local_var_req).await?;
211
212        let local_var_status = local_var_resp.status();
213        let local_var_content_type = local_var_resp
214            .headers()
215            .get("content-type")
216            .and_then(|v| v.to_str().ok())
217            .unwrap_or("application/octet-stream");
218        let local_var_content_type = super::ContentType::from(local_var_content_type);
219        let local_var_content = local_var_resp.text().await?;
220
221        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
222            match local_var_content_type {
223                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
224                ContentType::Text => {
225                    return Err(Error::from(serde_json::Error::custom(
226                        "Received `text/plain` content type response that cannot be converted to `models::ServiceAccountCountsResponseModel`",
227                    )));
228                }
229                ContentType::Unsupported(local_var_unknown_type) => {
230                    return Err(Error::from(serde_json::Error::custom(format!(
231                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ServiceAccountCountsResponseModel`"
232                    ))));
233                }
234            }
235        } else {
236            let local_var_entity: Option<GetByServiceAccountError> =
237                serde_json::from_str(&local_var_content).ok();
238            let local_var_error = ResponseContent {
239                status: local_var_status,
240                content: local_var_content,
241                entity: local_var_entity,
242            };
243            Err(Error::ResponseError(local_var_error))
244        }
245    }
246}
247
248/// struct for typed errors of method [`CountsApi::get_by_organization`]
249#[derive(Debug, Clone, Serialize, Deserialize)]
250#[serde(untagged)]
251pub enum GetByOrganizationError {
252    UnknownValue(serde_json::Value),
253}
254/// struct for typed errors of method [`CountsApi::get_by_project`]
255#[derive(Debug, Clone, Serialize, Deserialize)]
256#[serde(untagged)]
257pub enum GetByProjectError {
258    UnknownValue(serde_json::Value),
259}
260/// struct for typed errors of method [`CountsApi::get_by_service_account`]
261#[derive(Debug, Clone, Serialize, Deserialize)]
262#[serde(untagged)]
263pub enum GetByServiceAccountError {
264    UnknownValue(serde_json::Value),
265}