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

[PM-14235] Add more docs to bitwarden_vault #102

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tangowithfoxtrot
Copy link
Contributor

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-14235

📔 Objective

A first attempt at documenting stuff in bitwarden_vault. I'm missing context for a lot of the why on things, so most of it is documenting the what and adding examples where I can. Admittedly, explaining the what probably isn't as useful, so I'd appreciate some pointers on how to make these docs better.

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation
    team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed
    issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

pub async fn sync(&self, input: &SyncRequest) -> Result<SyncResponse, SyncError> {
sync(self.client, input).await
}
}

/// An extension trait for the [VaultClient] struct to provide vault functionality.
pub trait VaultClientExt<'a> {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not exactly sure what these "extensions" are or will be used for.

Copy link
Contributor

github-actions bot commented Jan 3, 2025

Logo
Checkmarx One – Scan Summary & Detailsf7e1fa4e-51fc-4fd3-8c72-7ef88874ac97

No New Or Fixed Issues Found

Copy link

codecov bot commented Jan 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.27%. Comparing base (42e7f45) to head (df09726).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #102   +/-   ##
=======================================
  Coverage   65.27%   65.27%           
=======================================
  Files         180      180           
  Lines       13833    13833           
=======================================
  Hits         9029     9029           
  Misses       4804     4804           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -9,6 +9,7 @@ use uuid::Uuid;

use crate::VaultParseError;

/// Encrypted Collection state
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does state imply?

Suggested change
/// Encrypted Collection state
/// Encrypted Collection

@@ -24,6 +25,7 @@ pub struct Collection {
pub manage: bool,
}

/// Decrypted Collection state
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Decrypted Collection state
/// Decrypted Collection

@@ -40,6 +42,7 @@ pub struct CollectionView {
}

impl LocateKey for Collection {
/// Returns a [SymmetricCryptoKey] on success, [CryptoError] on failure
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment conveys the exact same information as the type interface. We generally want to avoid these type of comments since they can easily get out of sync with the actual code. We're also actively refactoring these logic.

@@ -54,6 +54,7 @@ pub(crate) async fn sync(client: &Client, input: &SyncRequest) -> Result<SyncRes

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
/// Data returned from `/accounts/profile`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is false. ProfileResponseModel from bitwarden-api-api is the response from the endpoint. This is a part of the SyncResponse which is the internal SDK response from performing a sync.

@@ -79,6 +80,7 @@ pub struct DomainResponse {

#[derive(Serialize, Deserialize, Debug, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
/// Data returned from `/sync`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is false. SyncResponseModel from bitwarden-api-api is the response from the endpoint. This is an internal model containing the data returned by calling sync().

pub struct VaultClient<'a> {
/// A vault client.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a vault client though. This is the root SDK client.

Comment on lines +8 to +24
/// A vault client.
///
/// # Examples
///
/// ```rust
/// use bitwarden_core::{Client,ClientSettings,DeviceType};
/// use bitwarden_vault::VaultClient;
///
/// let client = Client::new(Some(ClientSettings {
/// identity_url: "https://identity.bitwarden.com".to_owned(),
/// api_url: "https://api.bitwarden.com".to_owned(),
/// user_agent: "Bitwarden Rust-SDK".to_owned(),
/// device_type: DeviceType::ChromeBrowser,
/// }));
///
/// let vault = VaultClient::new(&client);
/// ```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want people to manually. wire up VaultClient's and you should generally use the Extension i.e. client.vault() -> VaultClient.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dani-garcia should we remove pub from the Clients?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds reasonable yeah. I looked into it and VaultClient is the only partial client constructor that is pub too, the rest are private.

Comment on lines 51 to +73

/// Syncs the [VaultClient] with the server.
///
/// # Examples
///
/// ```rust
/// # use bitwarden_core::{Client,ClientSettings,DeviceType};
/// # use bitwarden_vault::{VaultClient,SyncRequest, SyncResponse};
/// async fn sync_vault(client: &Client) {
/// let vault = VaultClient::new(client);
/// let request = SyncRequest {
/// exclude_subdomains: Some(false),
/// };
///
/// let result = vault.sync(&request).await;
/// match result {
/// Ok(response) => println!("Response: {:?}", response),
/// Err(error) => {
/// eprintln!("Sync failed: {:?}", error);
/// },
/// }
/// }
/// ```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't actually want to expose this as public since it's to my knowledge unused.

@coroiu coroiu removed their request for review January 8, 2025 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants