bitwarden_api_api/apis/
phishing_domains_api.rs1use 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 PhishingDomainsApi: Send + Sync {
29 async fn get_checksum(&self) -> Result<String, Error<GetChecksumError>>;
31
32 async fn get_phishing_domains(&self) -> Result<Vec<String>, Error<GetPhishingDomainsError>>;
34}
35
36pub struct PhishingDomainsApiClient {
37 configuration: Arc<configuration::Configuration>,
38}
39
40impl PhishingDomainsApiClient {
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 PhishingDomainsApi for PhishingDomainsApiClient {
49 async fn get_checksum(&self) -> Result<String, Error<GetChecksumError>> {
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!(
55 "{}/phishing-domains/checksum",
56 local_var_configuration.base_path
57 );
58 let mut local_var_req_builder =
59 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
60
61 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
62 local_var_req_builder = local_var_req_builder
63 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
64 }
65 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
66 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
67 };
68
69 let local_var_req = local_var_req_builder.build()?;
70 let local_var_resp = local_var_client.execute(local_var_req).await?;
71
72 let local_var_status = local_var_resp.status();
73 let local_var_content_type = local_var_resp
74 .headers()
75 .get("content-type")
76 .and_then(|v| v.to_str().ok())
77 .unwrap_or("application/octet-stream");
78 let local_var_content_type = super::ContentType::from(local_var_content_type);
79 let local_var_content = local_var_resp.text().await?;
80
81 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
82 match local_var_content_type {
83 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
84 ContentType::Text => return Ok(local_var_content),
85 ContentType::Unsupported(local_var_unknown_type) => {
86 return Err(Error::from(serde_json::Error::custom(format!(
87 "Received `{local_var_unknown_type}` content type response that cannot be converted to `String`"
88 ))));
89 }
90 }
91 } else {
92 let local_var_entity: Option<GetChecksumError> =
93 serde_json::from_str(&local_var_content).ok();
94 let local_var_error = ResponseContent {
95 status: local_var_status,
96 content: local_var_content,
97 entity: local_var_entity,
98 };
99 Err(Error::ResponseError(local_var_error))
100 }
101 }
102
103 async fn get_phishing_domains(&self) -> Result<Vec<String>, Error<GetPhishingDomainsError>> {
104 let local_var_configuration = &self.configuration;
105
106 let local_var_client = &local_var_configuration.client;
107
108 let local_var_uri_str = format!("{}/phishing-domains", local_var_configuration.base_path);
109 let mut local_var_req_builder =
110 local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
111
112 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
113 local_var_req_builder = local_var_req_builder
114 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
115 }
116 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
117 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
118 };
119
120 let local_var_req = local_var_req_builder.build()?;
121 let local_var_resp = local_var_client.execute(local_var_req).await?;
122
123 let local_var_status = local_var_resp.status();
124 let local_var_content_type = local_var_resp
125 .headers()
126 .get("content-type")
127 .and_then(|v| v.to_str().ok())
128 .unwrap_or("application/octet-stream");
129 let local_var_content_type = super::ContentType::from(local_var_content_type);
130 let local_var_content = local_var_resp.text().await?;
131
132 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
133 match local_var_content_type {
134 ContentType::Json => serde_json::from_str(&local_var_content).map_err(Error::from),
135 ContentType::Text => {
136 return Err(Error::from(serde_json::Error::custom(
137 "Received `text/plain` content type response that cannot be converted to `Vec<String>`",
138 )));
139 }
140 ContentType::Unsupported(local_var_unknown_type) => {
141 return Err(Error::from(serde_json::Error::custom(format!(
142 "Received `{local_var_unknown_type}` content type response that cannot be converted to `Vec<String>`"
143 ))));
144 }
145 }
146 } else {
147 let local_var_entity: Option<GetPhishingDomainsError> =
148 serde_json::from_str(&local_var_content).ok();
149 let local_var_error = ResponseContent {
150 status: local_var_status,
151 content: local_var_content,
152 entity: local_var_entity,
153 };
154 Err(Error::ResponseError(local_var_error))
155 }
156 }
157}
158
159#[derive(Debug, Clone, Serialize, Deserialize)]
161#[serde(untagged)]
162pub enum GetChecksumError {
163 UnknownValue(serde_json::Value),
164}
165#[derive(Debug, Clone, Serialize, Deserialize)]
167#[serde(untagged)]
168pub enum GetPhishingDomainsError {
169 UnknownValue(serde_json::Value),
170}