Skip to main content

bitwarden_importers/importers/onepassword/
mod.rs

1//! 1Password importer.
2//!
3//! [`access`] is the Bitwarden-agnostic client that logs in and downloads the vaults.
4//! [`convert`] maps what it returns onto the importer's parsed shape.
5
6pub(crate) mod access;
7pub(crate) mod convert;
8
9use access::OnePasswordError;
10
11use crate::ImportError;
12
13impl From<OnePasswordError> for ImportError {
14    fn from(error: OnePasswordError) -> Self {
15        match error {
16            OnePasswordError::BadCredentials => ImportError::OnePasswordBadCredentials,
17            OnePasswordError::InvalidEmail => ImportError::OnePasswordInvalidEmail,
18            OnePasswordError::InvalidSignInAddress(_) => {
19                ImportError::OnePasswordInvalidSignInAddress
20            }
21            OnePasswordError::InvalidAccountKey(_) => ImportError::OnePasswordInvalidSecretKey,
22            OnePasswordError::TwoFactorRequired => ImportError::OnePasswordTwoFactorRequired,
23            OnePasswordError::TwoFactorFailed => ImportError::OnePasswordTwoFactorFailed,
24            OnePasswordError::Unsupported(what) => ImportError::OnePasswordUnsupported(what),
25            OnePasswordError::Network(what) => ImportError::OnePasswordNetwork(what),
26            // A payload that will not decrypt or parse is the same story to a user: the account
27            // came back unreadable.
28            OnePasswordError::Decryption | OnePasswordError::Parse => {
29                ImportError::OnePasswordDecryption
30            }
31            // Neither of these can reach a caller as anything actionable, so they read as a
32            // transport failure with the detail kept.
33            OnePasswordError::NotFound => {
34                ImportError::OnePasswordNetwork("the account or vault was not found".to_string())
35            }
36            OnePasswordError::Internal(what) => ImportError::OnePasswordNetwork(what),
37            error @ OnePasswordError::UnexpectedStatus { .. } => {
38                ImportError::OnePasswordNetwork(error.to_string())
39            }
40        }
41    }
42}