bitwarden_api_api/apis/
hibp_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 [`hibp_breach_get`]
18#[derive(Debug, Clone, Serialize, Deserialize)]
19#[serde(untagged)]
20pub enum HibpBreachGetError {
21    UnknownValue(serde_json::Value),
22}
23
24pub async fn hibp_breach_get(
25    configuration: &configuration::Configuration,
26    username: Option<&str>,
27) -> Result<(), Error<HibpBreachGetError>> {
28    // add a prefix to parameters to efficiently prevent name collisions
29    let p_username = username;
30
31    let uri_str = format!("{}/hibp/breach", configuration.base_path);
32    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
33
34    if let Some(ref param_value) = p_username {
35        req_builder = req_builder.query(&[("username", &param_value.to_string())]);
36    }
37    if let Some(ref user_agent) = configuration.user_agent {
38        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
39    }
40    if let Some(ref token) = configuration.oauth_access_token {
41        req_builder = req_builder.bearer_auth(token.to_owned());
42    };
43
44    let req = req_builder.build()?;
45    let resp = configuration.client.execute(req).await?;
46
47    let status = resp.status();
48
49    if !status.is_client_error() && !status.is_server_error() {
50        Ok(())
51    } else {
52        let content = resp.text().await?;
53        let entity: Option<HibpBreachGetError> = serde_json::from_str(&content).ok();
54        Err(Error::ResponseError(ResponseContent {
55            status,
56            content,
57            entity,
58        }))
59    }
60}