From e8e1d95006e1a941991b564fbdfdae94a8a4f404 Mon Sep 17 00:00:00 2001 From: Brandon Thomas Date: Tue, 31 Mar 2026 03:55:12 -0400 Subject: [PATCH] central config --- Cargo.lock | 9 +++++++++ Cargo.toml | 2 ++ .../config/shared_env_var_config/Cargo.toml | 12 +++++++++++ .../config/shared_env_var_config/src/lib.rs | 1 + .../shared_env_var_config/src/paging.rs | 20 +++++++++++++++++++ .../job/video_thumbnail_job/Cargo.toml | 1 + .../src/startup/build_pager.rs | 8 ++++---- crates/service/web/storyteller_web/Cargo.toml | 1 + .../src/startup/build_pager.rs | 6 +++--- 9 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 crates/schema/config/shared_env_var_config/Cargo.toml create mode 100644 crates/schema/config/shared_env_var_config/src/lib.rs create mode 100644 crates/schema/config/shared_env_var_config/src/paging.rs diff --git a/Cargo.lock b/Cargo.lock index 83537fc81b..e718e09738 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10705,6 +10705,13 @@ dependencies = [ "keccak", ] +[[package]] +name = "shared_env_var_config" +version = "0.0.1" +dependencies = [ + "easyenv", +] + [[package]] name = "shlex" version = "1.3.0" @@ -11290,6 +11297,7 @@ dependencies = [ "serde_derive", "serde_json", "server_environment", + "shared_env_var_config", "speculoos", "sqlx", "strum", @@ -13372,6 +13380,7 @@ dependencies = [ "serde_derive", "serde_json", "server_environment", + "shared_env_var_config", "sqlx", "tempdir", "tokio", diff --git a/Cargo.toml b/Cargo.toml index 83d90b4959..2b29b4d128 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -103,6 +103,7 @@ members = [ # Schema (config): configuration constants for external services "crates/schema/config/rootly_config", + "crates/schema/config/shared_env_var_config", # Schema (database): queries, database layouts, Redis keys, etc. "crates/schema/database/elasticsearch_schema", @@ -246,6 +247,7 @@ filesys = { path = "crates/lib/files/filesys" } grok_client = { path = "crates/api_clients/grok_client" } rootly_client = { path = "crates/api_clients/rootly_client" } rootly_config = { path = "crates/schema/config/rootly_config" } +shared_env_var_config = { path = "crates/schema/config/shared_env_var_config" } http_headers = { path = "crates/lib/http_headers" } images = { path = "crates/lib/files/images" } jobs_common = { path = "crates/lib/jobs_common" } diff --git a/crates/schema/config/shared_env_var_config/Cargo.toml b/crates/schema/config/shared_env_var_config/Cargo.toml new file mode 100644 index 0000000000..de3921a0f1 --- /dev/null +++ b/crates/schema/config/shared_env_var_config/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "shared_env_var_config" +edition = "2024" +version = "0.0.1" +publish = false + +[lib] +name = "shared_env_var_config" +path = "src/lib.rs" + +[dependencies] +easyenv.workspace = true diff --git a/crates/schema/config/shared_env_var_config/src/lib.rs b/crates/schema/config/shared_env_var_config/src/lib.rs new file mode 100644 index 0000000000..b7460ec27e --- /dev/null +++ b/crates/schema/config/shared_env_var_config/src/lib.rs @@ -0,0 +1 @@ +pub mod paging; diff --git a/crates/schema/config/shared_env_var_config/src/paging.rs b/crates/schema/config/shared_env_var_config/src/paging.rs new file mode 100644 index 0000000000..3805f6f127 --- /dev/null +++ b/crates/schema/config/shared_env_var_config/src/paging.rs @@ -0,0 +1,20 @@ +const ENV_ENABLE_PAGING: &str = "ENABLE_PAGING"; +const ENV_ROOTLY_API_KEY: &str = "ROOTLY_API_KEY"; +const ENV_ROOTLY_NOTIFICATION_TARGET_TYPE: &str = "ROOTLY_NOTIFICATION_TARGET_TYPE"; +const ENV_ROOTLY_NOTIFICATION_TARGET_ID: &str = "ROOTLY_NOTIFICATION_TARGET_ID"; + +pub fn env_enable_paging_default_false() -> bool { + easyenv::get_env_bool_or_default(ENV_ENABLE_PAGING, false) +} + +pub fn env_optional_rootly_api_key() -> Option { + easyenv::get_env_string_optional(ENV_ROOTLY_API_KEY) +} + +pub fn env_optional_rootly_notification_target_type() -> Option { + easyenv::get_env_string_optional(ENV_ROOTLY_NOTIFICATION_TARGET_TYPE) +} + +pub fn env_optional_rootly_notification_target_id() -> Option { + easyenv::get_env_string_optional(ENV_ROOTLY_NOTIFICATION_TARGET_ID) +} diff --git a/crates/service/job/video_thumbnail_job/Cargo.toml b/crates/service/job/video_thumbnail_job/Cargo.toml index c7628298b1..c9215a15c6 100644 --- a/crates/service/job/video_thumbnail_job/Cargo.toml +++ b/crates/service/job/video_thumbnail_job/Cargo.toml @@ -34,6 +34,7 @@ mysql_queries.workspace = true pager = { path = "../../../lib/pager" } rootly_client.workspace = true rootly_config.workspace = true +shared_env_var_config.workspace = true server_environment = { path = "../../../lib/server_environment" } # External diff --git a/crates/service/job/video_thumbnail_job/src/startup/build_pager.rs b/crates/service/job/video_thumbnail_job/src/startup/build_pager.rs index c7e11043ca..908c5f5d4c 100644 --- a/crates/service/job/video_thumbnail_job/src/startup/build_pager.rs +++ b/crates/service/job/video_thumbnail_job/src/startup/build_pager.rs @@ -10,7 +10,7 @@ pub fn build_pager( server_environment: server_environment::ServerEnvironment, hostname: &str, ) -> (Pager, PagerWorker) { - let is_paging_enabled = easyenv::get_env_bool_or_default("ENABLE_PAGING", false); + let is_paging_enabled = shared_env_var_config::paging::env_enable_paging_default_false(); info!("Paging enabled: {}", is_paging_enabled); @@ -32,7 +32,7 @@ pub fn build_pager( return builder.build_with_worker(); } - let maybe_api_key = easyenv::get_env_string_optional("ROOTLY_API_KEY"); + let maybe_api_key = shared_env_var_config::paging::env_optional_rootly_api_key(); match maybe_api_key { Some(api_key) => { @@ -53,8 +53,8 @@ fn build_rootly_pager(builder: PagerBuilder, api_key: String) -> (Pager, PagerWo .urgency_id_medium(ROOTLY_URGENCY_ID_MEDIUM.to_string()) .urgency_id_low(ROOTLY_URGENCY_ID_LOW.to_string()); - let target_type = easyenv::get_env_string_optional("ROOTLY_NOTIFICATION_TARGET_TYPE"); - let target_id = easyenv::get_env_string_optional("ROOTLY_NOTIFICATION_TARGET_ID"); + let target_type = shared_env_var_config::paging::env_optional_rootly_notification_target_type(); + let target_id = shared_env_var_config::paging::env_optional_rootly_notification_target_id(); if let (Some(t_type), Some(t_id)) = (target_type, target_id) { rootly_builder = rootly_builder.notification_target(t_type, t_id); diff --git a/crates/service/web/storyteller_web/Cargo.toml b/crates/service/web/storyteller_web/Cargo.toml index 4ebf86339c..6dddd34fe2 100644 --- a/crates/service/web/storyteller_web/Cargo.toml +++ b/crates/service/web/storyteller_web/Cargo.toml @@ -69,6 +69,7 @@ pager.workspace = true password = { path = "../../../lib/password" } rootly_client.workspace = true rootly_config.workspace = true +shared_env_var_config.workspace = true primitives = { path = "../../../lib/data/primitives" } prompt_engineering = { path = "../../../lib/deprecated/machine_learning/prompt_engineering" } redis_caching = { path = "../../../lib/caching/redis_caching" } diff --git a/crates/service/web/storyteller_web/src/startup/build_pager.rs b/crates/service/web/storyteller_web/src/startup/build_pager.rs index 640b5db59c..1be6e96dee 100644 --- a/crates/service/web/storyteller_web/src/startup/build_pager.rs +++ b/crates/service/web/storyteller_web/src/startup/build_pager.rs @@ -35,7 +35,7 @@ pub fn build_pager( return (pager, worker, paging_flags); } - let maybe_api_key = easyenv::get_env_string_optional("ROOTLY_API_KEY"); + let maybe_api_key = shared_env_var_config::paging::env_optional_rootly_api_key(); let (pager, worker) = match maybe_api_key { Some(api_key) => { @@ -58,8 +58,8 @@ fn build_rootly_pager(builder: PagerBuilder, api_key: String) -> (Pager, PagerWo .urgency_id_medium(ROOTLY_URGENCY_ID_MEDIUM.to_string()) .urgency_id_low(ROOTLY_URGENCY_ID_LOW.to_string()); - let target_type = easyenv::get_env_string_optional("ROOTLY_NOTIFICATION_TARGET_TYPE"); - let target_id = easyenv::get_env_string_optional("ROOTLY_NOTIFICATION_TARGET_ID"); + let target_type = shared_env_var_config::paging::env_optional_rootly_notification_target_type(); + let target_id = shared_env_var_config::paging::env_optional_rootly_notification_target_id(); if let (Some(t_type), Some(t_id)) = (target_type, target_id) { rootly_builder = rootly_builder.notification_target(t_type, t_id);