bitwarden_api_api/apis/
info_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 InfoApi: Send + Sync {
29    /// GET /alive
30    async fn get_alive(&self) -> Result<String, Error<GetAliveError>>;
31
32    /// GET /version
33    async fn get_version(&self) -> Result<(), Error<GetVersionError>>;
34}
35
36pub struct InfoApiClient {
37    configuration: Arc<configuration::Configuration>,
38}
39
40impl InfoApiClient {
41    pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
42        Self { configuration }
43    }
44}
45
46#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
47#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
48impl InfoApi for InfoApiClient {
49    async fn get_alive(&self) -> Result<String, Error<GetAliveError>> {
50        let local_var_configuration = &self.configuration;
51
52        let local_var_client = &local_var_configuration.client;
53
54        let local_var_uri_str = format!("{}/alive", local_var_configuration.base_path);
55        let mut local_var_req_builder =
56            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
57
58        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
59            local_var_req_builder = local_var_req_builder
60                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
61        }
62        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
63            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
64        };
65
66        let local_var_req = local_var_req_builder.build()?;
67        let local_var_resp = local_var_client.execute(local_var_req).await?;
68
69        let local_var_status = local_var_resp.status();
70        let local_var_content_type = local_var_resp
71            .headers()
72            .get("content-type")
73            .and_then(|v| v.to_str().ok())
74            .unwrap_or("application/octet-stream");
75        let local_var_content_type = super::ContentType::from(local_var_content_type);
76        let local_var_content = local_var_resp.text().await?;
77
78        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
79            match local_var_content_type {
80                ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
81                ContentType::Text => return Ok(local_var_content),
82                ContentType::Unsupported(local_var_unknown_type) => {
83                    return Err(Error::from(serde_json::Error::custom(format!(
84                        "Received `{local_var_unknown_type}` content type response that cannot be converted to `String`"
85                    ))));
86                }
87            }
88        } else {
89            let local_var_entity: Option<GetAliveError> =
90                serde_json::from_str(&local_var_content).ok();
91            let local_var_error = ResponseContent {
92                status: local_var_status,
93                content: local_var_content,
94                entity: local_var_entity,
95            };
96            Err(Error::ResponseError(local_var_error))
97        }
98    }
99
100    async fn get_version(&self) -> Result<(), Error<GetVersionError>> {
101        let local_var_configuration = &self.configuration;
102
103        let local_var_client = &local_var_configuration.client;
104
105        let local_var_uri_str = format!("{}/version", local_var_configuration.base_path);
106        let mut local_var_req_builder =
107            local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
108
109        if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
110            local_var_req_builder = local_var_req_builder
111                .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
112        }
113        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
114            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
115        };
116
117        let local_var_req = local_var_req_builder.build()?;
118        let local_var_resp = local_var_client.execute(local_var_req).await?;
119
120        let local_var_status = local_var_resp.status();
121        let local_var_content = local_var_resp.text().await?;
122
123        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
124            Ok(())
125        } else {
126            let local_var_entity: Option<GetVersionError> =
127                serde_json::from_str(&local_var_content).ok();
128            let local_var_error = ResponseContent {
129                status: local_var_status,
130                content: local_var_content,
131                entity: local_var_entity,
132            };
133            Err(Error::ResponseError(local_var_error))
134        }
135    }
136}
137
138/// struct for typed errors of method [`InfoApi::get_alive`]
139#[derive(Debug, Clone, Serialize, Deserialize)]
140#[serde(untagged)]
141pub enum GetAliveError {
142    UnknownValue(serde_json::Value),
143}
144/// struct for typed errors of method [`InfoApi::get_version`]
145#[derive(Debug, Clone, Serialize, Deserialize)]
146#[serde(untagged)]
147pub enum GetVersionError {
148    UnknownValue(serde_json::Value),
149}