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::{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_user_agent) = local_var_configuration.user_agent {
56            local_var_req_builder = local_var_req_builder
57                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
58        }
59        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
60            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
61        };
62
63        let local_var_req = local_var_req_builder.build()?;
64        let local_var_resp = local_var_client.execute(local_var_req).await?;
65
66        let local_var_status = local_var_resp.status();
67        let local_var_content_type = local_var_resp
68            .headers()
69            .get("content-type")
70            .and_then(|v| v.to_str().ok())
71            .unwrap_or("application/octet-stream");
72        let local_var_content_type = super::ContentType::from(local_var_content_type);
73        let local_var_content = local_var_resp.text().await?;
74
75        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
76            match local_var_content_type {
77                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
78                ContentType::Text => {
79                    return Err(Error::from(serde_json::Error::custom(
80                        "Received `text/plain` content type response that cannot be converted to `models::ConfigResponseModel`",
81                    )));
82                }
83                ContentType::Unsupported(local_var_unknown_type) => {
84                    return Err(Error::from(serde_json::Error::custom(format!(
85                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `models::ConfigResponseModel`"
86                    ))));
87                }
88            }
89        } else {
90            let local_var_entity: Option<GetConfigsError> =
91                serde_json::from_str(&local_var_content).ok();
92            let local_var_error = ResponseContent {
93                status: local_var_status,
94                content: local_var_content,
95                entity: local_var_entity,
96            };
97            Err(Error::ResponseError(local_var_error))
98        }
99    }
100}
101
102/// struct for typed errors of method [`ConfigApi::get_configs`]
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(untagged)]
105pub enum GetConfigsError {
106    UnknownValue(serde_json::Value),
107}