diff --git a/services/backup/src/constants.rs b/services/backup/src/constants.rs
index 0cb2c4e92..f1eb28756 100644
--- a/services/backup/src/constants.rs
+++ b/services/backup/src/constants.rs
@@ -1,45 +1,54 @@
// Assorted constants
pub const MPSC_CHANNEL_BUFFER_CAPACITY: usize = 1;
pub const ID_SEPARATOR: &str = ":";
pub const ATTACHMENT_HOLDER_SEPARATOR: &str = ";";
pub const WS_FRAME_SIZE: usize = 1_048_576; // 1MiB
pub const LOG_DEFAULT_PAGE_SIZE: i32 = 20;
pub const LOG_BACKUP_ID_SEPARATOR: &str = "#";
// Configuration defaults
pub const DEFAULT_HTTP_PORT: u16 = 50052;
pub const DEFAULT_BLOB_SERVICE_URL: &str = "http://localhost:50053";
// Environment variable names
pub const LOG_LEVEL_ENV_VAR: &str =
tracing_subscriber::filter::EnvFilter::DEFAULT_ENV;
pub const COMM_SERVICES_USE_JSON_LOGS: &str = "COMM_SERVICES_USE_JSON_LOGS";
// DynamoDB constants
pub mod backup_table {
pub const TABLE_NAME: &str = "backup-service-backup";
pub const CREATED_INDEX: &str = "userID-created-index";
pub mod attr {
pub const USER_ID: &str = "userID";
pub const BACKUP_ID: &str = "backupID";
pub const CREATED: &str = "created";
pub const USER_DATA: &str = "userData";
pub const USER_KEYS: &str = "userKeys";
pub const ATTACHMENTS: &str = "attachments";
pub const SIWE_BACKUP_MSG: &str = "siweBackupMsg";
}
}
pub mod log_table {
pub const TABLE_NAME: &str = "backup-service-log";
pub mod attr {
pub const BACKUP_ID: &str = "backupID";
pub const LOG_ID: &str = "logID";
pub const CONTENT_DB: &str = "content";
pub const CONTENT_BLOB_INFO: &str = "blobInfo";
pub const ATTACHMENTS: &str = "attachments";
}
}
+
+// Error Types
+
+pub mod error_types {
+ pub const DDB_ERROR: &str = "DDB Error";
+ pub const AUTH_ERROR: &str = "Auth Error";
+ pub const BLOB_ERROR: &str = "Blob Error";
+ pub const WS_ERROR: &str = "WS Error";
+}
diff --git a/services/backup/src/database/mod.rs b/services/backup/src/database/mod.rs
index 9dab455ec..22c63e0a0 100644
--- a/services/backup/src/database/mod.rs
+++ b/services/backup/src/database/mod.rs
@@ -1,369 +1,389 @@
pub mod backup_item;
pub mod log_item;
use self::{
backup_item::{BackupItem, OrderedBackupItem},
log_item::LogItem,
};
-use crate::constants::{backup_table, log_table, LOG_DEFAULT_PAGE_SIZE};
+use crate::constants::{
+ backup_table, error_types, log_table, LOG_DEFAULT_PAGE_SIZE,
+};
use aws_sdk_dynamodb::{
operation::get_item::GetItemOutput,
types::{AttributeValue, DeleteRequest, ReturnValue, WriteRequest},
};
use comm_lib::{
blob::client::BlobServiceClient,
database::{
self, batch_operations::ExponentialBackoffConfig, parse_int_attribute,
Error,
},
};
use tracing::{error, trace, warn};
#[derive(Clone)]
pub struct DatabaseClient {
client: aws_sdk_dynamodb::Client,
}
impl DatabaseClient {
pub fn new(aws_config: &aws_config::SdkConfig) -> Self {
DatabaseClient {
client: aws_sdk_dynamodb::Client::new(aws_config),
}
}
}
/// Backup functions
impl DatabaseClient {
pub async fn put_backup_item(
&self,
backup_item: BackupItem,
) -> Result<(), Error> {
let item = backup_item.into();
self
.client
.put_item()
.table_name(backup_table::TABLE_NAME)
.set_item(Some(item))
.send()
.await
.map_err(|e| {
- error!("DynamoDB client failed to put backup item");
+ error!(
+ errorType = error_types::DDB_ERROR,
+ "DynamoDB client failed to put backup item"
+ );
Error::AwsSdk(e.into())
})?;
Ok(())
}
pub async fn find_backup_item(
&self,
user_id: &str,
backup_id: &str,
) -> Result