Skip to main content

bitwarden_importers/
import.rs

1//! Routing: maps each importer's public entry to its parser + the generic submit pipeline.
2
3use bitwarden_core::Client;
4
5use crate::{
6    Credentials, ImportError, ImportOptions, ImportSummary, OnePasswordTwoFactorUi,
7    importers::{
8        self,
9        onepassword::{access, convert},
10    },
11    pipeline,
12};
13
14/// See [crate::ImporterClient::import_kdbx] for more documentation.
15pub(crate) async fn import_kdbx(
16    client: &Client,
17    file: Vec<u8>,
18    password: Option<String>,
19    key_file: Option<Vec<u8>>,
20    options: ImportOptions,
21) -> Result<ImportSummary, ImportError> {
22    let parsed = importers::kdbx::parse(file, password, key_file)?;
23    pipeline::submit_import(client, parsed, options).await
24}
25
26/// See [crate::ImporterClient::import_onepassword] for more documentation.
27pub(crate) async fn import_onepassword(
28    client: &Client,
29    credentials: Credentials,
30    two_factor: &dyn OnePasswordTwoFactorUi,
31    options: ImportOptions,
32) -> Result<ImportSummary, ImportError> {
33    // 1Password is a third-party host, so this goes through the client's external transport rather
34    // than the one configured for the Bitwarden API.
35    let onepassword = access::Client::new(client.internal.get_http_client().clone());
36    let vaults = onepassword
37        .download_all_vaults(credentials, two_factor)
38        .await?;
39
40    pipeline::submit_import(client, convert::convert(vaults), options).await
41}