bitwarden_api_api/apis/
config_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 ConfigApi: Send + Sync {
29    /// GET /config
30    async fn get_configs(&self) -> Result<models::ConfigResponseModel, Error<GetConfigsError>>;
31}
32
33pub struct ConfigApiClient {
34    configuration: Arc<configuration::Configuration>,
35}
36
37impl ConfigApiClient {
38    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
39        Self { configuration }
40    }
41}
42
43#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
44#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
45impl ConfigApi for ConfigApiClient {
46    async fn get_configs(&self) -> Result<models::ConfigResponseModel, Error<GetConfigsError>> {
47        let local_var_configuration = &self.configuration;
48
49        let local_var_client = &local_var_configuration.client;
50
51        let local_var_uri_str = format!("{}/config", local_var_configuration.base_path);
52        let mut local_var_req_builder =
53            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
54
55        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
56            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
57        };
58        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
59
60        let local_var_req = local_var_req_builder.build()?;
61        let local_var_resp = local_var_client.execute(local_var_req).await?;
62
63        let local_var_status = local_var_resp.status();
64        let local_var_content_type = local_var_resp
65            .headers()
66            .get("content-type")
67            .and_then(|v| v.to_str().ok())
68            .unwrap_or("application/octet-stream");
69        let local_var_content_type = super::ContentType::from(local_var_content_type);
70        let local_var_content = local_var_resp.text().await?;
71
72        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
73            match local_var_content_type {
74                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
75                ContentType::Text => {
76                    return Err(Error::from(serde_json::Error::custom(
77                        "Received `text/plain` content type response that cannot be converted to `models::ConfigResponseModel`",
78                    )));
79                }
80                ContentType::Unsupported(local_var_unknown_type) => {
81                    return Err(Error::from(serde_json::Error::custom(format!(
82                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ConfigResponseModel`"
83                    ))));
84                }
85            }
86        } else {
87            let local_var_entity: Option<GetConfigsError> =
88                serde_json::from_str(&local_var_content).ok();
89            let local_var_error = ResponseContent {
90                status: local_var_status,
91                content: local_var_content,
92                entity: local_var_entity,
93            };
94            Err(Error::ResponseError(local_var_error))
95        }
96    }
97}
98
99/// struct for typed errors of method [`ConfigApi::get_configs`]
100#[derive(Debug, Clone, Serialize, Deserialize)]
101#[serde(untagged)]
102pub enum GetConfigsError {
103    UnknownValue(serde_json::Value),
104}