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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
54 changes: 54 additions & 0 deletions src/configuration/action.rs
Original file line number Diff line number Diff line change
@@ -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<ActionServiceConfiguration>,
}

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::<ActionConfiguration>(&data) {
Ok(conf) => return conf,
Err(error) => {
panic!(
"There was a problem deserializing the json file: {:?}",
error
);
}
};
}
}
82 changes: 82 additions & 0 deletions src/configuration/config.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
82 changes: 2 additions & 80 deletions src/configuration/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion src/server/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down