diff --git a/services/blob/src/config.rs b/services/blob/src/config.rs --- a/services/blob/src/config.rs +++ b/services/blob/src/config.rs @@ -1,11 +1,11 @@ use anyhow::{ensure, Result}; -use clap::{builder::FalseyValueParser, Parser}; +use clap::Parser; use once_cell::sync::Lazy; use tracing::info; use crate::constants::{ - DEFAULT_GRPC_PORT, DEFAULT_HTTP_PORT, DEFAULT_S3_BUCKET_NAME, LOCALSTACK_URL, - S3_BUCKET_ENV_VAR, SANDBOX_ENV_VAR, + DEFAULT_GRPC_PORT, DEFAULT_HTTP_PORT, DEFAULT_S3_BUCKET_NAME, + S3_BUCKET_ENV_VAR, }; #[derive(Parser)] @@ -17,15 +17,10 @@ /// HTTP server listening port #[arg(long, default_value_t = DEFAULT_HTTP_PORT)] pub http_port: u16, - /// 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 = LOCALSTACK_URL.to_string())] - pub localstack_url: String, + /// AWS Localstack service URL + #[arg(env = "LOCALSTACK_ENDPOINT")] + #[arg(long)] + pub localstack_endpoint: Option, #[arg(env = S3_BUCKET_ENV_VAR)] #[arg(long, default_value_t = DEFAULT_S3_BUCKET_NAME.to_string())] pub s3_bucket_name: String, @@ -58,12 +53,9 @@ 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/blob/src/constants.rs b/services/blob/src/constants.rs --- a/services/blob/src/constants.rs +++ b/services/blob/src/constants.rs @@ -2,7 +2,6 @@ pub const DEFAULT_GRPC_PORT: u16 = 50051; pub const DEFAULT_HTTP_PORT: u16 = 51001; -pub const LOCALSTACK_URL: &str = "http://localstack:4566"; pub const MPSC_CHANNEL_BUFFER_CAPACITY: usize = 1; /// 4MB limit @@ -64,7 +63,6 @@ // Environment variables -pub const SANDBOX_ENV_VAR: &str = "COMM_SERVICES_SANDBOX"; pub const LOG_LEVEL_ENV_VAR: &str = tracing_subscriber::filter::EnvFilter::DEFAULT_ENV; diff --git a/services/blob/src/http/mod.rs b/services/blob/src/http/mod.rs --- a/services/blob/src/http/mod.rs +++ b/services/blob/src/http/mod.rs @@ -13,7 +13,8 @@ } fn cors_config() -> Cors { - if CONFIG.is_sandbox { + // For local development, use relaxed CORS config + if CONFIG.localstack_endpoint.is_some() { // All origins, methods, request headers and exposed headers allowed. // Credentials supported. Max age 1 hour. Does not send wildcard. return Cors::permissive(); diff --git a/services/blob/src/s3.rs b/services/blob/src/s3.rs --- a/services/blob/src/s3.rs +++ b/services/blob/src/s3.rs @@ -107,7 +107,7 @@ pub fn new(aws_config: &aws_types::SdkConfig) -> Self { let s3_config = aws_sdk_s3::config::Builder::from(aws_config) // localstack doesn't support virtual addressing - .force_path_style(crate::config::CONFIG.is_sandbox) + .force_path_style(crate::config::CONFIG.localstack_endpoint.is_some()) .build(); S3Client { client: Arc::new(aws_sdk_s3::Client::from_conf(s3_config)), diff --git a/services/blob/src/tools.rs b/services/blob/src/tools.rs --- a/services/blob/src/tools.rs +++ b/services/blob/src/tools.rs @@ -1,18 +1,6 @@ -use std::{env, error::Error as StdError}; +use std::error::Error as StdError; use tonic::codegen::futures_core::Stream; -use crate::constants; - -fn is_env_flag_set(env_var_name: &str) -> bool { - let flag_value = env::var(env_var_name).unwrap_or_default().to_lowercase(); - return ["1", "true"].contains(&flag_value.as_str()); -} - -/// Returns true if the `COMM_SERVICES_SANDBOX` environment variable is set -pub fn is_sandbox_env() -> bool { - return is_env_flag_set(constants::SANDBOX_ENV_VAR); -} - pub type BoxedError = Box; // Trait type aliases aren't supported in Rust, but // we can workaround this by creating an empty trait