Changeset View
Standalone View
services/feature-flags/src/config.rs
use aws_sdk_dynamodb::{Endpoint, Region}; | |||||
use clap::{builder::FalseyValueParser, Parser}; | use clap::{builder::FalseyValueParser, Parser}; | ||||
use http::Uri; | |||||
use once_cell::sync::Lazy; | use once_cell::sync::Lazy; | ||||
use tracing::info; | |||||
use crate::constants::DEFAULT_LOCALSTACK_URL; | use crate::constants::{AWS_REGION, DEFAULT_LOCALSTACK_URL}; | ||||
#[derive(Parser)] | #[derive(Parser)] | ||||
#[command(version, about, long_about = None)] | #[command(version, about, long_about = None)] | ||||
pub struct AppConfig { | pub struct AppConfig { | ||||
/// Run the service in sandbox | /// Run the service in sandbox | ||||
#[arg(long = "sandbox", default_value_t = false)] | #[arg(long = "sandbox", default_value_t = false)] | ||||
#[arg(value_parser = FalseyValueParser::new())] | #[arg(value_parser = FalseyValueParser::new())] | ||||
pub is_sandbox: bool, | pub is_sandbox: bool, | ||||
/// AWS Localstack service URL, applicable in sandbox mode | /// AWS Localstack service URL, applicable in sandbox mode | ||||
#[arg(long, default_value_t = DEFAULT_LOCALSTACK_URL.to_string())] | #[arg(long, default_value_t = DEFAULT_LOCALSTACK_URL.to_string())] | ||||
pub localstack_url: String, | pub localstack_url: String, | ||||
} | } | ||||
pub static CONFIG: Lazy<AppConfig> = Lazy::new(|| AppConfig::parse()); | pub static CONFIG: Lazy<AppConfig> = Lazy::new(|| AppConfig::parse()); | ||||
pub fn parse_cmdline_args() { | pub fn parse_cmdline_args() { | ||||
Lazy::force(&CONFIG); | Lazy::force(&CONFIG); | ||||
} | } | ||||
pub async fn load_aws_config() -> aws_types::SdkConfig { | |||||
bartek: Side note - we should prioritize the https://linear.app/comm/issue/ENG-2311/shared-rust-code… | |||||
tomekAuthorUnsubmitted Done Inline ActionsAgree! I think we can discuss this during our next planning meeting. tomek: Agree! I think we can discuss this during our next planning meeting. | |||||
ashoatUnsubmitted Not Done Inline ActionsPlanning meeting are not the best venue for housekeeping tasks... they are closely tied to external goals we set, and "shared Rust code across services" is not easy to frame as an external goal What's blocking us from just creating a shared library right now and moving things over as we need them? ashoat: Planning meeting are not the best venue for housekeeping tasks... they are closely tied to… | |||||
tomekAuthorUnsubmitted Done Inline Actions
I think our priority should be to deliver the goals. If we have some time at the end, we can work on additional things.
Even when it is an internal goal, it still takes time and prioritizing this over an external goal should be a conscious decision. I'm not sure if limiting planning meetings to just external goals is always beneficial. tomek: > What's blocking us from just creating a shared library right now and moving things over as we… | |||||
ashoatUnsubmitted Not Done Inline Actions
Generally agree with this, but I also wonder what the cost is. Seems like it would be rather easy to just create a shared library and start using it. I feel like I've seen you request changes when somebody copy-pastes code from native to web to reach a monthly goal, for instance... I think this is a similar thing. If the cost is low enough, I think we can start sharing code by just introducing the library and starting to use it. ashoat: > I think our priority should be to deliver the goals. If we have some time at the end, we can… | |||||
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 | |||||
} |
Side note - we should prioritize the https://linear.app/comm/issue/ENG-2311/shared-rust-code-across-services for services - this is the third service where this exact function is copied.