Skip to content

Commit

Permalink
Rename type.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpfs committed Nov 27, 2023
1 parent de2cb26 commit 2dd561d
Show file tree
Hide file tree
Showing 30 changed files with 116 additions and 125 deletions.
4 changes: 2 additions & 2 deletions src/commands/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use sos_net::{
AccountBackup, ExtractFilesLocation, Inventory,
RestoreOptions,
},
AccountInfo, AccountRef, LocalProvider, UserPaths,
AccountInfo, AccountRef, FolderStorage, UserPaths,
},
vfs,
},
Expand Down Expand Up @@ -403,7 +403,7 @@ async fn account_restore(input: PathBuf) -> Result<Option<AccountInfo>> {
let account_ref = AccountRef::Address(inventory.manifest.address);
let account = find_account(&account_ref).await?;

let provider: Option<Arc<RwLock<LocalProvider>>> =
let provider: Option<Arc<RwLock<FolderStorage>>> =
if let Some(account) = account {
let confirmed = read_flag(Some(
"Overwrite all account data from backup? (y/n) ",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use terminal_banner::{Banner, Padding};

use sos_net::sdk::{
account::{
search::{ArchiveFilter, DocumentView, Document},
search::{ArchiveFilter, Document, DocumentView},
AccountRef,
},
vault::{
Expand Down
3 changes: 1 addition & 2 deletions src/helpers/secret.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ use terminal_banner::{Banner, Padding};

use secrecy::{ExposeSecret, SecretString};
use sos_net::sdk::{
hex,
account::search::Document,
secrecy,
hex, secrecy,
url::Url,
vault::{
secret::{FileContent, Secret, SecretId, SecretMeta, SecretRef},
Expand Down
22 changes: 10 additions & 12 deletions tests/integration/account_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ use sos_net::sdk::{
account::{
archive::{AccountBackup, ExtractFilesLocation, RestoreOptions},
files::FileStorage,
Account, DelegatedPassphrase, AccountsList,
LocalProvider,
search::SearchIndex,
Account, AccountsList, DelegatedPassphrase, FolderStorage,
},
hex,
passwd::diceware::generate_passphrase,
Expand All @@ -29,14 +28,13 @@ async fn integration_account_manager() -> Result<()> {
let account_name = TEST_ID.to_string();
let (passphrase, _) = generate_passphrase()?;

let (mut account, new_account) =
Account::<()>::new_account(
account_name.clone(),
passphrase.clone(),
Some(test_data_dir.clone()),
None,
)
.await?;
let (mut account, new_account) = Account::<()>::new_account(
account_name.clone(),
passphrase.clone(),
Some(test_data_dir.clone()),
None,
)
.await?;

account.sign_in(passphrase.clone()).await?;

Expand All @@ -49,7 +47,7 @@ async fn integration_account_manager() -> Result<()> {
let accounts = AccountsList::list_accounts(Some(&paths)).await?;
assert_eq!(1, accounts.len());
let user = account.user()?;

let address = new_account.address.clone();
let summary = new_account.default_folder().clone();

Expand Down Expand Up @@ -142,7 +140,7 @@ async fn integration_account_manager() -> Result<()> {
// Restore from archive whilst signed in (with provider),
// overwrites existing data (backup)
let signer = user.identity().signer().clone();
let mut provider = LocalProvider::new(
let mut provider = FolderStorage::new(
signer.address()?.to_string(),
Some(test_data_dir.clone()),
)
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/archive_export_restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tempfile::tempdir;
use sos_net::sdk::{
account::{
archive::{AccountBackup, RestoreOptions, Writer},
Identity, LocalProvider,
FolderStorage, Identity,
},
encode,
events::WriteEvent,
Expand All @@ -30,7 +30,7 @@ async fn integration_archive_local_provider() -> Result<()> {
let user_id = signer.address()?.to_string();
let passphrase = SecretString::new("mock-password".to_owned());
let mut storage =
LocalProvider::new(user_id, Some(dir.path().to_path_buf())).await?;
FolderStorage::new(user_id, Some(dir.path().to_path_buf())).await?;

// Prepare a vault to add to the archive
let default_vault = VaultBuilder::new()
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/local_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use tempfile::tempdir;

use secrecy::ExposeSecret;
use sos_net::sdk::{
account::LocalProvider,
account::FolderStorage,
events::WriteEvent,
signer::{ecdsa::SingleParty, Signer},
vault::secret::{Secret, SecretData},
Expand All @@ -29,12 +29,12 @@ async fn integration_local_provider_file() -> Result<()> {
let signer = Box::new(SingleParty::new_random());
let user_id = signer.address()?.to_string();
let mut storage =
LocalProvider::new(user_id, Some(dir.path().to_path_buf())).await?;
FolderStorage::new(user_id, Some(dir.path().to_path_buf())).await?;
run_local_storage_tests(&mut storage).await?;
Ok(())
}

async fn run_local_storage_tests(storage: &mut LocalProvider) -> Result<()> {
async fn run_local_storage_tests(storage: &mut FolderStorage) -> Result<()> {
// Create an account with default login vault
let (_, passphrase, _) = storage.create_account(None, None).await?;

Expand Down
43 changes: 21 additions & 22 deletions tests/integration/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use web3_address::ethereum::Address;
use sos_net::{
client::{Origin, RemoteBridge, RemoteSync, UserStorage},
sdk::{
account::LocalProvider,
account::FolderStorage,
crypto::AccessKey,
events::{AuditLogFile, WriteEvent},
hex,
Expand Down Expand Up @@ -63,7 +63,7 @@ async fn remote_bridge(
) -> Result<RemoteBridge> {
let keypair = Keypair::new(PATTERN.parse()?)?;
let local =
LocalProvider::new(signer.address()?.to_string(), data_dir).await?;
FolderStorage::new(signer.address()?.to_string(), data_dir).await?;
let provider = RemoteBridge::new(
Arc::new(RwLock::new(local)),
origin.clone(),
Expand Down Expand Up @@ -304,22 +304,21 @@ pub async fn create_local_account(
data_dir: Option<PathBuf>,
) -> Result<(UserStorage, Summary, SecretString)> {
let (passphrase, _) = generate_passphrase()?;
let (mut owner, new_account) =
UserStorage::new_account_with_builder(
account_name.to_owned(),
passphrase.clone(),
|builder| {
builder
.save_passphrase(false)
.create_archive(true)
.create_authenticator(false)
.create_contacts(true)
.create_file_password(true)
},
data_dir,
None,
)
.await?;
let (mut owner, new_account) = UserStorage::new_account_with_builder(
account_name.to_owned(),
passphrase.clone(),
|builder| {
builder
.save_passphrase(false)
.create_archive(true)
.create_authenticator(false)
.create_contacts(true)
.create_file_password(true)
},
data_dir,
None,
)
.await?;

let summary = new_account.default_folder().clone();

Expand All @@ -341,7 +340,7 @@ pub fn mock_note(label: &str, text: &str) -> (SecretMeta, Secret) {
}

pub async fn create_secrets(
provider: &mut LocalProvider,
provider: &mut FolderStorage,
summary: &Summary,
) -> Result<Vec<(SecretId, &'static str)>> {
let notes = vec![
Expand Down Expand Up @@ -379,7 +378,7 @@ pub async fn create_secrets(
}

pub async fn delete_secret(
provider: &mut LocalProvider,
provider: &mut FolderStorage,
summary: &Summary,
id: &SecretId,
) -> Result<()> {
Expand Down Expand Up @@ -425,10 +424,10 @@ async fn create_account(
pub async fn create_local_provider(
signer: BoxedEcdsaSigner,
data_dir: Option<PathBuf>,
) -> Result<(AccountCredentials, LocalProvider)> {
) -> Result<(AccountCredentials, FolderStorage)> {
let address = signer.address()?;
let mut provider =
LocalProvider::new(address.to_string(), data_dir).await?;
FolderStorage::new(address.to_string(), data_dir).await?;
let (_, encryption_passphrase, summary) =
provider.create_account(None, None).await?;
let account = AccountCredentials {
Expand Down
2 changes: 1 addition & 1 deletion workspace/migrate/src/import/csv/bitwarden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ mod test {
use tokio::sync::RwLock;

use sos_sdk::{
passwd::diceware::generate_passphrase,
account::search::SearchIndex,
passwd::diceware::generate_passphrase,
vault::{Gatekeeper, VaultBuilder},
};
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion workspace/migrate/src/import/csv/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ mod test {
use tokio::sync::RwLock;

use sos_sdk::{
passwd::diceware::generate_passphrase,
account::search::SearchIndex,
passwd::diceware::generate_passphrase,
vault::{Gatekeeper, VaultBuilder},
};
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion workspace/migrate/src/import/csv/dashlane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,8 @@ mod test {
use tokio::sync::RwLock;

use sos_sdk::{
passwd::diceware::generate_passphrase,
account::search::SearchIndex,
passwd::diceware::generate_passphrase,
vault::{secret::Secret, Gatekeeper, VaultBuilder},
};
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion workspace/migrate/src/import/csv/firefox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ mod test {
use tokio::sync::RwLock;

use sos_sdk::{
passwd::diceware::generate_passphrase,
account::search::SearchIndex,
passwd::diceware::generate_passphrase,
vault::{Gatekeeper, VaultBuilder},
};
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion workspace/migrate/src/import/csv/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ mod test {
use tokio::sync::RwLock;

use sos_sdk::{
passwd::diceware::generate_passphrase,
account::search::SearchIndex,
passwd::diceware::generate_passphrase,
vault::{Gatekeeper, VaultBuilder},
};
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion workspace/migrate/src/import/csv/one_password.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ mod test {
use tokio::sync::RwLock;

use sos_sdk::{
passwd::diceware::generate_passphrase,
account::search::SearchIndex,
passwd::diceware::generate_passphrase,
vault::{Gatekeeper, VaultBuilder},
};
use std::sync::Arc;
Expand Down
8 changes: 4 additions & 4 deletions workspace/net/src/client/account/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use async_trait::async_trait;
use http::StatusCode;

use sos_sdk::{
account::{AccountStatus, LocalProvider},
account::{AccountStatus, FolderStorage},
commit::{CommitHash, CommitProof, CommitState, Comparison},
crypto::SecureAccessKey,
decode,
Expand Down Expand Up @@ -58,7 +58,7 @@ pub struct RemoteBridge {
/// Origin for this remote.
origin: Origin,
/// Local provider.
local: Arc<RwLock<LocalProvider>>,
local: Arc<RwLock<FolderStorage>>,
/// Client to use for remote communication.
remote: RpcClient,
}
Expand All @@ -67,7 +67,7 @@ impl RemoteBridge {
/// Create a new remote bridge that wraps the given
/// local provider.
pub fn new(
local: Arc<RwLock<LocalProvider>>,
local: Arc<RwLock<FolderStorage>>,
origin: Origin,
signer: BoxedEcdsaSigner,
keypair: Keypair,
Expand All @@ -81,7 +81,7 @@ impl RemoteBridge {
}

/// Clone of the local provider.
pub fn local(&self) -> Arc<RwLock<LocalProvider>> {
pub fn local(&self) -> Arc<RwLock<FolderStorage>> {
Arc::clone(&self.local)
}
}
Expand Down
35 changes: 18 additions & 17 deletions workspace/net/src/client/account/user_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ use sos_sdk::{
archive::{
AccountBackup, ExtractFilesLocation, Inventory, RestoreOptions,
},
search::{AccountSearch, DocumentCount, SearchIndex, AccountStatistics},
Account, AccountBuilder, AccountData, AccountHandler, AccountInfo,
AuthenticatedUser, DelegatedPassphrase, DetachedView,
AccountsList, LocalProvider, NewAccount, AccessOptions, UserPaths,
search::{
AccountSearch, AccountStatistics, DocumentCount, SearchIndex,
},
AccessOptions, Account, AccountBuilder, AccountData, AccountHandler,
AccountInfo, AccountsList, AuthenticatedUser, DelegatedPassphrase,
DetachedView, FolderStorage, NewAccount, UserPaths,
},
commit::{CommitHash, CommitProof, CommitState},
crypto::{AccessKey, SecureAccessKey},
Expand Down Expand Up @@ -83,7 +85,7 @@ impl SyncHandler {
/// Try to sync the target folder against all remotes.
async fn try_sync_folder(
&self,
storage: Arc<RwLock<LocalProvider>>,
storage: Arc<RwLock<FolderStorage>>,
folder: &Summary,
commit_state: &CommitState,
) -> Result<Option<CommitState>> {
Expand Down Expand Up @@ -134,7 +136,7 @@ impl AccountHandler for SyncHandler {

async fn before_change(
&self,
storage: Arc<RwLock<LocalProvider>>,
storage: Arc<RwLock<FolderStorage>>,
folder: &Summary,
commit_state: &CommitState,
) -> Option<CommitState> {
Expand Down Expand Up @@ -246,15 +248,14 @@ impl UserStorage {
remotes: Arc::clone(&remotes),
};

let (account, new_account) =
LocalAccount::new_account_with_builder(
account_name,
passphrase.clone(),
builder,
data_dir.clone(),
Some(Box::new(handler)),
)
.await?;
let (account, new_account) = LocalAccount::new_account_with_builder(
account_name,
passphrase.clone(),
builder,
data_dir.clone(),
Some(Box::new(handler)),
)
.await?;

let devices_dir = account.paths().devices_dir().clone();

Expand Down Expand Up @@ -286,7 +287,7 @@ impl UserStorage {
}

/// Storage provider.
pub fn storage(&self) -> Result<Arc<RwLock<LocalProvider>>> {
pub fn storage(&self) -> Result<Arc<RwLock<FolderStorage>>> {
Ok(self.account.storage()?)
}

Expand Down Expand Up @@ -1206,7 +1207,7 @@ impl UserStorage {
}

/*
impl From<UserStorage> for Arc<RwLock<LocalProvider>> {
impl From<UserStorage> for Arc<RwLock<FolderStorage>> {
fn from(value: UserStorage) -> Self {
value.account.into()
}
Expand Down
Loading

0 comments on commit 2dd561d

Please sign in to comment.