diff --git a/services/backup/src/config.rs b/services/backup/src/config.rs index d8850b0d3..94d11a41b 100644 --- a/services/backup/src/config.rs +++ b/services/backup/src/config.rs @@ -1,50 +1,40 @@ -use clap::{builder::FalseyValueParser, Parser}; +use clap::Parser; use once_cell::sync::Lazy; use tracing::info; -use crate::constants::{ - DEFAULT_BLOB_SERVICE_URL, DEFAULT_LOCALSTACK_URL, SANDBOX_ENV_VAR, -}; +use crate::constants::DEFAULT_BLOB_SERVICE_URL; #[derive(Parser)] #[command(version, about, long_about = None)] pub struct AppConfig { - /// Run the service in sandbox - #[arg(long = "sandbox", default_value_t = false)] - // support the env var for compatibility reasons - #[arg(env = SANDBOX_ENV_VAR)] - #[arg(value_parser = FalseyValueParser::new())] - pub is_sandbox: bool, - /// AWS Localstack service URL, applicable in sandbox mode - #[arg(long, default_value_t = DEFAULT_LOCALSTACK_URL.to_string())] - pub localstack_url: String, + /// AWS Localstack service URL + #[arg(env = "LOCALSTACK_ENDPOINT")] + #[arg(long)] + pub localstack_endpoint: Option, /// Blob service URL #[arg(long, default_value_t = DEFAULT_BLOB_SERVICE_URL.to_string())] pub blob_service_url: String, } /// Stores configuration parsed from command-line arguments /// and environment variables pub static CONFIG: Lazy = Lazy::new(|| AppConfig::parse()); /// Processes the command-line arguments and environment variables. /// Should be called at the beginning of the `main()` function. pub(super) fn parse_cmdline_args() { // force evaluation of the lazy initialized config Lazy::force(&CONFIG); } /// Provides region/credentials configuration for AWS SDKs pub async fn load_aws_config() -> aws_types::SdkConfig { let mut config_builder = aws_config::from_env(); - if CONFIG.is_sandbox { - info!( - "Running in sandbox environment. Localstack URL: {}", - &CONFIG.localstack_url - ); - config_builder = config_builder.endpoint_url(&CONFIG.localstack_url); + if let Some(endpoint) = &CONFIG.localstack_endpoint { + info!("Using Localstack. AWS endpoint URL: {}", endpoint); + config_builder = config_builder.endpoint_url(endpoint); } config_builder.load().await } diff --git a/services/backup/src/constants.rs b/services/backup/src/constants.rs index 308e4be53..36a402d21 100644 --- a/services/backup/src/constants.rs +++ b/services/backup/src/constants.rs @@ -1,60 +1,57 @@ // Assorted constants pub const MPSC_CHANNEL_BUFFER_CAPACITY: usize = 1; pub const ID_SEPARATOR: &str = ":"; pub const ATTACHMENT_HOLDER_SEPARATOR: &str = ";"; // 400KiB limit (in docs there is KB but they mean KiB) - // https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/ServiceQuotas.html // This includes both attribute names' and values' lengths // // This has to be smaller than GRPC_CHUNK_SIZE_LIMIT because we need to // recognize if we may receive multiple chunks or just one. If it was larger // than the chunk limit, once we get the amount of data of size equal to the // limit, we wouldn't know if we should put this in the database right away or // wait for more data. pub const LOG_DATA_SIZE_DATABASE_LIMIT: usize = 1024 * 400; // 4MB limit // WARNING: use keeping in mind that grpc adds its own headers to messages // https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md // so the message that actually is being sent over the network looks like this // [Compressed-Flag] [Message-Length] [Message] // [Compressed-Flag] 1 byte - added by grpc // [Message-Length] 4 bytes - added by grpc // [Message] N bytes - actual data // so for every message we get 5 additional bytes of data // as mentioned here // https://github.com/grpc/grpc/issues/15734#issuecomment-396962671 // grpc stream may contain more than one message pub const GRPC_CHUNK_SIZE_LIMIT: usize = 4 * 1024 * 1024; pub const GRPC_METADATA_SIZE_PER_MESSAGE: usize = 5; // Configuration defaults -pub const DEFAULT_LOCALSTACK_URL: &str = "http://localhost:4566"; pub const DEFAULT_BLOB_SERVICE_URL: &str = "http://localhost:50053"; // Environment variable names - -pub const SANDBOX_ENV_VAR: &str = "COMM_SERVICES_SANDBOX"; pub const LOG_LEVEL_ENV_VAR: &str = tracing_subscriber::filter::EnvFilter::DEFAULT_ENV; // DynamoDB constants pub const BACKUP_TABLE_NAME: &str = "backup-service-backup"; pub const BACKUP_TABLE_FIELD_USER_ID: &str = "userID"; pub const BACKUP_TABLE_FIELD_BACKUP_ID: &str = "backupID"; pub const BACKUP_TABLE_FIELD_CREATED: &str = "created"; pub const BACKUP_TABLE_FIELD_RECOVERY_DATA: &str = "recoveryData"; pub const BACKUP_TABLE_FIELD_COMPACTION_HOLDER: &str = "compactionHolder"; pub const BACKUP_TABLE_FIELD_ATTACHMENT_HOLDERS: &str = "attachmentHolders"; pub const BACKUP_TABLE_INDEX_USERID_CREATED: &str = "userID-created-index"; pub const LOG_TABLE_NAME: &str = "backup-service-log"; pub const LOG_TABLE_FIELD_BACKUP_ID: &str = "backupID"; pub const LOG_TABLE_FIELD_LOG_ID: &str = "logID"; pub const LOG_TABLE_FIELD_PERSISTED_IN_BLOB: &str = "persistedInBlob"; pub const LOG_TABLE_FIELD_VALUE: &str = "value"; pub const LOG_TABLE_FIELD_ATTACHMENT_HOLDERS: &str = "attachmentHolders"; pub const LOG_TABLE_FIELD_DATA_HASH: &str = "dataHash";