Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP attachment export #255

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/bitwarden-uniffi/src/tool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
Ok(self
.0
.0
.read()
.write()

Check warning on line 68 in crates/bitwarden-uniffi/src/tool/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-uniffi/src/tool/mod.rs#L68

Added line #L68 was not covered by tests
.await
.exporters()
.export_vault(folders, ciphers, format)
Expand All @@ -82,7 +82,7 @@
Ok(self
.0
.0
.read()
.write()

Check warning on line 85 in crates/bitwarden-uniffi/src/tool/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-uniffi/src/tool/mod.rs#L85

Added line #L85 was not covered by tests
.await
.exporters()
.export_organization_vault(collections, ciphers, format)
Expand Down
9 changes: 7 additions & 2 deletions crates/bitwarden/src/tool/exporters/client_exporter.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use super::export_vault_attachments;
use crate::{
error::Result,
tool::exporters::{export_organization_vault, export_vault, ExportFormat},
Expand All @@ -6,7 +7,7 @@
};

pub struct ClientExporters<'a> {
pub(crate) client: &'a crate::Client,
pub(crate) client: &'a mut crate::Client,
}

impl<'a> ClientExporters<'a> {
Expand All @@ -28,10 +29,14 @@
) -> Result<String> {
export_organization_vault(collections, ciphers, format)
}

pub async fn export_vault_attachments(&mut self) -> Result<()> {
export_vault_attachments(self.client).await
}

Check warning on line 35 in crates/bitwarden/src/tool/exporters/client_exporter.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/client_exporter.rs#L33-L35

Added lines #L33 - L35 were not covered by tests
}

impl<'a> Client {
pub fn exporters(&'a self) -> ClientExporters<'a> {
pub fn exporters(&'a mut self) -> ClientExporters<'a> {

Check warning on line 39 in crates/bitwarden/src/tool/exporters/client_exporter.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/client_exporter.rs#L39

Added line #L39 was not covered by tests
ClientExporters { client: self }
}
}
62 changes: 60 additions & 2 deletions crates/bitwarden/src/tool/exporters/mod.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
use std::{fs::File, io::Write};

use bitwarden_crypto::Decryptable;
use bitwarden_exporters::export;
use log::{debug, info};
use schemars::JsonSchema;

use crate::{
client::{LoginMethod, UserLoginMethod},
error::{Error, Result},
platform::SyncRequest,
vault::{
login::LoginUriView, Cipher, CipherType, CipherView, Collection, FieldView, Folder,
FolderView, SecureNoteType,
download_attachment, login::LoginUriView, Cipher, CipherType, CipherView, Collection,
FieldView, Folder, FolderView, SecureNoteType,
},
Client,
};
Expand Down Expand Up @@ -78,6 +82,60 @@
todo!();
}

pub(super) async fn export_vault_attachments(client: &mut Client) -> Result<()> {
info!("Syncing vault");
let sync = client
.sync(&SyncRequest {
exclude_subdomains: None,
})
.await?;

Check warning on line 91 in crates/bitwarden/src/tool/exporters/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/mod.rs#L85-L91

Added lines #L85 - L91 were not covered by tests

debug!("{:#?}", sync);

Check warning on line 93 in crates/bitwarden/src/tool/exporters/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/mod.rs#L93

Added line #L93 was not covered by tests

info!("Vault synced got {} ciphers", sync.ciphers.len());

Check warning on line 95 in crates/bitwarden/src/tool/exporters/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/mod.rs#L95

Added line #L95 was not covered by tests

let folders = sync.folders;
let ciphers = sync.ciphers;

Check warning on line 98 in crates/bitwarden/src/tool/exporters/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/mod.rs#L97-L98

Added lines #L97 - L98 were not covered by tests

let mut f = File::create("export.csv")?;
f.write_all(
export_vault(client, folders.clone(), ciphers.clone(), ExportFormat::Csv)?.as_bytes(),
)?;

Check warning on line 103 in crates/bitwarden/src/tool/exporters/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/mod.rs#L100-L103

Added lines #L100 - L103 were not covered by tests

let mut f = File::create("export.json")?;
f.write_all(export_vault(client, folders, ciphers.clone(), ExportFormat::Json)?.as_bytes())?;

Check warning on line 106 in crates/bitwarden/src/tool/exporters/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/mod.rs#L105-L106

Added lines #L105 - L106 were not covered by tests

let ciphers_with_attachments = ciphers
.iter()
.filter(|c| c.attachments.as_ref().is_some_and(|a| !a.is_empty()));

Check warning on line 110 in crates/bitwarden/src/tool/exporters/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/mod.rs#L108-L110

Added lines #L108 - L110 were not covered by tests

info!(
"Found {} ciphers with attachments",
ciphers_with_attachments.count()

Check warning on line 114 in crates/bitwarden/src/tool/exporters/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/mod.rs#L113-L114

Added lines #L113 - L114 were not covered by tests
);

info!("Decrypting ciphers");

Check warning on line 117 in crates/bitwarden/src/tool/exporters/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/mod.rs#L117

Added line #L117 was not covered by tests

let enc_settings = client.get_encryption_settings()?;

Check warning on line 119 in crates/bitwarden/src/tool/exporters/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/mod.rs#L119

Added line #L119 was not covered by tests

let decrypted: Vec<CipherView> = ciphers
.iter()
.map(|c| c.decrypt(enc_settings, &None).unwrap())
.collect();

let num_attachments = decrypted.iter().flat_map(|c| &c.attachments).count();

Check warning on line 126 in crates/bitwarden/src/tool/exporters/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/mod.rs#L121-L126

Added lines #L121 - L126 were not covered by tests

info!("Found {} attachments, starting export", num_attachments);

Check warning on line 128 in crates/bitwarden/src/tool/exporters/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/mod.rs#L128

Added line #L128 was not covered by tests

for cipher in decrypted {
for attachment in cipher.attachments.unwrap_or_default() {
download_attachment(client, cipher.id.unwrap(), &attachment.id.unwrap()).await?;

Check warning on line 132 in crates/bitwarden/src/tool/exporters/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/mod.rs#L130-L132

Added lines #L130 - L132 were not covered by tests
}
}

Ok(())
}

Check warning on line 137 in crates/bitwarden/src/tool/exporters/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/tool/exporters/mod.rs#L136-L137

Added lines #L136 - L137 were not covered by tests

impl TryFrom<FolderView> for bitwarden_exporters::Folder {
type Error = Error;

Expand Down
7 changes: 7 additions & 0 deletions crates/bitwarden/src/vault/api/attachment.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use reqwest::Response;

use crate::error::Result;

pub(crate) async fn attachment_get(url: &str) -> Result<Response> {
reqwest::get(url).await.map_err(|e| e.into())
}

Check warning on line 7 in crates/bitwarden/src/vault/api/attachment.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/api/attachment.rs#L5-L7

Added lines #L5 - L7 were not covered by tests
2 changes: 2 additions & 0 deletions crates/bitwarden/src/vault/api/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod attachment;
pub(super) use attachment::attachment_get;
60 changes: 58 additions & 2 deletions crates/bitwarden/src/vault/cipher/attachment.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
use std::{
fs::{create_dir_all, File},
io::Write,
path::Path,
};

use bitwarden_api_api::apis::ciphers_api::ciphers_id_attachment_attachment_id_get;
use bitwarden_crypto::{
CryptoError, EncString, KeyDecryptable, KeyEncryptable, SymmetricCryptoKey,
};
use log::debug;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use super::Cipher;
use crate::error::{Error, Result};
use crate::{
error::{Error, Result},
vault::api::attachment_get,
Client,
};

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]

Check warning on line 23 in crates/bitwarden/src/vault/cipher/attachment.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/attachment.rs#L23

Added line #L23 was not covered by tests
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct Attachment {
Expand All @@ -32,6 +45,49 @@
pub key: Option<EncString>,
}

pub async fn download_attachment(
client: &mut Client,
cipher_id: Uuid,
attachment_id: &str,
) -> Result<Vec<u8>> {

Check warning on line 52 in crates/bitwarden/src/vault/cipher/attachment.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/attachment.rs#L48-L52

Added lines #L48 - L52 were not covered by tests
// The attachments from sync doesn't contain the correct url
let configuration = &client.get_api_configurations().await.api;
let response = ciphers_id_attachment_attachment_id_get(
configuration,
cipher_id,
attachment_id.to_string().as_str(),
)
.await?;

Check warning on line 60 in crates/bitwarden/src/vault/cipher/attachment.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/attachment.rs#L54-L60

Added lines #L54 - L60 were not covered by tests

let attachment: Attachment = response.try_into()?;
let enc = client.get_encryption_settings()?;
let k = enc.get_key(&None).ok_or(Error::VaultLocked)?;

Check warning on line 64 in crates/bitwarden/src/vault/cipher/attachment.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/attachment.rs#L62-L64

Added lines #L62 - L64 were not covered by tests

let view = attachment.decrypt_with_key(k)?;
let mut cipher_key: Vec<u8> = view.key.unwrap().decrypt_with_key(k)?;

Check warning on line 67 in crates/bitwarden/src/vault/cipher/attachment.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/attachment.rs#L66-L67

Added lines #L66 - L67 were not covered by tests

let key = SymmetricCryptoKey::try_from(cipher_key.as_mut_slice())?;

Check warning on line 69 in crates/bitwarden/src/vault/cipher/attachment.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/attachment.rs#L69

Added line #L69 was not covered by tests

let response = attachment_get(&view.url.unwrap()).await?;
let bytes = response.bytes().await?;

Check warning on line 72 in crates/bitwarden/src/vault/cipher/attachment.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/attachment.rs#L71-L72

Added lines #L71 - L72 were not covered by tests

let buf = EncString::from_buffer(&bytes)?;
let dec: Vec<u8> = buf.decrypt_with_key(&key)?;

Check warning on line 75 in crates/bitwarden/src/vault/cipher/attachment.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/attachment.rs#L74-L75

Added lines #L74 - L75 were not covered by tests

let path = Path::new("attachments")
.join(cipher_id.to_string())
.join(attachment_id)
.join(view.file_name.unwrap());

create_dir_all(path.parent().unwrap())?;
let mut file = File::create(path)?;
file.write_all(&dec)?;

Check warning on line 84 in crates/bitwarden/src/vault/cipher/attachment.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/attachment.rs#L77-L84

Added lines #L77 - L84 were not covered by tests

debug!("{:?}", bytes.len());

Check warning on line 86 in crates/bitwarden/src/vault/cipher/attachment.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/attachment.rs#L86

Added line #L86 was not covered by tests

todo!()
}

Check warning on line 89 in crates/bitwarden/src/vault/cipher/attachment.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/attachment.rs#L88-L89

Added lines #L88 - L89 were not covered by tests

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden/src/vault/cipher/card.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use crate::error::{Error, Result};

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]

