Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3332957
D13875.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D13875.diff
View Options
diff --git a/services/backup/src/database/backup_item.rs b/services/backup/src/database/backup_item.rs
--- a/services/backup/src/database/backup_item.rs
+++ b/services/backup/src/database/backup_item.rs
@@ -15,7 +15,7 @@
pub backup_id: String,
pub created: DateTime<Utc>,
pub user_keys: BlobInfo,
- pub user_data: BlobInfo,
+ pub user_data: Option<BlobInfo>,
pub attachments: Vec<BlobInfo>,
pub siwe_backup_msg: Option<String>,
}
@@ -25,7 +25,7 @@
user_id: String,
backup_id: String,
user_keys: BlobInfo,
- user_data: BlobInfo,
+ user_data: Option<BlobInfo>,
attachments: Vec<BlobInfo>,
siwe_backup_msg: Option<String>,
) -> Self {
@@ -40,16 +40,18 @@
}
}
- pub fn revoke_holders(&self, blob_client: &BlobServiceClient) {
+ pub fn revoke_user_keys_holders(&self, blob_client: &BlobServiceClient) {
blob_client.schedule_revoke_holder(
&self.user_keys.blob_hash,
&self.user_keys.holder,
);
+ }
- blob_client.schedule_revoke_holder(
- &self.user_data.blob_hash,
- &self.user_data.holder,
- );
+ pub fn revoke_user_data_holders(&self, blob_client: &BlobServiceClient) {
+ if let Some(user_data) = &self.user_data {
+ blob_client
+ .schedule_revoke_holder(&user_data.blob_hash, &user_data.holder);
+ }
for attachment_info in &self.attachments {
blob_client.schedule_revoke_holder(
@@ -95,12 +97,12 @@
backup_table::attr::USER_KEYS.to_string(),
value.user_keys.into(),
),
- (
- backup_table::attr::USER_DATA.to_string(),
- value.user_data.into(),
- ),
]);
+ if let Some(user_data) = value.user_data {
+ attrs.insert(backup_table::attr::USER_DATA.to_string(), user_data.into());
+ }
+
if !value.attachments.is_empty() {
attrs.insert(
backup_table::attr::ATTACHMENTS.to_string(),
@@ -147,10 +149,12 @@
backup_table::attr::USER_KEYS,
value.remove(backup_table::attr::USER_KEYS),
)?;
- let user_data = BlobInfo::try_from_attr(
- backup_table::attr::USER_DATA,
- value.remove(backup_table::attr::USER_DATA),
- )?;
+ let user_data = value
+ .remove(backup_table::attr::USER_DATA)
+ .map(|attr| {
+ BlobInfo::try_from_attr(backup_table::attr::USER_DATA, Some(attr))
+ })
+ .transpose()?;
let attachments = value.remove(backup_table::attr::ATTACHMENTS);
let attachments = if attachments.is_some() {
diff --git a/services/backup/src/database/mod.rs b/services/backup/src/database/mod.rs
--- a/services/backup/src/database/mod.rs
+++ b/services/backup/src/database/mod.rs
@@ -123,7 +123,8 @@
.map_err(Error::from)?;
if let Some(backup_item) = &result {
- backup_item.revoke_holders(blob_client);
+ backup_item.revoke_user_keys_holders(blob_client);
+ backup_item.revoke_user_data_holders(blob_client);
}
self
diff --git a/services/backup/src/error.rs b/services/backup/src/error.rs
--- a/services/backup/src/error.rs
+++ b/services/backup/src/error.rs
@@ -23,6 +23,7 @@
DB(comm_lib::database::Error),
IdentityClientError(IdentityClientError),
BadRequest,
+ NoUserData,
}
impl From<&BackupError> for actix_web::Error {
@@ -75,6 +76,7 @@
}
BackupError::NoUserID => ErrorBadRequest("bad request"),
BackupError::BadRequest => ErrorBadRequest("bad request"),
+ BackupError::NoUserData => ErrorNotFound("not found"),
}
}
}
diff --git a/services/backup/src/http/handlers/backup.rs b/services/backup/src/http/handlers/backup.rs
--- a/services/backup/src/http/handlers/backup.rs
+++ b/services/backup/src/http/handlers/backup.rs
@@ -61,7 +61,7 @@
user.user_id.clone(),
backup_id,
user_keys_blob_info,
- user_data_blob_info,
+ Some(user_data_blob_info),
attachments,
siwe_backup_msg,
);
@@ -238,7 +238,7 @@
info!("Download user keys request");
let backup_id = path.into_inner();
download_user_blob(
- |item| &item.user_keys,
+ |item| Ok(&item.user_keys),
&user.user_id,
&backup_id,
blob_client.into_inner(),
@@ -257,7 +257,7 @@
info!("Download user data request");
let backup_id = path.into_inner();
download_user_blob(
- |item| &item.user_data,
+ |item| item.user_data.as_ref().ok_or(BackupError::NoUserData),
&user.user_id,
&backup_id,
blob_client.into_inner(),
@@ -267,7 +267,7 @@
}
pub async fn download_user_blob(
- data_extractor: impl FnOnce(&BackupItem) -> &BlobInfo,
+ data_extractor: impl FnOnce(&BackupItem) -> Result<&BlobInfo, BackupError>,
user_id: &str,
backup_id: &str,
blob_client: BlobServiceClient,
@@ -279,8 +279,10 @@
.map_err(BackupError::from)?
.ok_or(BackupError::NoBackup)?;
+ let blob_info = data_extractor(&backup_item)?;
+
let stream = blob_client
- .get(&data_extractor(&backup_item).blob_hash)
+ .get(&blob_info.blob_hash)
.await
.map_err(BackupError::from)?;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 22, 2:52 AM (20 h, 3 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2553907
Default Alt Text
D13875.diff (4 KB)
Attached To
Mode
D13875: [backup-service] make `user_data` optional in `BackupItem`
Attached
Detach File
Event Timeline
Log In to Comment