Skip to content

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

}

/// 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.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 3, 2025

Logo
Checkmarx One – Scan Summary & Details15285288-4d43-4a37-ba20-d43c5b24f6c6

Great job, no security vulnerabilities found in this Pull Request

@codecov
Copy link

codecov bot commented Jan 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 65.24%. Comparing base (c9a0295) to head (59c1025).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #102   +/-   ##
=======================================
  Coverage   65.24%   65.24%           
=======================================
  Files         181      181           
  Lines       13821    13821           
=======================================
  Hits         9018     9018           
  Misses       4803     4803           

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


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

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

}

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.


#[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.


#[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().

/// let vault = VaultClient::new(&client);
/// ```
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.

Copy link
Member

Choose a reason for hiding this comment

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

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
@tangowithfoxtrot tangowithfoxtrot marked this pull request as draft January 15, 2025 21:51
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.

4 participants