Check warning on line 10 in crates/bitwarden/src/vault/cipher/card.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/card.rs#L10

Added line #L10 was not covered by tests
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct Card {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden/src/vault/cipher/cipher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
Password = 1,
}

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]

Check warning on line 40 in crates/bitwarden/src/vault/cipher/cipher.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/cipher.rs#L40

Added line #L40 was not covered by tests
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct Cipher {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden/src/vault/cipher/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
Linked = 3,
}

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]

Check warning on line 22 in crates/bitwarden/src/vault/cipher/field.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/field.rs#L22

Added line #L22 was not covered by tests
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct Field {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden/src/vault/cipher/identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use crate::error::{Error, Result};

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]

Check warning on line 10 in crates/bitwarden/src/vault/cipher/identity.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/identity.rs#L10

Added line #L10 was not covered by tests
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct Identity {
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden/src/vault/cipher/local_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]

Check warning on line 5 in crates/bitwarden/src/vault/cipher/local_data.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/local_data.rs#L5

Added line #L5 was not covered by tests
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct LocalData {
Expand Down
4 changes: 2 additions & 2 deletions crates/bitwarden/src/vault/cipher/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Never = 5,
}

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]

Check warning on line 25 in crates/bitwarden/src/vault/cipher/login.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/login.rs#L25

Added line #L25 was not covered by tests
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct LoginUri {
Expand All @@ -38,7 +38,7 @@
pub r#match: Option<UriMatchType>,
}

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Debug, Clone, JsonSchema)]

Check warning on line 41 in crates/bitwarden/src/vault/cipher/login.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/cipher/login.rs#L41

