From 02195fa91cb6bae51d55ddae1809a7ec1c7ef771 Mon Sep 17 00:00:00 2001 From: Panagiotis Date: Mon, 18 Nov 2024 12:53:07 +0200 Subject: [PATCH 1/4] feat: Add `StaticConfig` and `RuntimeConfig` types --- src/core/blueprint/cors.rs | 6 +- src/core/blueprint/server.rs | 8 +- src/core/blueprint/telemetry.rs | 14 +- src/core/config/config.rs | 9 - src/core/config/config_module.rs | 25 +- src/core/config/directives/link.rs | 26 +- src/core/config/directives/server.rs | 52 +-- src/core/config/directives/telemetry.rs | 80 +--- src/core/config/directives/upstream.rs | 28 +- src/core/config/mod.rs | 16 +- src/core/config/runtime_config/mod.rs | 8 + .../config/runtime_config/runtime_config.rs | 7 + .../config/runtime_config/server_runtime.rs | 248 ++++++++++++ .../server_runtime/auth_runtime.rs | 169 ++++++++ .../server_runtime/cors_runtime.rs | 245 +++++++++++ .../runtime_config/telemetry_runtime.rs | 128 ++++++ .../config/runtime_config/upstream_runtime.rs | 104 +++++ src/core/config/static_config/link.rs | 79 ++++ src/core/config/static_config/mod.rs | 10 + .../config/static_config/server_static.rs | 382 ++++++++++++++++++ .../server_static/cors_static.rs} | 3 +- .../server_static/headers_static.rs} | 19 +- .../server_static}/key_values.rs | 0 .../server_static/routes_static.rs | 29 ++ .../config/static_config/static_config.rs | 87 ++++ .../config/static_config/telemetry_static.rs | 221 ++++++++++ .../telemetry_static/apollo_static.rs} | 17 +- .../telemetry_static}/reader_context.rs | 0 .../config/static_config/upstream_static.rs | 260 ++++++++++++ .../static_config/upstream_static/batch.rs | 38 ++ src/core/config/utils/encoding.rs | 10 + src/core/config/utils/mod.rs | 6 + src/core/config/utils/private_key.rs | 24 ++ src/core/config/utils/source.rs | 89 ++++ 34 files changed, 2202 insertions(+), 245 deletions(-) create mode 100644 src/core/config/runtime_config/mod.rs create mode 100644 src/core/config/runtime_config/runtime_config.rs create mode 100644 src/core/config/runtime_config/server_runtime.rs create mode 100644 src/core/config/runtime_config/server_runtime/auth_runtime.rs create mode 100644 src/core/config/runtime_config/server_runtime/cors_runtime.rs create mode 100644 src/core/config/runtime_config/telemetry_runtime.rs create mode 100644 src/core/config/runtime_config/upstream_runtime.rs create mode 100644 src/core/config/static_config/link.rs create mode 100644 src/core/config/static_config/mod.rs create mode 100644 src/core/config/static_config/server_static.rs rename src/core/config/{cors.rs => static_config/server_static/cors_static.rs} (98%) rename src/core/config/{headers.rs => static_config/server_static/headers_static.rs} (75%) rename src/core/config/{ => static_config/server_static}/key_values.rs (100%) create mode 100644 src/core/config/static_config/server_static/routes_static.rs create mode 100644 src/core/config/static_config/static_config.rs create mode 100644 src/core/config/static_config/telemetry_static.rs rename src/core/config/{apollo.rs => static_config/telemetry_static/apollo_static.rs} (83%) rename src/core/config/{ => static_config/telemetry_static}/reader_context.rs (100%) create mode 100644 src/core/config/static_config/upstream_static.rs create mode 100644 src/core/config/static_config/upstream_static/batch.rs create mode 100644 src/core/config/utils/encoding.rs create mode 100644 src/core/config/utils/mod.rs create mode 100644 src/core/config/utils/private_key.rs create mode 100644 src/core/config/utils/source.rs diff --git a/src/core/blueprint/cors.rs b/src/core/blueprint/cors.rs index b871d1905e..c73aa11ff4 100644 --- a/src/core/blueprint/cors.rs +++ b/src/core/blueprint/cors.rs @@ -6,7 +6,7 @@ use http::header::{HeaderName, HeaderValue}; use http::request::Parts; use tailcall_valid::ValidationError; -use crate::core::config; +use crate::core::config::cors_static::CorsStatic; #[derive(Clone, Debug, Setters, Default)] pub struct Cors { @@ -161,10 +161,10 @@ fn to_validation_err(err: T) -> ValidationError { ValidationError::new(err.to_string()) } -impl TryFrom for Cors { +impl TryFrom for Cors { type Error = ValidationError; - fn try_from(value: config::cors::Cors) -> Result> { + fn try_from(value: CorsStatic) -> Result> { let cors = Cors { allow_credentials: value.allow_credentials.unwrap_or_default(), allow_headers: (!value.allow_headers.is_empty()).then_some( diff --git a/src/core/blueprint/server.rs b/src/core/blueprint/server.rs index e8e0f54acd..0d2a34a151 100644 --- a/src/core/blueprint/server.rs +++ b/src/core/blueprint/server.rs @@ -9,8 +9,8 @@ use rustls_pki_types::CertificateDer; use tailcall_valid::{Valid, ValidationError, Validator}; use super::Auth; -use crate::core::blueprint::Cors; -use crate::core::config::{self, ConfigModule, HttpVersion, PrivateKey, Routes}; +use crate::core::config::cors_static::CorsStatic; +use crate::core::config::{self, ConfigModule, CorsRuntime, HttpVersion, PrivateKey, Routes}; #[derive(Clone, Debug, Setters)] pub struct Server { @@ -32,7 +32,7 @@ pub struct Server { pub http: Http, pub pipeline_flush: bool, pub script: Option