Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(auth_service): use macro_config from_ref_all (#3987)
Will Hutchinsond6f0bda9f3b2
diff --git a/rust/cloud-storage/authentication_service/src/config.rs b/rust/cloud-storage/authentication_service/src/config.rsindex dc19a6d468..8818e6904a 100644--- a/rust/cloud-storage/authentication_service/src/config.rs+++ b/rust/cloud-storage/authentication_service/src/config.rs@@ -2,6 +2,7 @@ use std::sync::LazyLock;use anyhow::Context;pub use macro_env::Environment;+use macro_env_var::{env_vars, maybe_env_vars};// BASE_URL config value. This is validated when creating the config in main.rspub static BASE_URL: LazyLock<String> = LazyLock::new(|| {@@ -9,6 +10,40 @@ pub static BASE_URL: LazyLock<String> = LazyLock::new(|| {.expect("BASE_URL must be provided via APP_SECRETS_JSON or env")});+env_vars! {+ pub struct BaseUrl;+ pub struct DatabaseUrl;+ pub struct RedisUri;+ pub struct FusionAuthTenantId;+ pub struct FusionAuthApiSecretKey;+ pub struct FusionAuthClientId;+ pub struct FusionAuthClientSecretKey;+ pub struct FusionAuthBaseUrl;+ pub struct FusionAuthOauthRedirectUri;+ pub struct GoogleClientId;+ pub struct GoogleClientSecretKey;+ pub struct StripeSecretKey;+ pub struct ServiceInternalAuthKey;+ pub struct NotificationQueue;+ pub struct SearchEventQueue;+ pub struct LinkManagerQueue;+ pub struct EmailBackfillQueue;+ pub struct GithubClientId;+ pub struct GithubClientSecret;+ pub struct GithubIdpId;+ pub struct StripePriceId;+}++maybe_env_vars! {+ pub struct GaMeasurementId;+ pub struct GaApiSecret;+ pub struct MetaPixelId;+ pub struct MetaAccessToken;+ pub struct MetaTestEventCode;+ pub struct PosthogApiKey;+ pub struct PosthogHost;+}+/// The configuration parameters for the application.////// These can either be passed on the command line, or pulled from environment variables.@@ -17,86 +52,73 @@ pub static BASE_URL: LazyLock<String> = LazyLock::new(|| {////// See `.env.sample` in document-storage-service root for details.#[derive(macro_config::MacroConfig)]+// #[macro_config::from_ref_all]#[serde(rename_all = "SCREAMING_SNAKE_CASE")]pub struct Config {#[allow(dead_code)]- pub base_url: String,+ pub base_url: BaseUrl,/// The connection URL for the Postgres database this application should use.- pub database_url: String,+ pub database_url: DatabaseUrl,/// The Redis URI for the Redis this application should use.- pub redis_uri: String,-+ pub redis_uri: RedisUri,/// FusionAuth Tenant Id- pub fusionauth_tenant_id: String,+ pub fusionauth_tenant_id: FusionAuthTenantId,/// FusionAuth API key secret name- pub fusionauth_api_key_secret_key: String,+ pub fusionauth_api_key_secret_key: FusionAuthApiSecretKey,/// FusionAuth client id- pub fusionauth_client_id: String,+ pub fusionauth_client_id: FusionAuthClientId,/// FusionAuth client secret key- pub fusionauth_client_secret_key: String,+ pub fusionauth_client_secret_key: FusionAuthClientSecretKey,/// FusionAuth base url- pub fusionauth_base_url: String,+ pub fusionauth_base_url: FusionAuthBaseUrl,/// FusionAuth oauth redirect uri- pub fusionauth_oauth_redirect_uri: String,+ pub fusionauth_oauth_redirect_uri: FusionAuthOauthRedirectUri,/// Google client id- pub google_client_id: String,+ pub google_client_id: GoogleClientId,/// Google client secret key- pub google_client_secret_key: String,-+ pub google_client_secret_key: GoogleClientSecretKey,/// Stripe secret key- pub stripe_secret_key: String,-+ pub stripe_secret_key: StripeSecretKey,/// The port to listen for HTTP requests on.#[macro_config_default(8080)]pub port: usize,-/// The environment we are in#[macro_config_default(Environment::new_or_prod())]pub environment: Environment,-/// The internal auth key used by other services- pub service_internal_auth_key: String,-+ pub service_internal_auth_key: ServiceInternalAuthKey,/// The notification queue- pub notification_queue: String,-+ pub notification_queue: NotificationQueue,/// The search event queue- pub search_event_queue: String,-+ pub search_event_queue: SearchEventQueue,/// The email link manager queue- pub link_manager_queue: String,-+ pub link_manager_queue: LinkManagerQueue,/// The email backfill queue. Used by `join_team` to enqueue a/// `PopulateCrmForUser` message that seeds CRM tables with the new/// member's historical sent-mail contacts.- pub email_backfill_queue: String,-+ pub email_backfill_queue: EmailBackfillQueue,/// The github client id- pub github_client_id: String,+ pub github_client_id: GithubClientId,/// The github client secret- pub github_client_secret: String,+ pub github_client_secret: GithubClientSecret,/// The github idp id- pub github_idp_id: String,-+ pub github_idp_id: GithubIdpId,/// GA4 Measurement ID (optional, e.g., "G-XXXXXXXXXX")- pub ga_measurement_id: Option<String>,+ pub ga_measurement_id: Option<GaMeasurementId>,/// GA4 Measurement Protocol API secret (optional)- pub ga_api_secret: Option<String>,-+ pub ga_api_secret: Option<GaApiSecret>,/// Meta Pixel ID (optional)- pub meta_pixel_id: Option<String>,+ pub meta_pixel_id: Option<MetaPixelId>,/// Meta Conversions API access token (optional)- pub meta_access_token: Option<String>,+ pub meta_access_token: Option<MetaAccessToken>,/// Meta test event code for testing (optional)- pub meta_test_event_code: Option<String>,-+ pub meta_test_event_code: Option<MetaTestEventCode>,/// PostHog API key (optional)- pub posthog_api_key: Option<String>,+ pub posthog_api_key: Option<PosthogApiKey>,/// PostHog host (optional)- pub posthog_host: Option<String>,-+ pub posthog_host: Option<PosthogHost>,/// The stripe price id- pub stripe_price_id: String,+ pub stripe_price_id: StripePriceId,}impl Config {diff --git a/rust/cloud-storage/authentication_service/src/main.rs b/rust/cloud-storage/authentication_service/src/main.rsindex 88f4b3ff44..5d42132e71 100644--- a/rust/cloud-storage/authentication_service/src/main.rs+++ b/rust/cloud-storage/authentication_service/src/main.rs@@ -107,7 +107,7 @@ async fn main() -> anyhow::Result<()> {.await?;let fusionauth_api_key = match config.environment {- Environment::Local => config.fusionauth_api_key_secret_key.clone(),+ Environment::Local => config.fusionauth_api_key_secret_key.to_string().clone(),_ => secretsmanager_client.get_secret_value(&config.fusionauth_api_key_secret_key).await@@ -116,7 +116,7 @@ async fn main() -> anyhow::Result<()> {};let fusionauth_client_secret = match config.environment {- Environment::Local => config.fusionauth_client_secret_key.clone(),+ Environment::Local => config.fusionauth_client_secret_key.to_string().clone(),_ => secretsmanager_client.get_secret_value(&config.fusionauth_client_secret_key).await@@ -125,7 +125,7 @@ async fn main() -> anyhow::Result<()> {};let stripe_client_secret = match config.environment {- Environment::Local => config.stripe_secret_key.clone(),+ Environment::Local => config.stripe_secret_key.to_string().clone(),_ => secretsmanager_client.get_secret_value(&config.stripe_secret_key).await@@ -134,7 +134,7 @@ async fn main() -> anyhow::Result<()> {};let google_client_secret = match config.environment {- Environment::Local => config.google_client_secret_key.clone(),+ Environment::Local => config.google_client_secret_key.to_string().clone(),_ => secretsmanager_client.get_secret_value(&config.google_client_secret_key).await@@ -143,24 +143,25 @@ async fn main() -> anyhow::Result<()> {};let auth_client = fusionauth::FusionAuthClient::new(- config.fusionauth_tenant_id,+ config.fusionauth_tenant_id.to_string(),fusionauth_api_key,- config.fusionauth_client_id.clone(),+ config.fusionauth_client_id.to_string().clone(),fusionauth_client_secret,- config.fusionauth_base_url.clone(),- config.fusionauth_oauth_redirect_uri.clone(),- config.google_client_id.clone(),+ config.fusionauth_base_url.to_string().clone(),+ config.fusionauth_oauth_redirect_uri.to_string().clone(),+ config.google_client_id.to_string().clone(),google_client_secret,);tracing::trace!("initialized auth client");let document_storage_service_client = DocumentStorageServiceClient::new(- config.service_internal_auth_key.clone(),+ config.service_internal_auth_key.to_string().clone(),DocumentStorageServiceUrl::new()?.to_string(),);tracing::trace!("initialized document storage service client");- let macro_cache_client = macro_cache_client::MacroCache::new(config.redis_uri.as_str());+ let macro_cache_client =+ macro_cache_client::MacroCache::new(config.redis_uri.to_string().as_str());tracing::trace!("initialized redis client");@@ -176,8 +177,8 @@ async fn main() -> anyhow::Result<()> {JwtValidationArgs::new_with_secret_manager(config.environment, &secretsmanager_client).await?;- let redis_client =- redis::Client::open(config.redis_uri.as_str()).context("failed to create redis client")?;+ let redis_client = redis::Client::open(config.redis_uri.to_string().as_str())+ .context("failed to create redis client")?;let redis_multiplexed_conn = redis_client.get_multiplexed_async_connection().await@@ -185,7 +186,7 @@ async fn main() -> anyhow::Result<()> {let ingress_queue = SqsQueue::new(aws_sdk_sqs::Client::new(¯o_aws_config::get_macro_aws_config().await),- config.notification_queue.clone(),+ config.notification_queue.to_string().clone(),);let notification_ingress_service = SqsNotificationIngress {queue: ingress_queue,@@ -209,8 +210,8 @@ async fn main() -> anyhow::Result<()> {.map(|(measurement_id, api_secret)| {tracing::info!("configuring Google Analytics");GoogleAnalyticsConfig {- measurement_id: measurement_id.clone(),- api_secret: api_secret.clone(),+ measurement_id: measurement_id.to_string().clone(),+ api_secret: api_secret.to_string().clone(),}}),meta: config@@ -220,18 +221,18 @@ async fn main() -> anyhow::Result<()> {.map(|(pixel_id, access_token)| {tracing::info!("configuring Meta Conversions API");MetaConfig {- pixel_id: pixel_id.clone(),- access_token: access_token.clone(),- test_event_code: config.meta_test_event_code.clone(),+ pixel_id: pixel_id.to_string().clone(),+ access_token: access_token.to_string().clone(),+ test_event_code: config.meta_test_event_code.map(|t| t.to_string()),}}),posthog: config.posthog_api_key.as_ref().map(|api_key| {tracing::info!("configuring PostHog");PostHogConfig {- api_key: api_key.clone(),+ api_key: api_key.to_string().clone(),host: config.posthog_host- .clone()+ .map(|p| p.to_string()).unwrap_or_else(|| "https://us.i.posthog.com".to_string()),}}),@@ -246,8 +247,10 @@ async fn main() -> anyhow::Result<()> {);let teams_repo_impl = TeamRepositoryImpl::new(db.clone());- let customer_repo_impl =- CustomerRepositoryImpl::new(stripe_client.clone(), config.stripe_price_id.clone());+ let customer_repo_impl = CustomerRepositoryImpl::new(+ stripe_client.clone(),+ config.stripe_price_id.to_string().clone(),+ );let team_channels_repo_impl = TeamChannelsRepositoryImpl::new(db.clone());let team_crm_settings_repo_impl =teams::outbound::team_crm_settings_repo::TeamCrmSettingsRepositoryImpl::new(db.clone());@@ -275,9 +278,9 @@ async fn main() -> anyhow::Result<()> {GithubAuthImpl::new(auth_client.clone(), redis_multiplexed_conn),foreign_entity_service,GithubLinkConfig {- client_id: config.github_client_id,- client_secret: config.github_client_secret,- idp_id: config.github_idp_id,+ client_id: config.github_client_id.to_string(),+ client_secret: config.github_client_secret.to_string(),+ idp_id: config.github_idp_id.to_string(),},);@@ -343,7 +346,7 @@ async fn main() -> anyhow::Result<()> {},}),analytics_client: Arc::new(analytics_client),- stripe_price_id: config.stripe_price_id,+ stripe_price_id: config.stripe_price_id.to_string(),},config.port,)