Skip to content

[PM-21691] - Added tree and test with implementation for CollectionView #279

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

Draft
wants to merge 23 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c50f843
Added tree and test with implementation for CollectionView
jrmccannon May 16, 2025
b0dbb1c
Added tests around parent node not existing and still forming a tree โ€ฆ
jrmccannon May 27, 2025
b9385af
Update crates/bitwarden-vault/src/tree.rs
jrmccannon May 28, 2025
de6d01f
Merge branch 'main' into jmccannon/ac/pm-21691-nested-tree
jrmccannon May 28, 2025
c66aee8
code review changes.
jrmccannon May 28, 2025
63c3213
Code review test changes.
jrmccannon May 28, 2025
10e7808
linting changes
jrmccannon May 28, 2025
0c80200
linting changes
jrmccannon May 28, 2025
46c5a12
linting changes
jrmccannon May 28, 2025
2c32732
Error on sync.rs.
jrmccannon Jun 3, 2025
aa2fe56
fix: unconvertable error
coroiu Jun 4, 2025
76ae039
fixed imports in exporter
jrmccannon Jun 4, 2025
c1d8061
importing the correct collections
jrmccannon Jun 4, 2025
b93a707
Added get_collection_tree to the collection_client.rs. Added wasm-binโ€ฆ
jrmccannon Jun 5, 2025
349cb9e
added tsify-next
jrmccannon Jun 5, 2025
0665db0
added tsify-next
jrmccannon Jun 5, 2025
f226d55
Merge branch 'main' into jmccannon/ac/pm-21691-nested-tree
jrmccannon Jun 5, 2025
3278a8f
fixed up warnings and errors.
jrmccannon Jun 6, 2025
342c6bd
Added readme and documentation.
jrmccannon Jun 6, 2025
6c2d931
Sorting collections
jrmccannon Jun 6, 2025
3b4d570
Lint fixing
jrmccannon Jun 6, 2025
b1c147e
Lint fixing :shrug: and some grammatical fixes.
jrmccannon Jun 6, 2025
1a4a122
Added a hashmap to improve lookup efficiency against the index list
jrmccannon Jun 6, 2025
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
23 changes: 21 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ bitwarden = { path = "crates/bitwarden", version = "=1.0.0" }
bitwarden-api-api = { path = "crates/bitwarden-api-api", version = "=1.0.0" }
bitwarden-api-identity = { path = "crates/bitwarden-api-identity", version = "=1.0.0" }
bitwarden-cli = { path = "crates/bitwarden-cli", version = "=1.0.0" }
bitwarden-collections = { path = "crates/bitwarden-collections", version = "=1.0.0" }
bitwarden-core = { path = "crates/bitwarden-core", version = "=1.0.0" }
bitwarden-crypto = { path = "crates/bitwarden-crypto", version = "=1.0.0" }
bitwarden-error = { path = "crates/bitwarden-error", version = "=1.0.0" }
Expand Down
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,21 @@ You can also browse the latest published documentation:
The project is structured as a monorepo using cargo workspaces. Some of the more noteworthy crates
are:

