Skip to main content

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