bitwarden_api_api/apis/
users_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 reqwest;
12use serde::{de::Error as _, Deserialize, Serialize};
13
14use super::{configuration, ContentType, Error};
15use crate::{apis::ResponseContent, models};
16
17/// struct for typed errors of method [`users_id_public_key_get`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum UsersIdPublicKeyGetError {
21    UnknownValue(serde_json::Value),
22}
23
24pub async fn users_id_public_key_get(
25    configuration: &configuration::Configuration,
26    id: &str,
27) -> Result<models::UserKeyResponseModel, Error<UsersIdPublicKeyGetError>> {
28    // add a prefix to parameters to efficiently prevent name collisions
29    let p_id = id;
30
31    let uri_str = format!(
32        "{}/users/{id}/public-key",
33        configuration.base_path,
34        id = crate::apis::urlencode(p_id)
35    );
36    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
37
38    if let Some(ref user_agent) = configuration.user_agent {
39        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
40    }
41    if let Some(ref token) = configuration.oauth_access_token {
42        req_builder = req_builder.bearer_auth(token.to_owned());
43    };
44
45    let req = req_builder.build()?;
46    let resp = configuration.client.execute(req).await?;
47
48    let status = resp.status();
49    let content_type = resp
50        .headers()
51        .get("content-type")
52        .and_then(|v| v.to_str().ok())
53        .unwrap_or("application/octet-stream");
54    let content_type = super::ContentType::from(content_type);
55
56    if !status.is_client_error() && !status.is_server_error() {
57        let content = resp.text().await?;
58        match content_type {
59            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
60            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::UserKeyResponseModel`"))),
61            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::UserKeyResponseModel`")))),
62        }
63    } else {
64        let content = resp.text().await?;
65        let entity: Option<UsersIdPublicKeyGetError> = serde_json::from_str(&content).ok();
66        Err(Error::ResponseError(ResponseContent {
67            status,
68            content,
69            entity,
70        }))
71    }
72}