From 9d6b7a0548afe571b90e3217b4159779a5954f80 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 5 Jun 2025 18:20:23 +0200 Subject: [PATCH 1/2] feat: implemented new config system --- .env-example | 4 ++++ .gitignore | 2 ++ src/configuration.rs | 38 ++++++++++++++++++++++++++++++++++++++ src/main.rs | 19 ++++++++++++++++--- 4 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 .env-example create mode 100644 src/configuration.rs diff --git a/.env-example b/.env-example new file mode 100644 index 0000000..c75ec79 --- /dev/null +++ b/.env-example @@ -0,0 +1,4 @@ +ENVIRONMENT='development' +MODE='dynamic' +RABBITMQ_URL='amqp://localhost:5672' +AQUILA_URL='http://localhost:8080' diff --git a/.gitignore b/.gitignore index 9fb6367..f7dff0f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ target .DS_Store ./out out + +.env diff --git a/src/configuration.rs b/src/configuration.rs new file mode 100644 index 0000000..7507c46 --- /dev/null +++ b/src/configuration.rs @@ -0,0 +1,38 @@ +use code0_flow::flow_config::{env_with_default, environment::Environment, mode::Mode}; + +/// Struct for all relevant `Taurus` startup configurations +pub struct Config { + /// Options: + /// `development` (default) + /// `staging` + /// `production` + pub environment: Environment, + + /// Aquila mode + /// + /// Options: + /// `static` (default) + /// `hybrid` + pub mode: Mode, + + /// Verification Token required for internal communication + pub rabbitmq_url: String, + + /// URL to the `Sagittarius` Server. + pub aquila_url: String, +} + +/// Implementation for all relevant `Aquila` startup configurations +/// +/// Behavior: +/// Searches for the env. file at root level. Filename: `.env` +impl Config { + pub fn new() -> Self { + Config { + environment: env_with_default("ENVIRONMENT", Environment::Development), + mode: env_with_default("MODE", Mode::STATIC), + rabbitmq_url: env_with_default("RABBITMQ_URL", String::from("amqp://localhost:5672")), + aquila_url: env_with_default("AQUILA_URL", String::from("http://localhost:8080")), + } + } +} diff --git a/src/main.rs b/src/main.rs index f7c78b2..38d5d63 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,15 @@ +mod configuration; pub mod context; pub mod error; pub mod implementation; pub mod locale; pub mod registry; - use std::sync::Arc; -use code0_flow::flow_queue::service::{Message, RabbitmqClient}; +use code0_flow::{ + flow_config::load_env_file, + flow_queue::service::{Message, RabbitmqClient}, +}; use context::{Context, ContextEntry, ContextResult}; use error::RuntimeError; use futures_lite::StreamExt; @@ -15,6 +18,8 @@ use locale::locale::Locale; use registry::FunctionStore; use tucana::shared::{Flow, NodeFunction, Value}; +use crate::configuration::Config; + fn handle_node_function( function: NodeFunction, store: &FunctionStore, @@ -165,10 +170,18 @@ fn handle_message(message: Message, store: &FunctionStore) -> Result Date: Thu, 5 Jun 2025 18:20:41 +0200 Subject: [PATCH 2/2] dependencies: added env_logger & updated code0-flow to 0.0.13 --- Cargo.lock | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++--- Cargo.toml | 5 +- 2 files changed, 153 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 847771c..6a4771d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -85,6 +85,56 @@ dependencies = [ "url", ] +[[package]] +name = "anstream" +version = "0.6.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "301af1932e46185686725e0fad2f8f2aa7da69dd70bf6ecc44d6b703844a3933" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" + +[[package]] +name = "anstyle-parse" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c8bdeb6047d8983be085bab0ba1472e6dc604e7041dbf6fcd5e71523014fae9" +dependencies = [ + "windows-sys 0.59.0", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "403f75924867bb1033c59fbf0797484329750cfbe3c4325cd33127941fabc882" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.59.0", +] + [[package]] name = "anyhow" version = "1.0.98" @@ -508,11 +558,12 @@ dependencies = [ [[package]] name = "code0-flow" -version = "0.0.12" +version = "0.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cf7a86a2ba2b0428289b0dc14b6a78d60ff94f84b80eb970e64382acac70319" +checksum = "ecc2b4e3ce2fb62521a5fc6825074525cc88269218e4919c1e4d3a9a83ba197b" dependencies = [ "async-trait", + "dotenv", "futures-lite 2.6.0", "lapin", "log", @@ -524,6 +575,12 @@ dependencies = [ "tucana", ] +[[package]] +name = "colorchoice" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" + [[package]] name = "combine" version = "4.6.7" @@ -690,12 +747,41 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "either" version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" +[[package]] +name = "env_filter" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0" +dependencies = [ + "log", + "regex", +] + +[[package]] +name = "env_logger" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f" +dependencies = [ + "anstream", + "anstyle", + "env_filter", + "jiff", + "log", +] + [[package]] name = "equivalent" version = "1.0.2" @@ -709,7 +795,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1232,6 +1318,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" + [[package]] name = "itertools" version = "0.14.0" @@ -1247,6 +1339,30 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" +[[package]] +name = "jiff" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a194df1107f33c79f4f93d02c80798520551949d59dfad22b6157048a88cca93" +dependencies = [ + "jiff-static", + "log", + "portable-atomic", + "portable-atomic-util", + "serde", +] + +[[package]] +name = "jiff-static" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c6e1db7ed32c6c71b759497fae34bf7933636f75a251b9e736555da426f6442" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "js-sys" version = "0.3.77" @@ -1461,6 +1577,12 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" +[[package]] +name = "once_cell_polyfill" +version = "1.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4895175b425cb1f87721b59f0f286c2092bd4af812243672510e1ac53e2e0ad" + [[package]] name = "openssl-probe" version = "0.1.6" @@ -1669,6 +1791,21 @@ dependencies = [ "windows-sys 0.59.0", ] +[[package]] +name = "portable-atomic" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e" + +[[package]] +name = "portable-atomic-util" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507" +dependencies = [ + "portable-atomic", +] + [[package]] name = "potential_utf" version = "0.1.2" @@ -1944,7 +2081,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.4.15", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1957,7 +2094,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys 0.9.4", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2273,6 +2410,7 @@ name = "taurus" version = "0.1.0" dependencies = [ "code0-flow", + "env_logger", "futures-lite 2.6.0", "lapin", "log", @@ -2306,7 +2444,7 @@ dependencies = [ "getrandom 0.3.3", "once_cell", "rustix 1.0.7", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -2622,6 +2760,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "value-bag" version = "1.11.1" diff --git a/Cargo.toml b/Cargo.toml index 74b3cd2..1ed2f40 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "taurus" version = "0.1.0" -edition = "2021" +edition = "2024" [dependencies] -code0-flow = { version = "0.0.12", features = ["all"] } +code0-flow = { version = "0.0.13" } tucana = { version = "0.0.28", features = ["aquila"] } lapin = "2.5.3" serde = "1.0.219" @@ -13,6 +13,7 @@ tokio = { version = "1.44.1", features = ["rt-multi-thread"] } toml = "0.8.0" log = "0.4.27" futures-lite = "2.6.0" +env_logger = "0.11.8" [dev-dependencies] tempfile = "3.19.1"