Skip to content

Commit 21f7b13

Browse files
committed
WIP: refactoring to remove access to storage via account.
1 parent d12aeb3 commit 21f7b13

File tree

5 files changed

+46
-33
lines changed

5 files changed

+46
-33
lines changed

crates/account/src/account.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ pub trait Account {
251251
/// User storage paths.
252252
fn paths(&self) -> Arc<Paths>;
253253

254+
/// Lookup a folder in the storage.
255+
async fn folder(
256+
&self,
257+
folder_id: &VaultId,
258+
) -> std::result::Result<Folder, Self::Error>;
259+
254260
/// Determine if the account is authenticated.
255261
async fn is_authenticated(&self) -> bool;
256262

@@ -1551,6 +1557,15 @@ impl Account for LocalAccount {
15511557
Arc::clone(&self.paths)
15521558
}
15531559

1560+
async fn folder(&self, folder_id: &VaultId) -> Result<Folder> {
1561+
Ok(self
1562+
.storage
1563+
.folders()
1564+
.get(folder_id)
1565+
.ok_or(StorageError::CacheNotAvailable(*folder_id))?
1566+
.clone())
1567+
}
1568+
15541569
async fn is_authenticated(&self) -> bool {
15551570
self.storage.is_authenticated()
15561571
}

crates/net/src/account/network_account.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use sos_account::{
88
FolderChange, FolderCreate, FolderDelete, LocalAccount, SecretChange,
99
SecretDelete, SecretInsert, SecretMove,
1010
};
11-
use sos_backend::ServerOrigins;
11+
use sos_backend::{Folder, ServerOrigins};
1212
use sos_client_storage::{
1313
AccessOptions, ClientDeviceStorage, ClientStorage, NewFolderOptions,
1414
};
@@ -709,6 +709,11 @@ impl Account for NetworkAccount {
709709
Arc::clone(&self.paths)
710710
}
711711

712+
async fn folder(&self, folder_id: &VaultId) -> Result<Folder> {
713+
let account = self.account.lock().await;
714+
Ok(account.folder(folder_id).await?)
715+
}
716+
712717
async fn is_authenticated(&self) -> bool {
713718
let account = self.account.lock().await;
714719
account.is_authenticated().await

crates/security_report/src/lib.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,11 @@ where
4646
.collect();
4747

4848
for target in targets {
49-
/*
50-
let storage = account.storage().await;
51-
let reader = storage.read().await;
49+
let folder = account.folder(target.id()).await?;
50+
let access_point = folder.access_point();
51+
let access_point = access_point.lock().await;
5252

53-
let folder = reader.folders().get(target.id()).unwrap();
54-
let keeper = folder.keeper();
55-
56-
let vault = keeper.vault();
53+
let vault = access_point.vault();
5754
let mut password_hashes: Vec<(
5855
SecretId,
5956
(Option<Entropy>, Vec<u8>),
@@ -63,7 +60,7 @@ where
6360
if let Some(target) = &options.target {
6461
secret_security_report::<E>(
6562
&target.1,
66-
keeper,
63+
&*access_point,
6764
&mut password_hashes,
6865
target.2.as_ref(),
6966
)
@@ -72,7 +69,7 @@ where
7269
for secret_id in vault.keys() {
7370
secret_security_report::<E>(
7471
secret_id,
75-
keeper,
72+
&*access_point,
7673
&mut password_hashes,
7774
None,
7875
)
@@ -93,9 +90,6 @@ where
9390
hashes.push(hex::encode(sha1));
9491
records.push(record);
9592
}
96-
*/
97-
98-
todo!("restore security report...");
9993
}
10094

10195
let database_checks =
@@ -245,7 +239,7 @@ pub struct SecurityReportRecord {
245239

246240
async fn secret_security_report<E>(
247241
secret_id: &SecretId,
248-
keeper: &AccessPoint,
242+
access_point: &AccessPoint,
249243
password_hashes: &mut Vec<(
250244
SecretId,
251245
(Option<Entropy>, Vec<u8>),
@@ -258,7 +252,9 @@ where
258252
+ From<sos_backend::StorageError>
259253
+ From<sos_backend::Error>,
260254
{
261-
if let Some((_meta, secret, _)) = keeper.read_secret(secret_id).await? {
255+
if let Some((_meta, secret, _)) =
256+
access_point.read_secret(secret_id).await?
257+
{
262258
for field in secret.user_data().fields().iter().filter(|field| {
263259
if let Some(field_id) = target_field {
264260
return field_id == field.id();

crates/sos/src/commands/tools/authenticator.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,12 @@ pub async fn run(cmd: Command) -> Result<()> {
5757
.await
5858
.ok_or(Error::NoAuthenticatorFolder)?;
5959

60-
todo!("restore auth export ");
60+
let folder = owner.folder(authenticator.id()).await?;
61+
let access_point = folder.access_point();
62+
let access_point = access_point.lock().await;
6163

62-
/*
63-
let storage = owner.storage().await;
64-
let storage = storage.read().await;
65-
let folder = storage.folders().get(authenticator.id()).unwrap();
66-
67-
export_authenticator(file, folder.keeper(), qr_codes).await?;
64+
export_authenticator(file, &*access_point, qr_codes).await?;
6865
success("authenticator TOTP secrets exported");
69-
*/
7066
}
7167
Command::Import {
7268
account,
@@ -109,16 +105,12 @@ pub async fn run(cmd: Command) -> Result<()> {
109105
};
110106

111107
if let Some(folder) = folder {
112-
/*
113-
let storage = owner.storage().await;
114-
let mut storage = storage.write().await;
115-
let folder =
116-
storage.folders_mut().get_mut(folder.id()).unwrap();
117-
import_authenticator(file, folder.keeper_mut()).await?;
118-
success("authenticator TOTP secrets imported");
119-
*/
108+
let folder = owner.folder(folder.id()).await?;
109+
let access_point = folder.access_point();
110+
let mut access_point = access_point.lock().await;
120111

121-
todo!("restore auth import");
112+
import_authenticator(file, &mut *access_point).await?;
113+
success("authenticator TOTP secrets imported");
122114
}
123115
}
124116
}

crates/web/src/linked_account.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use sos_account::{
88
FolderChange, FolderCreate, FolderDelete, LocalAccount, SecretChange,
99
SecretDelete, SecretInsert, SecretMove,
1010
};
11-
use sos_backend::{AccountEventLog, DeviceEventLog, FolderEventLog};
11+
use sos_backend::{AccountEventLog, DeviceEventLog, Folder, FolderEventLog};
1212
use sos_client_storage::{AccessOptions, ClientStorage, NewFolderOptions};
1313
use sos_core::{
1414
commit::{CommitHash, CommitState, Comparison},
@@ -137,6 +137,11 @@ impl Account for LinkedAccount {
137137
self.paths.clone()
138138
}
139139

140+
async fn folder(&self, folder_id: &VaultId) -> Result<Folder> {
141+
let account = self.account.lock().await;
142+
Ok(account.folder(folder_id).await?)
143+
}
144+
140145
async fn is_authenticated(&self) -> bool {
141146
let account = self.account.lock().await;
142147
account.is_authenticated().await

0 commit comments

Comments
 (0)