diff --git a/CHANGELOG.md b/CHANGELOG.md index 48ebe2b74f..90b01ab19b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **API** Return `API_REQUEST_TIMEOUT` error after 50s (see `docs/infrastructure/API_TIMEOUTS.md` for context) - **API** Move generated client APIs to sdks/ - Lower long poll timeout from 60s -> 40s +- **Bolt** Moved additional project roots to Bolt.toml ### Security diff --git a/lib/bolt/config/src/local.rs b/lib/bolt/config/src/local.rs index 56eac98724..ece43f029b 100644 --- a/lib/bolt/config/src/local.rs +++ b/lib/bolt/config/src/local.rs @@ -1,5 +1,3 @@ -use std::{collections::HashMap, path::PathBuf}; - use serde::Deserialize; /// Configuration for the Bolt.local.toml file. @@ -11,19 +9,11 @@ pub struct Local { #[serde(default)] pub namespace: Option, #[serde(default)] - pub additional_roots: HashMap, - #[serde(default)] pub up: Up, #[serde(default)] pub rust: Rust, } -#[derive(Clone, Debug, Default, Deserialize)] -#[serde(rename_all = "kebab-case", deny_unknown_fields)] -pub struct AdditionalRoot { - pub path: PathBuf, -} - #[derive(Clone, Debug, Default, Deserialize)] #[serde(rename_all = "kebab-case", deny_unknown_fields)] pub struct Up {} diff --git a/lib/bolt/config/src/ns.rs b/lib/bolt/config/src/ns.rs index eb4a69a57d..e47c6bae35 100644 --- a/lib/bolt/config/src/ns.rs +++ b/lib/bolt/config/src/ns.rs @@ -546,6 +546,8 @@ pub struct Rivet { pub dynamic_servers: DynamicServers, #[serde(default)] pub cdn: Cdn, + #[serde(default)] + pub billing: Option, } #[derive(Serialize, Deserialize, Clone, Debug, Default)] @@ -639,6 +641,12 @@ impl Default for Cdn { } } +#[derive(Serialize, Deserialize, Clone, Debug)] +#[serde(deny_unknown_fields)] +pub struct RivetBilling { + region_price_ids: HashMap, +} + fn default_regions() -> HashMap { toml::from_str(include_str!("../default_regions.toml")) .expect("failed to parse default_regions.toml") diff --git a/lib/bolt/config/src/project.rs b/lib/bolt/config/src/project.rs index 080515ae19..ee9c22126a 100644 --- a/lib/bolt/config/src/project.rs +++ b/lib/bolt/config/src/project.rs @@ -1,4 +1,5 @@ use serde::Deserialize; +use std::{collections::HashMap, path::PathBuf}; pub fn decode(s: &str) -> Result { toml::from_str(s) @@ -10,5 +11,11 @@ pub fn decode(s: &str) -> Result { #[serde(rename_all = "kebab-case")] pub struct Project { #[serde(default)] - pub billing_enabled: bool, + pub additional_roots: HashMap, +} + +#[derive(Clone, Debug, Default, Deserialize)] +#[serde(rename_all = "kebab-case", deny_unknown_fields)] +pub struct AdditionalRoot { + pub path: PathBuf, } diff --git a/lib/bolt/core/src/context/project.rs b/lib/bolt/core/src/context/project.rs index f12eb997c0..a5255aef9d 100644 --- a/lib/bolt/core/src/context/project.rs +++ b/lib/bolt/core/src/context/project.rs @@ -87,7 +87,7 @@ impl ProjectContextData { let mut svc_ctxs_map = HashMap::new(); // Load sub projects - for (_, additional_root) in &config_local.additional_roots { + for (_, additional_root) in &config.additional_roots { let path = project_root.join(&additional_root.path); Self::load_root_dir(&mut svc_ctxs_map, path).await; } diff --git a/lib/bolt/core/src/context/service.rs b/lib/bolt/core/src/context/service.rs index ccbcc3a334..f4c549a859 100644 --- a/lib/bolt/core/src/context/service.rs +++ b/lib/bolt/core/src/context/service.rs @@ -825,8 +825,11 @@ impl ServiceContextData { } // Add billing flag - if project_ctx.config().billing_enabled { - env.push(("IS_BILLING_ENABLED".to_owned(), "1".into())); + if let Some(billing) = &project_ctx.ns().rivet.billing { + env.push(( + "RIVET_BILLING".to_owned(), + serde_json::to_string(&billing).unwrap(), + )); } if project_ctx.ns().dns.is_some() { diff --git a/lib/bolt/core/src/tasks/gen.rs b/lib/bolt/core/src/tasks/gen.rs index ed962fe263..5b42becf26 100644 --- a/lib/bolt/core/src/tasks/gen.rs +++ b/lib/bolt/core/src/tasks/gen.rs @@ -26,7 +26,7 @@ pub async fn generate_project(ctx: &ProjectContext) { dep::k8s::gen::project(ctx).await.unwrap(); // Generate additional roots - let additional_roots = &ctx.config_local().additional_roots; + let additional_roots = &ctx.config().additional_roots; for (_, additional_root) in additional_roots { let path = fs::canonicalize(ctx.path().join(&additional_root.path)) .await diff --git a/lib/bolt/core/src/tasks/template.rs b/lib/bolt/core/src/tasks/template.rs index 5eb8248063..d69f425256 100644 --- a/lib/bolt/core/src/tasks/template.rs +++ b/lib/bolt/core/src/tasks/template.rs @@ -51,7 +51,7 @@ pub async fn generate(ctx: &mut ProjectContext, opts: TemplateOpts) -> Result<() // Create base path based on selected root let base_path = if let Some(root) = root { let root_path = &ctx - .config_local() + .config() .additional_roots .get(&root) .ok_or_else(|| anyhow!("Root `{}` not found in local config", root))?