1use crate::{
2 domain::dtos::route::Route,
3 use_cases::gateway::routes::load_config_from_yaml,
4};
5
6use futures::lock::Mutex;
7use lazy_static::lazy_static;
8use std::env::var_os;
9use tera::Tera;
10
11pub const DEFAULT_TOTP_DOMAIN: &str = "Mycelium";
20
21lazy_static! {
28 pub static ref ROUTES: Mutex<Vec<Route>> = Mutex::new(vec![]);
29}
30
31pub async fn init_in_memory_routes(routes_file: Option<String>) {
32 let source_file_path = match routes_file {
33 None => {
34 match var_os("SOURCE_FILE_PATH") {
35 Some(path) => Some(path.into_string().unwrap()),
36 None => {
37 panic!("Required environment variable SOURCE_FILE_PATH not set.")
38 }
39 }
40 }
41 Some(path) => Some(path),
42 };
43
44 let db = match load_config_from_yaml(match source_file_path.to_owned() {
45 None => panic!(
46 "Source path not already loaded. Please run the init method before
47 load database."
48 ),
49 Some(path) => path,
50 })
51 .await
52 {
53 Err(err) => {
54 panic!("Unexpected error on load in memory database: {err}")
55 }
56 Ok(res) => res,
57 };
58
59 ROUTES.lock().await.extend(db);
60}
61
62lazy_static! {
67 pub static ref TEMPLATES: Tera = {
68 let mut _tera = match Tera::new("templates/**/*") {
69 Ok(res) => res,
70 Err(err) => panic!("Error on load tera templates: {}", err),
71 };
72
73 _tera.autoescape_on(vec![".jinja"]);
74 _tera
75 };
76}