diff --git a/services/feature-flags/Dockerfile b/services/feature-flags/Dockerfile --- a/services/feature-flags/Dockerfile +++ b/services/feature-flags/Dockerfile @@ -32,4 +32,5 @@ ENV RUST_LOG=info -CMD ["feature-flags"] +# For compatibility with the existing Terraform config +CMD ["feature-flags", "--http-port", "50051"] diff --git a/services/feature-flags/src/config.rs b/services/feature-flags/src/config.rs --- a/services/feature-flags/src/config.rs +++ b/services/feature-flags/src/config.rs @@ -1,27 +1,21 @@ -use clap::{builder::FalseyValueParser, Parser}; +use clap::Parser; use once_cell::sync::Lazy; use tracing::info; -use crate::constants::{ - DEFAULT_LOCALSTACK_URL, HTTP_SERVER_DEFAULT_PORT, SANDBOX_ENV_VAR, -}; +use crate::constants::HTTP_SERVER_DEFAULT_PORT; #[derive(Parser)] #[command(version, about, long_about = None)] pub struct AppConfig { - /// Run the service in sandbox - #[arg(long = "sandbox", default_value_t = false)] - #[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, - #[arg(long = "port", default_value_t = HTTP_SERVER_DEFAULT_PORT)] + /// AWS Localstack service URL + #[arg(env = "LOCALSTACK_ENDPOINT")] + #[arg(long)] + pub localstack_endpoint: Option, + #[arg(long, default_value_t = HTTP_SERVER_DEFAULT_PORT)] pub http_port: u16, } -pub static CONFIG: Lazy = Lazy::new(|| AppConfig::parse()); +pub static CONFIG: Lazy = Lazy::new(AppConfig::parse); pub fn parse_cmdline_args() { Lazy::force(&CONFIG); @@ -30,12 +24,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/feature-flags/src/constants.rs b/services/feature-flags/src/constants.rs --- a/services/feature-flags/src/constants.rs +++ b/services/feature-flags/src/constants.rs @@ -1,8 +1,6 @@ -pub const DEFAULT_LOCALSTACK_URL: &str = "http://localhost:4566"; pub const LOG_LEVEL_ENV_VAR: &str = tracing_subscriber::filter::EnvFilter::DEFAULT_ENV; -pub const HTTP_SERVER_DEFAULT_PORT: u16 = 50051; -pub const SANDBOX_ENV_VAR: &str = "COMM_SERVICES_SANDBOX"; +pub const HTTP_SERVER_DEFAULT_PORT: u16 = 50055; // The configuration of feature flags is stored in a table in DynamoDB. // Each row is identified by a compound primary key consisting of diff --git a/services/feature-flags/src/service.rs b/services/feature-flags/src/service.rs --- a/services/feature-flags/src/service.rs +++ b/services/feature-flags/src/service.rs @@ -5,6 +5,7 @@ use comm_services_lib::database::Error; use serde::{Deserialize, Serialize}; use std::collections::HashSet; +use tracing::info; pub struct FeatureFlagsService { db: DatabaseClient, @@ -16,6 +17,11 @@ } pub async fn start(&self) -> std::io::Result<()> { + info!( + "Starting HTTP server listening at port {}", + CONFIG.http_port + ); + let db_clone = self.db.clone(); HttpServer::new(move || { App::new()