-
Notifications
You must be signed in to change notification settings - Fork 8
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -9,6 +9,7 @@ use uuid::Uuid; | |||||
|
||||||
use crate::VaultParseError; | ||||||
|
||||||
/// Encrypted Collection state | ||||||
#[derive(Serialize, Deserialize, Debug, JsonSchema)] | ||||||
#[serde(rename_all = "camelCase", deny_unknown_fields)] | ||||||
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))] | ||||||
|
@@ -24,6 +25,7 @@ pub struct Collection { | |||||
pub manage: bool, | ||||||
} | ||||||
|
||||||
/// Decrypted Collection state | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
#[derive(Serialize, Deserialize, Debug, JsonSchema)] | ||||||
#[serde(rename_all = "camelCase", deny_unknown_fields)] | ||||||
#[cfg_attr(feature = "uniffi", derive(uniffi::Record))] | ||||||
|
@@ -40,6 +42,7 @@ pub struct CollectionView { | |||||
} | ||||||
|
||||||
impl LocateKey for Collection { | ||||||
/// Returns a [SymmetricCryptoKey] on success, [CryptoError] on failure | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||||||
fn locate_key<'a>( | ||||||
&self, | ||||||
enc: &'a dyn KeyContainer, | ||||||
|
@@ -48,6 +51,7 @@ impl LocateKey for Collection { | |||||
enc.get_key(&Some(self.organization_id)) | ||||||
} | ||||||
} | ||||||
|
||||||
impl KeyDecryptable<SymmetricCryptoKey, CollectionView> for Collection { | ||||||
fn decrypt_with_key(&self, key: &SymmetricCryptoKey) -> Result<CollectionView, CryptoError> { | ||||||
Ok(CollectionView { | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is false. |
||
pub struct ProfileResponse { | ||
pub id: Uuid, | ||
pub name: String, | ||
|
@@ -79,6 +80,7 @@ pub struct DomainResponse { | |
|
||
#[derive(Serialize, Deserialize, Debug, JsonSchema)] | ||
#[serde(rename_all = "camelCase", deny_unknown_fields)] | ||
/// Data returned from `/sync`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is false. |
||
pub struct SyncResponse { | ||
/// Data about the user, including their encryption keys and the organizations they are a part | ||
/// of | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,20 +5,78 @@ use crate::{ | |
SyncRequest, SyncResponse, | ||
}; | ||
|
||
/// 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); | ||
/// ``` | ||
Comment on lines
+8
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dani-garcia should we remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds reasonable yeah. I looked into it and |
||
pub struct VaultClient<'a> { | ||
/// A vault client. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
pub(crate) client: &'a Client, | ||
} | ||
|
||
impl<'a> VaultClient<'a> { | ||
/// Constructs a new [VaultClient] with the given [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); | ||
/// let ciphers = vault.ciphers(); | ||
/// // ... | ||
/// ``` | ||
pub fn new(client: &'a Client) -> Self { | ||
Self { client } | ||
} | ||
|
||
/// 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); | ||
/// }, | ||
/// } | ||
/// } | ||
/// ``` | ||
Comment on lines
51
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
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> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
fn vault(&'a self) -> VaultClient<'a>; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does
state
imply?