diff --git a/services/feature-flags/src/config.rs b/services/feature-flags/src/config.rs index a2ba50550..537b56172 100644 --- a/services/feature-flags/src/config.rs +++ b/services/feature-flags/src/config.rs @@ -1,42 +1,46 @@ use aws_sdk_dynamodb::{Endpoint, Region}; use clap::{builder::FalseyValueParser, Parser}; use http::Uri; use once_cell::sync::Lazy; use tracing::info; -use crate::constants::{AWS_REGION, DEFAULT_LOCALSTACK_URL}; +use crate::constants::{ + AWS_REGION, DEFAULT_LOCALSTACK_URL, 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(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)] + pub http_port: u16, } pub static CONFIG: Lazy = Lazy::new(|| AppConfig::parse()); pub fn parse_cmdline_args() { Lazy::force(&CONFIG); } pub async fn load_aws_config() -> aws_types::SdkConfig { let mut config_builder = aws_config::from_env().region(Region::new(AWS_REGION)); if CONFIG.is_sandbox { info!( "Running in sandbox environment. Localstack URL: {}", &CONFIG.localstack_url ); config_builder = config_builder.endpoint_resolver(Endpoint::immutable( Uri::from_static(&CONFIG.localstack_url), )); } config_builder.load().await } diff --git a/services/feature-flags/src/constants.rs b/services/feature-flags/src/constants.rs index c8c9af131..df3d2f99d 100644 --- a/services/feature-flags/src/constants.rs +++ b/services/feature-flags/src/constants.rs @@ -1,30 +1,31 @@ pub const AWS_REGION: &str = "us-east-2"; 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; // The configuration of feature flags is stored in a table in DynamoDB. // Each row is identified by a compound primary key consisting of // partition key - platform and sort key - feature. // A row also contains the configuration, which is a map indexed by code // version with values containing boolean flags for staff and non-staff config. // A sample row from the db looks like this: // { // "feature": S("FEATURE_1"), // "configuration": M({ // "123": M({ // "staff": Bool(true), // "non-staff": Bool(false) // }) // }), // "platform": S("ANDROID") // } pub const FEATURE_FLAGS_TABLE_NAME: &str = "feature-flags"; pub const FEATURE_FLAGS_PLATFORM_FIELD: &str = "platform"; pub const FEATURE_FLAGS_CONFIG_FIELD: &str = "configuration"; pub const FEATURE_FLAGS_FEATURE_FIELD: &str = "feature"; pub const FEATURE_FLAGS_STAFF_FIELD: &str = "staff"; pub const FEATURE_FLAGS_NON_STAFF_FIELD: &str = "non-staff"; pub const PLATFORM_IOS: &str = "IOS"; pub const PLATFORM_ANDROID: &str = "ANDROID";