bitwarden_api_api/apis/
import_ciphers_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 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::{AuthRequired, 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    /// POST /ciphers/import
30    async fn post_import<'a>(
31        &self,
32        import_ciphers_request_model: Option<models::ImportCiphersRequestModel>,
33    ) -> Result<(), Error<PostImportError>>;
34
35    /// POST /ciphers/import-organization
36    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_token) = local_var_configuration.oauth_access_token {
71            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
72        };
73        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
74        local_var_req_builder = local_var_req_builder.json(&import_ciphers_request_model);
75
76        let local_var_req = local_var_req_builder.build()?;
77        let local_var_resp = local_var_client.execute(local_var_req).await?;
78
79        let local_var_status = local_var_resp.status();
80        let local_var_content = local_var_resp.text().await?;
81
82        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
83            Ok(())
84        } else {
85            let local_var_entity: Option<PostImportError> =
86                serde_json::from_str(&local_var_content).ok();
87            let local_var_error = ResponseContent {
88                status: local_var_status,
89                content: local_var_content,
90                entity: local_var_entity,
91            };
92            Err(Error::ResponseError(local_var_error))
93        }
94    }
95
96    async fn post_import_organization<'a>(
97        &self,
98        organization_id: Option<&'a str>,
99        import_organization_ciphers_request_model: Option<
100            models::ImportOrganizationCiphersRequestModel,
101        >,
102    ) -> Result<(), Error<PostImportOrganizationError>> {
103        let local_var_configuration = &self.configuration;
104
105        let local_var_client = &local_var_configuration.client;
106
107        let local_var_uri_str = format!(
108            "{}/ciphers/import-organization",
109            local_var_configuration.base_path
110        );
111        let mut local_var_req_builder =
112            local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
113
114        if let Some(ref param_value) = organization_id {
115            local_var_req_builder =
116                local_var_req_builder.query(&[("organizationId", &param_value.to_string())]);
117        }
118        if let Some(ref local_var_token) = local_var_configuration.oauth_access_token {
119            local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
120        };
121        local_var_req_builder = local_var_req_builder.with_extension(AuthRequired::Bearer);
122        local_var_req_builder =
123            local_var_req_builder.json(&import_organization_ciphers_request_model);
124
125        let local_var_req = local_var_req_builder.build()?;
126        let local_var_resp = local_var_client.execute(local_var_req).await?;
127
128        let local_var_status = local_var_resp.status();
129        let local_var_content = local_var_resp.text().await?;
130
131        if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
132            Ok(())
133        } else {
134            let local_var_entity: Option<PostImportOrganizationError> =
135                serde_json::from_str(&local_var_content).ok();
136            let local_var_error = ResponseContent {
137                status: local_var_status,
138                content: local_var_content,
139                entity: local_var_entity,
140            };
141            Err(Error::ResponseError(local_var_error))
142        }
143    }
144}
145
146/// struct for typed errors of method [`ImportCiphersApi::post_import`]
147#[derive(Debug, Clone, Serialize, Deserialize)]
148#[serde(untagged)]
149pub enum PostImportError {
150    UnknownValue(serde_json::Value),
151}
152/// struct for typed errors of method [`ImportCiphersApi::post_import_organization`]
153#[derive(Debug, Clone, Serialize, Deserialize)]
154#[serde(untagged)]
155pub enum PostImportOrganizationError {
156    UnknownValue(serde_json::Value),
157}