Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .env-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ENVIRONMENT='development'
MODE='dynamic'
REDIS_URL='redis://localhost:6379'
RABBITMQ_URL='amqp://localhost:5672'
AQUILA_URL='http://localhost:8080'
PORT=8080
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
*/target
target

.env
23 changes: 9 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[workspace]
members = ["crates/config", "crates/http", "crates/validator", "adapter/rest"]
members = ["crates/http", "crates/validator", "adapter/rest"]

[workspace.package]
version = "0.0.0"
edition = "2021"

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

[workspace.dependencies.config]
path = "../draco/crates/config"

[workspace.dependencies.http]
path = "../draco/crates/http"

Expand Down
1 change: 0 additions & 1 deletion adapter/rest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ edition = "2021"

[dependencies]
http = { workspace = true }
config = { workspace = true }
validator = { workspace = true }
code0-flow = { workspace = true }
tokio = { workspace = true }
Expand Down
51 changes: 51 additions & 0 deletions adapter/rest/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use code0_flow::flow_config::{env_with_default, environment::Environment, mode::Mode};

/// Struct for all relevant `Draco` startup configurations
pub struct Config {
/// Options:
/// `development` (default)
/// `staging`
/// `production`
pub environment: Environment,

/// Aquila mode
///
/// Options:
/// `static` (default)
/// `hybrid`
pub mode: Mode,

/// URL to the Redis Server.
/// Default none
pub redis_url: String,

/// Verification Token required for internal communication
pub rabbitmq_url: String,

/// URL to the `Sagittarius` Server.
pub aquila_url: String,

/// Port for the HTTP server
pub port: u16,
}

/// 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),
redis_url: env_with_default("REDIS_URL", String::from("redis://localhost:6379")),
rabbitmq_url: env_with_default("RABBITMQ_URL", String::from("amqp://localhost:5672")),
aquila_url: env_with_default("AQUILA_URL", String::from("http://localhost:8080")),
port: env_with_default("PORT", 8080),
}
}

pub fn is_static(&self) -> bool {
self.mode == Mode::STATIC
}
}
20 changes: 8 additions & 12 deletions adapter/rest/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
mod config;
pub mod queue;
pub mod store;
mod types;

use code0_flow::{
flow_config::mode::Mode,
flow_queue::service::RabbitmqClient,
flow_store::{
connection::create_flow_store_connection,
service::{FlowStoreService, FlowStoreServiceBase},
},
};
use config::FromEnv;
use http::{
request::HttpRequest,
response::HttpResponse,
Expand All @@ -20,6 +21,8 @@ use std::{future::Future, pin::Pin, sync::Arc};
use tokio::sync::Mutex;
use types::{get_data_types, get_flow_types};

use crate::config::Config;

pub struct FlowConnectionHandler {
flow_store: Arc<Mutex<FlowStoreService>>,
rabbitmq_client: Arc<RabbitmqClient>,
Expand Down Expand Up @@ -49,25 +52,18 @@ impl AsyncHandler for FlowConnectionHandler {
}
}

#[derive(FromEnv)]
pub struct Config {
port: u16,
redis_url: String,
rabbitmq_url: String,
aquila_url: String,
is_static: bool,
}

#[tokio::main]
async fn main() {
env_logger::Builder::from_default_env()
.filter_level(log::LevelFilter::Debug)
.init();

code0_flow::flow_config::load_env_file();

log::info!("Starting Draco REST server");
let config = Config::from_file("./.env");
let config = Config::new();

if !config.is_static {
if !config.is_static() {
let update_client =
code0_flow::flow_definition::FlowUpdateService::from_url(config.aquila_url.clone())
.with_data_types(get_data_types())
Expand Down
14 changes: 0 additions & 14 deletions crates/config/Cargo.toml

This file was deleted.

101 changes: 0 additions & 101 deletions crates/config/src/lib.rs

This file was deleted.