bitwarden_api_api/apis/
import_ciphers_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 ImportCiphersApi: Send + Sync {
29 async fn post_import<'a>(
31 &self,
32 import_ciphers_request_model: Option<models::ImportCiphersRequestModel>,
33 ) -> Result<(), Error<PostImportError>>;
34
35 async fn post_import_organization<'a>(
37 &self,
38 organization_id: Option<&'a str>,
39 import_organization_ciphers_request_model: Option<
40 models::ImportOrganizationCiphersRequestModel,
41 >,
42 ) -> Result<(), Error<PostImportOrganizationError>>;
43}
44
45pub struct ImportCiphersApiClient {
46 configuration: Arc<configuration::Configuration>,
47}
48
49impl ImportCiphersApiClient {
50 pub fn new(configuration: Arc<configuration::Configuration>) -> Self {
51 Self { configuration }
52 }
53}
54
55#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
56#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
57impl ImportCiphersApi for ImportCiphersApiClient {
58 async fn post_import<'a>(
59 &self,
60 import_ciphers_request_model: Option<models::ImportCiphersRequestModel>,
61 ) -> Result<(), Error<PostImportError>> {
62 let local_var_configuration = &self.configuration;
63
64 let local_var_client = &local_var_configuration.client;
65
66 let local_var_uri_str = format!("{}/ciphers/import", local_var_configuration.base_path);
67 let mut local_var_req_builder =
68 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
69
70 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
71 local_var_req_builder = local_var_req_builder
72 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
73 }
74 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
75 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
76 };
77 local_var_req_builder = local_var_req_builder.json(&import_ciphers_request_model);
78
79 let local_var_req = local_var_req_builder.build()?;
80 let local_var_resp = local_var_client.execute(local_var_req).await?;
81
82 let local_var_status = local_var_resp.status();
83 let local_var_content = local_var_resp.text().await?;
84
85 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
86 Ok(())
87 } else {
88 let local_var_entity: Option<PostImportError> =
89 serde_json::from_str(&local_var_content).ok();
90 let local_var_error = ResponseContent {
91 status: local_var_status,
92 content: local_var_content,
93 entity: local_var_entity,
94 };
95 Err(Error::ResponseError(local_var_error))
96 }
97 }
98
99 async fn post_import_organization<'a>(
100 &self,
101 organization_id: Option<&'a str>,
102 import_organization_ciphers_request_model: Option<
103 models::ImportOrganizationCiphersRequestModel,
104 >,
105 ) -> Result<(), Error<PostImportOrganizationError>> {
106 let local_var_configuration = &self.configuration;
107
108 let local_var_client = &local_var_configuration.client;
109
110 let local_var_uri_str = format!(
111 "{}/ciphers/import-organization",
112 local_var_configuration.base_path
113 );
114 let mut local_var_req_builder =
115 local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
116
117 if let Some(ref param_value) = organization_id {
118 local_var_req_builder =
119 local_var_req_builder.query(&[("organizationId", ¶m_value.to_string())]);
120 }
121 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
122 local_var_req_builder = local_var_req_builder
123 .header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
124 }
125 if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
126 local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
127 };
128 local_var_req_builder =
129 local_var_req_builder.json(&import_organization_ciphers_request_model);
130
131 let local_var_req = local_var_req_builder.build()?;
132 let local_var_resp = local_var_client.execute(local_var_req).await?;
133
134 let local_var_status = local_var_resp.status();
135 let local_var_content = local_var_resp.text().await?;
136
137 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
138 Ok(())
139 } else {
140 let local_var_entity: Option<PostImportOrganizationError> =
141 serde_json::from_str(&local_var_content).ok();
142 let local_var_error = ResponseContent {
143 status: local_var_status,
144 content: local_var_content,
145 entity: local_var_entity,
146 };
147 Err(Error::ResponseError(local_var_error))
148 }
149 }
150}
151
152#[derive(Debug, Clone, Serialize, Deserialize)]
154#[serde(untagged)]
155pub enum PostImportError {
156 UnknownValue(serde_json::Value),
157}
158#[derive(Debug, Clone, Serialize, Deserialize)]
160#[serde(untagged)]
161pub enum PostImportOrganizationError {
162 UnknownValue(serde_json::Value),
163}