Init package
This commit is contained in:
commit
66b3a99814
17 changed files with 2526 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
2373
Cargo.lock
generated
Normal file
2373
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
37
Cargo.toml
Normal file
37
Cargo.toml
Normal file
|
@ -0,0 +1,37 @@
|
|||
[package]
|
||||
name = "minauthator"
|
||||
description = "Identity provider and OAuth2 server for an small-scale organization."
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
# commons utils
|
||||
anyhow = "1.0"
|
||||
fully_pub = "0.1"
|
||||
argon2 = "0.5"
|
||||
strum_macros = "0.26"
|
||||
uuid = { version = "1.8", features = ["serde", "v4"] }
|
||||
argh = "0.1" # for CLI
|
||||
|
||||
# logging
|
||||
log = "0.4"
|
||||
env_logger = "0.11"
|
||||
|
||||
# serialization
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
toml = "0.8"
|
||||
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
|
||||
# DB
|
||||
sqlx = { version = "0.7.4", features = ["sqlite", "runtime-tokio", "chrono", "uuid"] }
|
||||
redis = { version = "0.27.3", default-features = false, features = ["acl"] }
|
||||
|
||||
# web
|
||||
axum = { version = "0.7.7", features = ["json"] }
|
||||
axum-template = { version = "2.4.0", features = ["minijinja"] }
|
||||
minijinja = { version = "2.1", features = ["builtins"] }
|
||||
|
||||
# Auth utils
|
||||
totp-rs = "5.6"
|
28
src/cli.rs
Normal file
28
src/cli.rs
Normal file
|
@ -0,0 +1,28 @@
|
|||
use argh::FromArgs;
|
||||
|
||||
|
||||
|
||||
#[derive(Debug, FromArgs)]
|
||||
/// Autotasker daemon
|
||||
struct CliFlags {
|
||||
/// path to YAML config file to use to configure autotasker
|
||||
#[argh(option)]
|
||||
config: Option<String>,
|
||||
|
||||
/// path to the Sqlite3 DB file to use
|
||||
#[argh(option)]
|
||||
database: Option<String>,
|
||||
|
||||
/// path to the static assets dir
|
||||
#[argh(option)]
|
||||
static_assets: Option<String>,
|
||||
|
||||
/// HTTP listen host
|
||||
#[argh(option, default="String::from(\"localhost\")")]
|
||||
listen_host: String,
|
||||
/// HTTP listen port
|
||||
#[argh(option, default="8085")]
|
||||
listen_port: u32
|
||||
}
|
||||
|
||||
|
1
src/controllers/api/mod.rs
Normal file
1
src/controllers/api/mod.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub mod verify_authorization;
|
0
src/controllers/api/verify_authorization.rs
Normal file
0
src/controllers/api/verify_authorization.rs
Normal file
2
src/controllers/mod.rs
Normal file
2
src/controllers/mod.rs
Normal file
|
@ -0,0 +1,2 @@
|
|||
pub mod api;
|
||||
pub mod ui;
|
0
src/controllers/ui/authorize.rs
Normal file
0
src/controllers/ui/authorize.rs
Normal file
0
src/controllers/ui/login.rs
Normal file
0
src/controllers/ui/login.rs
Normal file
3
src/controllers/ui/mod.rs
Normal file
3
src/controllers/ui/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub mod authorize;
|
||||
pub mod login;
|
||||
pub mod register;
|
0
src/controllers/ui/register.rs
Normal file
0
src/controllers/ui/register.rs
Normal file
20
src/main.rs
Normal file
20
src/main.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
pub mod models;
|
||||
pub mod controllers;
|
||||
|
||||
use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions};
|
||||
use sqlx::{ConnectOptions, Pool, Sqlite};
|
||||
use models::config::Config;
|
||||
use minijinja::{context, Environment};
|
||||
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AppState {
|
||||
config: Config,
|
||||
db: Pool<Sqlite>,
|
||||
templating_env: Environment<'static>
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
0
src/models/app.rs
Normal file
0
src/models/app.rs
Normal file
24
src/models/config.rs
Normal file
24
src/models/config.rs
Normal file
|
@ -0,0 +1,24 @@
|
|||
use std::collections::HashMap;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use fully_pub::fully_pub;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[fully_pub]
|
||||
/// Instance branding/customization config
|
||||
struct InstanceConfig {
|
||||
name: String,
|
||||
logo_uri: String
|
||||
}
|
||||
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[fully_pub]
|
||||
/// Configuration of this minauthator instance
|
||||
struct Config {
|
||||
/// configure current autotasker instance
|
||||
instance: Option<InstanceConfig>,
|
||||
}
|
||||
|
3
src/models/mod.rs
Normal file
3
src/models/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub mod app;
|
||||
pub mod config;
|
||||
pub mod user;
|
0
src/models/user.rs
Normal file
0
src/models/user.rs
Normal file
34
src/server.rs
Normal file
34
src/server.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
|
||||
fn get_config(path: String) -> Result<Config> {
|
||||
let inp_def_yaml = fs::read_to_string(path)
|
||||
.expect("Should have been able to read the the config file");
|
||||
|
||||
serde_yaml::from_str(&inp_def_yaml)
|
||||
.map_err(|e| anyhow!("Failed to parse config, {:?}", e))
|
||||
}
|
||||
|
||||
fn build_templating_env() -> Environment<'static> {
|
||||
let mut templating_env = Environment::new();
|
||||
|
||||
let _ = templating_env
|
||||
.add_template("layouts/base.html", include_str!("./templates/layouts/base.html"));
|
||||
let _ = templating_env
|
||||
.add_template("pages/home.html", include_str!("./templates/pages/home.html"));
|
||||
let _ = templating_env
|
||||
.add_template("pages/list_tasks.html", include_str!("./templates/pages/list_tasks.html"));
|
||||
let _ = templating_env
|
||||
.add_template("pages/list_task_runs.html", include_str!("./templates/pages/list_task_runs.html"));
|
||||
let _ = templating_env
|
||||
.add_template("pages/task_run_details.html", include_str!("./templates/pages/task_run_details.html"));
|
||||
let _ = templating_env
|
||||
.add_template("pages/run_task.html", include_str!("./templates/pages/run_task.html"));
|
||||
|
||||
// TODO: better loading with embed https://docs.rs/minijinja-embed/latest/minijinja_embed/
|
||||
templating_env.add_global("gl", context! {
|
||||
instance => context! {
|
||||
version => "1.243".to_string()
|
||||
}
|
||||
});
|
||||
templating_env
|
||||
}
|
||||
|
Loading…
Reference in a new issue