From 8efb1650d24a4685538c20c00158c4bd7bcc5e81 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 24 Feb 2026 11:41:44 +0100 Subject: [PATCH 1/3] ref: moved config into its own module --- src/configuration/config.rs | 82 +++++++++++++++++++++++++++++++++++++ src/configuration/mod.rs | 82 +------------------------------------ src/main.rs | 2 +- src/server/mod.rs | 2 +- 4 files changed, 86 insertions(+), 82 deletions(-) create mode 100644 src/configuration/config.rs diff --git a/src/configuration/config.rs b/src/configuration/config.rs new file mode 100644 index 0000000..2d696fc --- /dev/null +++ b/src/configuration/config.rs @@ -0,0 +1,82 @@ +use code0_flow::flow_config::{env_with_default, environment::Environment, mode::Mode}; + +/// Struct for all relevant `Aquila` startup configurations +pub struct Config { + /// Aquila environment + /// + /// Options: + /// `development` (default) + /// `staging` + /// `production` + pub environment: Environment, + + /// Aquila mode + /// + /// Options: + /// `static` (default) + /// `hybrid` + pub mode: Mode, + + /// URL to the NATS Server. + pub nats_url: String, + + /// Name of the NATS Bucket. + pub nats_bucket: String, + + /// Fallback file to load flows if gRPC & scheduling is disabled. + pub flow_fallback_path: String, + + /// Verification Token required for internal communication + pub runtime_token: String, + + /// URL to the `Sagittarius` Server. + pub backend_url: String, + + // Port of the `Aquila` Server + pub grpc_port: u16, + + // Host of the `Aquila` Server + pub grpc_host: String, + + pub with_health_service: bool, + + pub action_config_path: String, +} + +/// Implementation for all relevant `Aquila` startup configurations +/// +/// Behavior: +/// Searches for the env. file at root level. Filename: `.env` +impl Default for Config { + fn default() -> Self { + Self::new() + } +} + +impl Config { + pub fn new() -> Self { + Config { + environment: env_with_default("ENVIRONMENT", Environment::Development), + mode: env_with_default("MODE", Mode::STATIC), + nats_url: env_with_default("NATS_URL", String::from("nats://localhost:4222")), + nats_bucket: env_with_default("NATS_BUCKET", String::from("flow_store")), + flow_fallback_path: env_with_default( + "FLOW_FALLBACK_PATH", + String::from("./flowExport.json"), + ), + grpc_port: env_with_default("GRPC_PORT", 8081), + grpc_host: env_with_default("GRPC_HOST", String::from("127.0.0.1")), + with_health_service: env_with_default("WITH_HEALTH_SERVICE", false), + runtime_token: env_with_default("RUNTIME_TOKEN", String::from("default_session_token")), + backend_url: env_with_default( + "SAGITTARIUS_URL", + String::from("http://localhost:50051"), + ), + action_config_path: env_with_default("ACTION_CONFIG_PATH", String::from("./action.configuration.json")) + } + } + + pub fn is_static(&self) -> bool { + self.mode == Mode::STATIC + } +} diff --git a/src/configuration/mod.rs b/src/configuration/mod.rs index 618b7e0..75bdc90 100644 --- a/src/configuration/mod.rs +++ b/src/configuration/mod.rs @@ -1,81 +1,3 @@ -use code0_flow::flow_config::{env_with_default, environment::Environment, mode::Mode}; - +pub mod action; pub mod state; - -/// Struct for all relevant `Aquila` startup configurations -pub struct Config { - /// Aquila environment - /// - /// Options: - /// `development` (default) - /// `staging` - /// `production` - pub environment: Environment, - - /// Aquila mode - /// - /// Options: - /// `static` (default) - /// `hybrid` - pub mode: Mode, - - /// URL to the NATS Server. - pub nats_url: String, - - /// Name of the NATS Bucket. - pub nats_bucket: String, - - /// Fallback file to load flows if gRPC & scheduling is disabled. - pub flow_fallback_path: String, - - /// Verification Token required for internal communication - pub runtime_token: String, - - /// URL to the `Sagittarius` Server. - pub backend_url: String, - - // Port of the `Aquila` Server - pub grpc_port: u16, - - // Host of the `Aquila` Server - pub grpc_host: String, - - pub with_health_service: bool, -} - -/// Implementation for all relevant `Aquila` startup configurations -/// -/// Behavior: -/// Searches for the env. file at root level. Filename: `.env` -impl Default for Config { - fn default() -> Self { - Self::new() - } -} - -impl Config { - pub fn new() -> Self { - Config { - environment: env_with_default("ENVIRONMENT", Environment::Development), - mode: env_with_default("MODE", Mode::STATIC), - nats_url: env_with_default("NATS_URL", String::from("nats://localhost:4222")), - nats_bucket: env_with_default("NATS_BUCKET", String::from("flow_store")), - flow_fallback_path: env_with_default( - "FLOW_FALLBACK_PATH", - String::from("../flow/test_flow_one.json"), - ), - grpc_port: env_with_default("GRPC_PORT", 8081), - grpc_host: env_with_default("GRPC_HOST", String::from("127.0.0.1")), - with_health_service: env_with_default("WITH_HEALTH_SERVICE", false), - runtime_token: env_with_default("RUNTIME_TOKEN", String::from("default_session_token")), - backend_url: env_with_default( - "SAGITTARIUS_URL", - String::from("http://localhost:50051"), - ), - } - } - - pub fn is_static(&self) -> bool { - self.mode == Mode::STATIC - } -} +pub mod config; diff --git a/src/main.rs b/src/main.rs index ee4d0a7..2adb5e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,5 @@ use crate::{ - configuration::{Config as AquilaConfig, state::AppReadiness}, + configuration::{config::Config as AquilaConfig, state::AppReadiness}, flow::get_flow_identifier, sagittarius::retry::create_channel_with_retry, }; diff --git a/src/server/mod.rs b/src/server/mod.rs index 2ba7f85..d265400 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1,5 +1,5 @@ use crate::{ - configuration::{Config, state::AppReadiness}, + configuration::{config::Config, state::AppReadiness}, sagittarius::{ data_type_service_client_impl::SagittariusDataTypeServiceClient, flow_type_service_client_impl::SagittariusFlowTypeServiceClient, From a5d1b4eb1b80e7a0e59442b03372ea954842720b Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 24 Feb 2026 11:41:53 +0100 Subject: [PATCH 2/3] feat: added action service config --- src/configuration/action.rs | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/configuration/action.rs diff --git a/src/configuration/action.rs b/src/configuration/action.rs new file mode 100644 index 0000000..4127632 --- /dev/null +++ b/src/configuration/action.rs @@ -0,0 +1,54 @@ +use serde::{Deserialize, Serialize}; +use serde_json::from_str; +use std::{fs::File, io::Read}; + +#[derive(Serialize, Deserialize)] +pub struct ActionServiceConfiguration { + token: String, + service_name: String, +} + +#[derive(Serialize, Deserialize)] +pub struct ActionConfiguration { + actions: Vec, +} + +impl ActionConfiguration { + + pub fn has_action(self, token: String) -> bool { + match self.actions.into_iter().find(|x| x.token == token) { + Some(_) => true, + None => false, + } + } + + pub fn from_path(path: String) -> Self { + let mut data = String::new(); + + let mut file = match File::open(path) { + Ok(file) => file, + Err(error) => { + panic!("There was a problem opening the file: {:?}", error); + } + }; + + match file.read_to_string(&mut data) { + Ok(_) => { + log::debug!("Successfully loaded action configuration file"); + } + Err(error) => { + panic!("There was a problem reading the file: {:?}", error); + } + } + + match from_str::(&data) { + Ok(conf) => return conf, + Err(error) => { + panic!( + "There was a problem deserializing the json file: {:?}", + error + ); + } + }; + } +} From 296182b55b55895b3900ed6e34e38129754658fa Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 24 Feb 2026 11:42:03 +0100 Subject: [PATCH 3/3] dependencies: added serde --- Cargo.lock | 1 + Cargo.toml | 1 + 2 files changed, 2 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 1c5313d..526e5c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,6 +77,7 @@ dependencies = [ "futures", "log", "prost", + "serde", "serde_json", "tokio", "tokio-stream", diff --git a/Cargo.toml b/Cargo.toml index 4bae34f..8dc4f5f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,3 +17,4 @@ async-nats = "0.46.0" tonic-health = "0.14.1" tokio-stream = "0.1.17" uuid = { version = "1.18.0", features = ["v4"] } +serde = "1.0.228"