Skip to content

Commit 8eb75f5

Browse files
Merge pull request #61 from code0-tech/59-new-config-system
New Config System
2 parents d39f742 + f88b3a5 commit 8eb75f5

File tree

9 files changed

+78
-147
lines changed

9 files changed

+78
-147
lines changed

.env-example

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ENVIRONMENT='development'
2+
MODE='dynamic'
3+
REDIS_URL='redis://localhost:6379'
4+
RABBITMQ_URL='amqp://localhost:5672'
5+
AQUILA_URL='http://localhost:8080'
6+
PORT=8080

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
*/target
22
target
3+
4+
.env

Cargo.lock

Lines changed: 9 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
[workspace]
2-
members = ["crates/config", "crates/http", "crates/validator", "adapter/rest"]
2+
members = ["crates/http", "crates/validator", "adapter/rest"]
33

44
[workspace.package]
55
version = "0.0.0"
66
edition = "2021"
77

88
[workspace.dependencies]
9-
code0-flow = { version = "0.0.12" }
9+
code0-flow = { version = "0.0.13" }
1010
tucana = { version = "0.0.28", features = ["aquila"] }
1111
serde_json = { version = "1.0.138" }
1212
serde = "1.0.219"
@@ -20,9 +20,6 @@ tokio = { version = "1.44.1", features = ["rt-multi-thread"] }
2020
uuid = { version = "1.16.0", features = ["v4"] }
2121
tonic = "0.13.0"
2222

23-
[workspace.dependencies.config]
24-
path = "../draco/crates/config"
25-
2623
[workspace.dependencies.http]
2724
path = "../draco/crates/http"
2825

adapter/rest/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ edition = "2021"
55

66
[dependencies]
77
http = { workspace = true }
8-
config = { workspace = true }
98
validator = { workspace = true }
109
code0-flow = { workspace = true }
1110
tokio = { workspace = true }

adapter/rest/src/config/mod.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
use code0_flow::flow_config::{env_with_default, environment::Environment, mode::Mode};
2+
3+
/// Struct for all relevant `Draco` startup configurations
4+
pub struct Config {
5+
/// Options:
6+
/// `development` (default)
7+
/// `staging`
8+
/// `production`
9+
pub environment: Environment,
10+
11+
/// Aquila mode
12+
///
13+
/// Options:
14+
/// `static` (default)
15+
/// `hybrid`
16+
pub mode: Mode,
17+
18+
/// URL to the Redis Server.
19+
/// Default none
20+
pub redis_url: String,
21+
22+
/// Verification Token required for internal communication
23+
pub rabbitmq_url: String,
24+
25+
/// URL to the `Sagittarius` Server.
26+
pub aquila_url: String,
27+
28+
/// Port for the HTTP server
29+
pub port: u16,
30+
}
31+
32+
/// Implementation for all relevant `Aquila` startup configurations
33+
///
34+
/// Behavior:
35+
/// Searches for the env. file at root level. Filename: `.env`
36+
impl Config {
37+
pub fn new() -> Self {
38+
Config {
39+
environment: env_with_default("ENVIRONMENT", Environment::Development),
40+
mode: env_with_default("MODE", Mode::STATIC),
41+
redis_url: env_with_default("REDIS_URL", String::from("redis://localhost:6379")),
42+
rabbitmq_url: env_with_default("RABBITMQ_URL", String::from("amqp://localhost:5672")),
43+
aquila_url: env_with_default("AQUILA_URL", String::from("http://localhost:8080")),
44+
port: env_with_default("PORT", 8080),
45+
}
46+
}
47+
48+
pub fn is_static(&self) -> bool {
49+
self.mode == Mode::STATIC
50+
}
51+
}

adapter/rest/src/main.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
mod config;
12
pub mod queue;
23
pub mod store;
34
mod types;
45

56
use code0_flow::{
7+
flow_config::mode::Mode,
68
flow_queue::service::RabbitmqClient,
79
flow_store::{
810
connection::create_flow_store_connection,
911
service::{FlowStoreService, FlowStoreServiceBase},
1012
},
1113
};
12-
use config::FromEnv;
1314
use http::{
1415
request::HttpRequest,
1516
response::HttpResponse,
@@ -20,6 +21,8 @@ use std::{future::Future, pin::Pin, sync::Arc};
2021
use tokio::sync::Mutex;
2122
use types::{get_data_types, get_flow_types};
2223

24+
use crate::config::Config;
25+
2326
pub struct FlowConnectionHandler {
2427
flow_store: Arc<Mutex<FlowStoreService>>,
2528
rabbitmq_client: Arc<RabbitmqClient>,
@@ -49,25 +52,18 @@ impl AsyncHandler for FlowConnectionHandler {
4952
}
5053
}
5154

52-
#[derive(FromEnv)]
53-
pub struct Config {
54-
port: u16,
55-
redis_url: String,
56-
rabbitmq_url: String,
57-
aquila_url: String,
58-
is_static: bool,
59-
}
60-
6155
#[tokio::main]
6256
async fn main() {
6357
env_logger::Builder::from_default_env()
6458
.filter_level(log::LevelFilter::Debug)
6559
.init();
6660

61+
code0_flow::flow_config::load_env_file();
62+
6763
log::info!("Starting Draco REST server");
68-
let config = Config::from_file("./.env");
64+
let config = Config::new();
6965

70-
if !config.is_static {
66+
if !config.is_static() {
7167
let update_client =
7268
code0_flow::flow_definition::FlowUpdateService::from_url(config.aquila_url.clone())
7369
.with_data_types(get_data_types())

crates/config/Cargo.toml

Lines changed: 0 additions & 14 deletions
This file was deleted.

crates/config/src/lib.rs

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
 (0)