Added line #L41 was not covered by tests
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct Login {
Expand Down
3 changes: 2 additions & 1 deletion crates/bitwarden/src/vault/cipher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ pub(crate) mod login;
pub(crate) mod secure_note;

pub use attachment::{
Attachment, AttachmentEncryptResult, AttachmentFile, AttachmentFileView, AttachmentView,
download_attachment, Attachment, AttachmentEncryptResult, AttachmentFile, AttachmentFileView,
AttachmentView,
};
pub use cipher::{Cipher, CipherListView, CipherRepromptType, CipherType, CipherView};
pub use field::FieldView;
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden/src/vault/folder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use crate::error::{Error, Result};

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]

Check warning on line 12 in crates/bitwarden/src/vault/folder.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/folder.rs#L12

Added line #L12 was not covered by tests
#[serde(rename_all = "camelCase")]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct Folder {
Expand Down
1 change: 1 addition & 0 deletions crates/bitwarden/src/vault/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod api;
mod cipher;
mod collection;
mod folder;
Expand Down
2 changes: 1 addition & 1 deletion crates/bitwarden/src/vault/password_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use crate::error::{Error, Result};

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[derive(Serialize, Deserialize, Clone, Debug, JsonSchema)]

Check warning on line 11 in crates/bitwarden/src/vault/password_history.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden/src/vault/password_history.rs#L11

Added line #L11 was not covered by tests
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "mobile", derive(uniffi::Record))]
pub struct PasswordHistory {
Expand Down
2 changes: 1 addition & 1 deletion crates/bw/src/auth/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use inquire::{Password, Text};
use log::{debug, error, info};

pub(crate) async fn login_password(mut client: Client, email: Option<String>) -> Result<()> {
pub(crate) async fn login_password(client: &mut Client, email: Option<String>) -> Result<()> {

Check warning on line 14 in crates/bw/src/auth/login.rs

View check run for this annotation

Codecov / codecov/patch

crates/bw/src/auth/login.rs#L14

Added line #L14 was not covered by tests
let email = text_prompt_when_none("Email", email)?;

let password = Password::new("Password").without_confirmation().prompt()?;
Expand Down
29 changes: 26 additions & 3 deletions crates/bw/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@
#[command(subcommand)]
command: GeneratorCommands,
},

Export {
// TODO: Remove these
#[arg(short = 'e', long, help = "Email address")]
email: Option<String>,
#[arg(short = 's', long, global = true, help = "Server URL")]
server: Option<String>,
},
}

#[derive(Args, Clone)]
Expand Down Expand Up @@ -157,12 +165,12 @@
identity_url: format!("{}/identity", server),
..Default::default()
});
let client = bitwarden::Client::new(settings);
let mut client = bitwarden::Client::new(settings);

Check warning on line 168 in crates/bw/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/bw/src/main.rs#L168

Added line #L168 was not covered by tests

match args.command {
// FIXME: Rust CLI will not support password login!
LoginCommands::Password { email } => {
auth::login_password(client, email).await?;
auth::login_password(&mut client, email).await?;

Check warning on line 173 in crates/bw/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/bw/src/main.rs#L173

Added line #L173 was not covered by tests
}
LoginCommands::ApiKey {
client_id,
Expand Down Expand Up @@ -203,9 +211,23 @@
})
.await?;
}
Commands::Export { email, server } => {
let settings = server.map(|server| ClientSettings {
api_url: format!("{}/api", server),
identity_url: format!("{}/identity", server),
..Default::default()
});
let mut client = bitwarden::Client::new(settings);

auth::login_password(&mut client, email).await?;

Check warning on line 222 in crates/bw/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/bw/src/main.rs#L214-L222

Added lines #L214 - L222 were not covered by tests

client.exporters().export_vault_attachments().await?;

Check warning on line 224 in crates/bw/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/bw/src/main.rs#L224

Added line #L224 was not covered by tests

return Ok(());

Check warning on line 226 in crates/bw/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/bw/src/main.rs#L226

Added line #L226 was not covered by tests
// Export vault
}
_ => {}
}

// Not login, assuming we have a config
let client = bitwarden::Client::new(None);

Expand All @@ -215,6 +237,7 @@
Commands::Register { .. } => unreachable!(),
Commands::Item { command: _ } => todo!(),
Commands::Sync {} => todo!(),
Commands::Export { .. } => unreachable!(),

Check warning on line 240 in crates/bw/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/bw/src/main.rs#L240

Added line #L240 was not covered by tests
Commands::Generate { command } => match command {
GeneratorCommands::Password(args) => {
let password = client
Expand Down
Loading