bitwarden_api_api/apis/
config_api.rs1use reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum ConfigGetError {
21 UnknownValue(serde_json::Value),
22}
23
24pub async fn config_get(
25 configuration: &configuration::Configuration,
26) -> Result<models::ConfigResponseModel, Error<ConfigGetError>> {
27 let uri_str = format!("{}/config", configuration.base_path);
28 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
29
30 if let Some(ref user_agent) = configuration.user_agent {
31 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
32 }
33 if let Some(ref token) = configuration.oauth_access_token {
34 req_builder = req_builder.bearer_auth(token.to_owned());
35 };
36
37 let req = req_builder.build()?;
38 let resp = configuration.client.execute(req).await?;
39
40 let status = resp.status();
41 let content_type = resp
42 .headers()
43 .get("content-type")
44 .and_then(|v| v.to_str().ok())
45 .unwrap_or("application/octet-stream");
46 let content_type = super::ContentType::from(content_type);
47
48 if !status.is_client_error() && !status.is_server_error() {
49 let content = resp.text().await?;
50 match content_type {
51 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
52 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigResponseModel`"))),
53 ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ConfigResponseModel`")))),
54 }
55 } else {
56 let content = resp.text().await?;
57 let entity: Option<ConfigGetError> = serde_json::from_str(&content).ok();
58 Err(Error::ResponseError(ResponseContent {
59 status,
60 content,
61 entity,
62 }))
63 }
64}