- [`bitwarden-api-api`](./crates/bitwarden-api-api/): Auto-generated API bindings for the API
- [`bitwarden-api-api`](./crates/bitwarden-api-api): Auto-generated API bindings for the API
server.
- [`bitwarden-api-identity`](./crates/bitwarden-api-identity/): Auto-generated API bindings for the
- [`bitwarden-api-identity`](./crates/bitwarden-api-identity): Auto-generated API bindings for the
Identity server.
- [`bitwarden-core`](./crates/bitwarden-core/): The core functionality consumed by the other crates.
- [`bitwarden-crypto`](./crates/bitwarden-crypto/): Crypto library.
- [`bitwarden-wasm-internal`](./crates/bitwarden-wasm-internal/): WASM bindings for the internal
- [`bitwarden-core`](./crates/bitwarden-core): The core functionality consumed by the other crates.
- [`bitwarden-crypto`](./crates/bitwarden-crypto): Crypto library.
- [`bitwarden-wasm-internal`](./crates/bitwarden-wasm-internal): WASM bindings for the internal
SDK.
- [`bitwarden-uniffi`](./crates/bitwarden-uniffi/): Mobile bindings for swift and kotlin using
- [`bitwarden-uniffi`](./crates/bitwarden-uniffi): Mobile bindings for swift and kotlin using
[UniFFI](https://github.com/mozilla/uniffi-rs/).

## API Bindings

We autogenerate the server bindings using
[openapi-generator](https://github.com/OpenAPITools/openapi-generator). To do this we first need to
build the internal swagger documentation.
We autogenerate the server bindings using[openapi-generator](https://github.com/OpenAPITools/openapi-generator).
To do this, we first need to build the internal swagger documentation.

### Swagger generation

Expand All @@ -83,14 +82,14 @@ ASPNETCORE_ENVIRONMENT=development dotnet swagger tofile --output ../../identity

### OpenApi Generator

To generate a new version of the bindings run the following script from the root of the SDK project.
To generate a new version of the bindings, run the following script from the root of the SDK project.

```bash
./support/build-api.sh
```

This project uses customized templates which lives in the `support/openapi-templates` directory.
These templates resolves some outstanding issues we've experienced with the rust generator. But we
This project uses customized templates that live in the `support/openapi-templates` directory.
These templates resolve some outstanding issues we've experienced with the rust generator. But we
strive towards modifying the templates as little as possible to ease future upgrades.

### Note
Expand All @@ -102,8 +101,8 @@ strive towards modifying the templates as little as possible to ease future upgr

## Developer tools

This project recommends the use of certain developer tools, and also includes configurations for
them to make developers lives easier. The use of these tools is optional and they might require a
This project recommends the use of certain developer tools and includes configurations for
them to make developers' lives easier. The use of these tools is optional, and they might require a
separate installation step.

The list of developer tools is:
Expand All @@ -122,12 +121,12 @@ The list of developer tools is:
## Formatting & Linting

This repository uses various tools to check formatting and linting before it's merged. It's
recommended to run the checks prior to submitting a PR.
recommended to run the checks before submitting a PR.

### Installation

Please see the [lint.yml](./.github/workflows/lint.yml) file for example installation commands &
versions. Here are the cli tools we use:
Please see the [lint.yml](./.github/workflows/lint.yml) file, for example, installation commands and versions. Here are the
cli tools we use:

- Nightly [cargo fmt](https://github.com/rust-lang/rustfmt) and
[cargo udeps](https://github.com/est31/cargo-udeps)
Expand Down
34 changes: 34 additions & 0 deletions crates/bitwarden-collections/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "bitwarden-collections"
version.workspace = true
authors.workspace = true
edition.workspace = true
rust-version.workspace = true
homepage.workspace = true
repository.workspace = true
license-file.workspace = true
readme.workspace = true
keywords.workspace = true

[features]
uniffi = [
"bitwarden-core/uniffi",
"bitwarden-crypto/uniffi",
"dep:uniffi",
] # Uniffi bindings
wasm = ["dep:tsify-next", "dep:wasm-bindgen"] # WASM support

[dependencies]
bitwarden-api-api = { workspace = true }
bitwarden-core = { workspace = true, features = ["internal"] }
bitwarden-crypto = { workspace = true }
bitwarden-error = { workspace = true }
serde = { workspace = true }
thiserror = { workspace = true }
tsify-next = { workspace = true, optional = true }
uniffi = { workspace = true, optional = true }
uuid = { workspace = true }
wasm-bindgen = { workspace = true, optional = true }

[lints]
workspace = true
5 changes: 5 additions & 0 deletions crates/bitwarden-collections/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Bitwarden Collections

Defines the data model for collections both encrypted and decrypted. It also handles conversions between those two
states by implementing `Encryptable`. It also provides `Tree` struct which allows all structs implementing `TreeItem`
to be represented in a tree structure along with functions to access each node.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::VaultParseError;
use crate::{error::CollectionsParseError, tree::TreeItem};

#[allow(missing_docs)]
#[derive(Serialize, Deserialize, Debug)]
Expand All @@ -31,7 +31,7 @@
}

#[allow(missing_docs)]
#[derive(Serialize, Deserialize, Debug)]
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))]
pub struct CollectionView {
Expand All @@ -46,12 +46,7 @@
pub manage: bool,
}

impl IdentifyKey<SymmetricKeyId> for Collection {
fn key_identifier(&self) -> SymmetricKeyId {
SymmetricKeyId::Organization(self.organization_id)
}
}

#[allow(missing_docs)]
impl Decryptable<KeyIds, SymmetricKeyId, CollectionView> for Collection {
fn decrypt(
&self,
Expand All @@ -72,8 +67,9 @@
}
}

#[allow(missing_docs)]
impl TryFrom<CollectionDetailsResponseModel> for Collection {
type Error = VaultParseError;
type Error = CollectionsParseError;

fn try_from(collection: CollectionDetailsResponseModel) -> Result<Self, Self::Error> {
Ok(Collection {
Expand All @@ -87,3 +83,30 @@
})
}
}

#[allow(missing_docs)]
impl IdentifyKey<SymmetricKeyId> for Collection {
fn key_identifier(&self) -> SymmetricKeyId {
SymmetricKeyId::Organization(self.organization_id)
}
}

#[allow(missing_docs)]
impl TreeItem for CollectionView {
fn id(&self) -> Uuid {
self.id.unwrap_or_default()
}

Check warning on line 98 in crates/bitwarden-collections/src/collection.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-collections/src/collection.rs#L96-L98

Added lines #L96 - L98 were not covered by tests

fn short_name(&self) -> &str {
self.path().last().unwrap_or(&"")
}

Check warning on line 102 in crates/bitwarden-collections/src/collection.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-collections/src/collection.rs#L100-L102

Added lines #L100 - L102 were not covered by tests

fn path(&self) -> Vec<&str> {
self.name
.split(Self::DELIMITER)
.filter(|s| !s.is_empty())
.collect::<Vec<&str>>()
}

Check warning on line 109 in crates/bitwarden-collections/src/collection.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-collections/src/collection.rs#L104-L109

Added lines #L104 - L109 were not covered by tests

const DELIMITER: char = '/';
}
19 changes: 19 additions & 0 deletions crates/bitwarden-collections/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use bitwarden_error::bitwarden_error;
use thiserror::Error;

#[allow(missing_docs)]
#[bitwarden_error(flat)]

Check warning on line 5 in crates/bitwarden-collections/src/error.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-collections/src/error.rs#L5

Added line #L5 was not covered by tests
#[derive(Debug, Error)]
pub enum CollectionDecryptError {
#[error(transparent)]
Crypto(#[from] bitwarden_crypto::CryptoError),
}

#[allow(missing_docs)]
#[derive(Debug, Error)]
pub enum CollectionsParseError {
#[error(transparent)]
Crypto(#[from] bitwarden_crypto::CryptoError),
#[error(transparent)]
MissingFieldError(#[from] bitwarden_core::MissingFieldError),
}
19 changes: 19 additions & 0 deletions crates/bitwarden-collections/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#![doc = include_str!("../README.md")]

#[cfg(feature = "uniffi")]
uniffi::setup_scaffolding!();

Check warning on line 4 in crates/bitwarden-collections/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-collections/src/lib.rs#L4

Added line #L4 was not covered by tests
#[cfg(feature = "uniffi")]
mod uniffi_support;

///
/// Module containing the collection data models. It also contains the implementations for
/// Encryptable, TryFrom, and TreeItem
pub mod collection;
///
/// Module containing the error types.
pub mod error;
///
/// Module containing Tree struct that is a tree representation of all structs implementing TreeItem
/// trait. It is made using an index vector to hold the data and another vector to hold the
/// parent child relationships between those nodes.
pub mod tree;
Loading
Loading