WIP: refactor hexagonal architecture
This commit is contained in:
parent
49978bb3d8
commit
3f4e94948f
63 changed files with 41 additions and 20 deletions
12
Cargo.toml
12
Cargo.toml
|
|
@ -22,7 +22,9 @@ base64 = "0.22.1"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
rand_core = { version = "0.6.4", features = ["std"] }
|
rand_core = { version = "0.6.4", features = ["std"] }
|
||||||
url = "2.5.3"
|
url = "2.5.3"
|
||||||
argh = "0.1" # for CLI
|
|
||||||
|
# CLI
|
||||||
|
argh = "0.1"
|
||||||
|
|
||||||
# Async
|
# Async
|
||||||
tokio = { version = "1.40.0", features = ["rt-multi-thread"] }
|
tokio = { version = "1.40.0", features = ["rt-multi-thread"] }
|
||||||
|
|
@ -61,3 +63,11 @@ time = "0.3.36"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
minijinja-embed = "2.3.1"
|
minijinja-embed = "2.3.1"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "minauthator-server"
|
||||||
|
path = "src/http_server/cli.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "minauthator-admin"
|
||||||
|
path = "src/admin_cli/cli.rs"
|
||||||
|
|
|
||||||
7
src/Cargo.toml
Normal file
7
src/Cargo.toml
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
[workspace]
|
||||||
|
members = [
|
||||||
|
"kernel",
|
||||||
|
"http_server",
|
||||||
|
"admin_cli"
|
||||||
|
"utils"
|
||||||
|
]
|
||||||
4
src/admin_cli/cli.rs
Normal file
4
src/admin_cli/cli.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<()> {
|
||||||
|
cli::start_server_cli().await
|
||||||
|
}
|
||||||
|
|
@ -1 +0,0 @@
|
||||||
pub const WEB_GUI_JWT_COOKIE_NAME: &str = "minauthator_jwt";
|
|
||||||
|
|
@ -46,3 +46,8 @@ pub async fn start_server_cli() -> Result<()> {
|
||||||
db_pool
|
db_pool
|
||||||
).await
|
).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<()> {
|
||||||
|
cli::start_server_cli().await
|
||||||
|
}
|
||||||
0
src/http_server/controllers/ui/admin/apps.rs
Normal file
0
src/http_server/controllers/ui/admin/apps.rs
Normal file
0
src/http_server/controllers/ui/admin/authorizations.rs
Normal file
0
src/http_server/controllers/ui/admin/authorizations.rs
Normal file
0
src/http_server/controllers/ui/admin/users.rs
Normal file
0
src/http_server/controllers/ui/admin/users.rs
Normal file
|
|
@ -1,11 +1,9 @@
|
||||||
|
pub mod cli;
|
||||||
pub mod controllers;
|
pub mod controllers;
|
||||||
pub mod router;
|
pub mod router;
|
||||||
pub mod database;
|
|
||||||
pub mod utils;
|
|
||||||
pub mod services;
|
pub mod services;
|
||||||
pub mod middlewares;
|
pub mod middlewares;
|
||||||
pub mod renderer;
|
pub mod renderer;
|
||||||
pub mod consts;
|
|
||||||
|
|
||||||
use base64::{prelude::BASE64_STANDARD, Engine};
|
use base64::{prelude::BASE64_STANDARD, Engine};
|
||||||
use fully_pub::fully_pub;
|
use fully_pub::fully_pub;
|
||||||
|
|
@ -13,6 +11,7 @@ use anyhow::{Result, Context};
|
||||||
use log::info;
|
use log::info;
|
||||||
use minijinja::{context, Environment};
|
use minijinja::{context, Environment};
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
|
|
||||||
use crate::{models::config::{AppSecrets, Config}, router::build_router};
|
use crate::{models::config::{AppSecrets, Config}, router::build_router};
|
||||||
|
|
||||||
fn build_templating_env(config: &Config) -> Environment<'static> {
|
fn build_templating_env(config: &Config) -> Environment<'static> {
|
||||||
0
src/kernel/Cargo.toml
Normal file
0
src/kernel/Cargo.toml
Normal file
5
src/kernel/consts.rs
Normal file
5
src/kernel/consts.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
pub const DEFAULT_DB_PATH: &str = "/var/lib/minauthator/minauthator.db";
|
||||||
|
pub const DEFAULT_ASSETS_PATH: &str = "/usr/local/lib/minauthator/assets";
|
||||||
|
pub const DEFAULT_CONFIG_PATH: &str = "/etc/minauthator/config.yaml";
|
||||||
|
|
||||||
|
pub const WEB_GUI_JWT_COOKIE_NAME: &str = "minauthator_jwt";
|
||||||
|
|
@ -1,21 +1,12 @@
|
||||||
pub mod models;
|
|
||||||
pub mod server;
|
|
||||||
pub mod database;
|
|
||||||
pub mod utils;
|
|
||||||
pub mod consts;
|
|
||||||
|
|
||||||
use std::{env, fs};
|
use std::{env, fs};
|
||||||
use anyhow::{Result, Context, anyhow};
|
use anyhow::{Result, Context, anyhow};
|
||||||
|
use fully_pub::fully_pub;
|
||||||
|
|
||||||
use database::prepare_database;
|
use database::prepare_database;
|
||||||
use log::info;
|
use log::info;
|
||||||
use sqlx::{Pool, Sqlite};
|
use sqlx::{Pool, Sqlite};
|
||||||
use models::config::{AppSecrets, Config};
|
use models::config::{AppSecrets, Config};
|
||||||
|
|
||||||
pub const DEFAULT_DB_PATH: &str = "/var/lib/minauthator/minauthator.db";
|
|
||||||
pub const DEFAULT_ASSETS_PATH: &str = "/usr/local/lib/minauthator/assets";
|
|
||||||
pub const DEFAULT_CONFIG_PATH: &str = "/etc/minauthator/config.yaml";
|
|
||||||
|
|
||||||
fn get_config(path: String) -> Result<Config> {
|
fn get_config(path: String) -> Result<Config> {
|
||||||
let inp_def_yaml = fs::read_to_string(path)
|
let inp_def_yaml = fs::read_to_string(path)
|
||||||
.expect("Should have been able to read the the config file");
|
.expect("Should have been able to read the the config file");
|
||||||
|
|
@ -24,16 +15,12 @@ fn get_config(path: String) -> Result<Config> {
|
||||||
.map_err(|e| anyhow!("Failed to parse config, {:?}", e))
|
.map_err(|e| anyhow!("Failed to parse config, {:?}", e))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[fully_pub]
|
||||||
struct StartAppConfig {
|
struct StartAppConfig {
|
||||||
config_path: Option<String>,
|
config_path: Option<String>,
|
||||||
database_path: Option<String>,
|
database_path: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() -> Result<()> {
|
|
||||||
cli::start_server_cli().await
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn get_app_context(start_app_config: StartAppConfig) -> Result<(Config, AppSecrets, Pool<Sqlite>)> {
|
async fn get_app_context(start_app_config: StartAppConfig) -> Result<(Config, AppSecrets, Pool<Sqlite>)> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let _ = dotenvy::dotenv();
|
let _ = dotenvy::dotenv();
|
||||||
5
src/kernel/mod.rs
Normal file
5
src/kernel/mod.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
pub mod models;
|
||||||
|
pub mod database;
|
||||||
|
pub mod consts;
|
||||||
|
pub mod context;
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue