diff --git a/Cargo.lock b/Cargo.lock index 9564c3a..be5f755 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -285,7 +285,6 @@ dependencies = [ "dotenv", "env_logger", "futures", - "getrandom", "http 1.0.0", "jsonwebtoken", "log", @@ -659,9 +658,9 @@ dependencies = [ [[package]] name = "http-range-header" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ce4ef31cda248bbdb6e6820603b82dfcd9e833db65a43e997a0ccec777d11fe" +checksum = "08a397c49fec283e3d6211adbe480be95aae5f304cfb923e9970e08956d5168a" [[package]] name = "httparse" diff --git a/Cargo.toml b/Cargo.toml index 22ae6ef..c85c79e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,57 +1,137 @@ [package] name = "citadels" edition = "2021" -default-run = "citadels" version = "0.7.1" +default-run = "citadels" -[[bin]] -name = "citadels" -path = "src/main.rs" +[package.metadata.cargo-machete] +ignored = ["tower"] [dependencies] -askama = { version = "0.12.1", default-features = false } -axum = { version = "0.7.2", features = ["ws","macros"], default-features = true } -futures = { version = "0.3.30", default-features = false } -http = { version = "1.0.0", default-features = false } -rand = { version = "0.8.5", default-features = false } -tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread"] } -tokio-stream = { version = "0.1.14", default-features = false } -tower = "0.4.13" -tower-http = { version = "0.5.0", features = ["fs", "trace"] } -tower-layer = "0.3.2" -tower-cookies = "0.10.0" +async-trait = "0.1.80" +axum-core = "0.4.3" log = "0.4.20" -env_logger = { version = "0.10.1", features = ["color"] } +percent-encoding = "2.3.1" rand_xoshiro = "0.6.0" -rand_core = { version = "0.6.4", features = ["getrandom"] } -serde = { version = "1.0.195", features = ["derive"] } serde_json = "1.0.111" -time = "0.3.31" -dotenv = { version = "0.15.0", optional = true } -axum-core = "0.4.3" serde_with = "3.5.0" -tracing = { version = "0.1.40", default-features = false } -macros = { path = "./macros"} -reqwest = { version = "0.12.4", features = ["json"], default-features = false } -anyhow = { version = "1.0.83", features = ["std", "backtrace"], default-features = false } -maud = { version = "0.26.0", features = ["axum"], default-features = false} -arcstr = { version = "1.2.0", features = ["serde"], default-features = false } -uuid = { version = "1.8.0", features = ["v4"] } thiserror = "1.0.61" -percent-encoding = "2.3.1" -pkce = { path = "./vendor/pkce" } +time = "0.3.31" +tower = "0.4.13" +tower-cookies = "0.10.0" +tower-layer = "0.3.2" tower-service = "0.3.2" -async-trait = "0.1.80" -jsonwebtoken = { version = "9.3.0", default-features = false } -getrandom = { version = "0.2.11", default-features = false } + +[dependencies.anyhow] +version = "1.0.83" +features = ["std", "backtrace"] +default-features = false + +[dependencies.arcstr] +version = "1.2.0" +features = ["serde"] +default-features = false + +[dependencies.askama] +version = "0.12.1" +features = [] +default-features = false + +[dependencies.axum] +version = "0.7.2" +features = ["ws", "macros"] + +[dependencies.dotenv] +version = "0.15.0" +features = [] +optional = true + +[dependencies.env_logger] +version = "0.10.1" +features = ["color"] + +[dependencies.futures] +version = "0.3.30" +features = [] +default-features = false + +[dependencies.http] +version = "1.0.0" +features = [] +default-features = false + +[dependencies.jsonwebtoken] +version = "9.3.0" +features = [] +default-features = false + +[dependencies.macros] +path = "./macros" +features = [] + +[dependencies.maud] +version = "0.26.0" +features = ["axum"] +default-features = false + +[dependencies.pkce] +path = "./vendor/pkce" +features = [] + +[dependencies.rand] +version = "0.8.5" +features = [] +default-features = false + +[dependencies.rand_core] +version = "0.6.4" +features = ["getrandom"] + +[dependencies.reqwest] +version = "0.12.4" +features = ["json"] +default-features = false + +[dependencies.serde] +version = "1.0.195" +features = ["derive"] + +[dependencies.tokio] +version = "1.35.1" +features = ["macros", "rt-multi-thread"] + +[dependencies.tokio-stream] +version = "0.1.14" +features = [] +default-features = false + +[dependencies.tower-http] +version = "0.5.0" +features = ["fs"] +default-features = false +optional = true + +[dependencies.tracing] +version = "0.1.40" +features = [] +default-features = false + +[dependencies.uuid] +version = "1.8.0" +features = ["v4"] +default-features = false [features] -dev = [] +dev = ["dep:tower-http"] dotenv = ["dep:dotenv"] -# https://old.reddit.com/r/rust/comments/gvrgca/this_is_a_neat_trick_for_getting_good_runtime/ +[profile.dev] +opt-level = 0 + [profile.dev.package."*"] opt-level = 3 -[profile.dev] -opt-level = 0 +[[bin]] +path = "src/main.rs" +name = "citadels" +required-features = [] diff --git a/README.md b/README.md index 0c4f11b..7e2ae71 100644 --- a/README.md +++ b/README.md @@ -72,10 +72,6 @@ This is excessive, and I will try to stick to 3: - info ## Env & Secret management -Script to generate a new signing key: -```bash -node -e "console.log(require('crypto').randomBytes(64).toString('hex'))" -``` In prod use `fly secret`. In dev, use the .env file. @@ -87,3 +83,8 @@ For production go in: - Use `fly secret`, for the secret env vars. Don't use `.config/cargo.toml` or the env! macro. We need runtime env lookup, not compile time. + +## Dependency Management +Use cargo-machete & cargo-unused-features to prune what is downloaded and compiled. + +Use careful judgement about when to include a dep, and when to fork and vendor. By vendoring we can still respect the licenses but remove unused optional dependencies. `vendor/` folder is for forked vendored libraries. diff --git a/sample.json b/sample.json deleted file mode 100644 index f4a3168..0000000 --- a/sample.json +++ /dev/null @@ -1 +0,0 @@ -{"access_token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJhdXRoZW50aWNhdGVkIiwiZXhwIjoxNzE2MDgxODM4LCJpYXQiOjE3MTYwNzgyMzgsImlzcyI6Imh0dHA6Ly8xMjcuMC4wLjE6NTQzMjEvYXV0aC92MSIsInN1YiI6IjQ3NTNhYjgyLWZlMmYtNDliYi04M2YzLWFhYTRlNWFiZWQ1MyIsImVtYWlsIjoiY2hhcmxlc3RheWxvcjk1QGdtYWlsLmNvbSIsInBob25lIjoiIiwiYXBwX21ldGFkYXRhIjp7InByb3ZpZGVyIjoiZW1haWwiLCJwcm92aWRlcnMiOlsiZW1haWwiLCJkaXNjb3JkIl19LCJ1c2VyX21ldGFkYXRhIjp7ImF2YXRhcl91cmwiOiJodHRwczovL2Nkbi5kaXNjb3JkYXBwLmNvbS9hdmF0YXJzLzIxNTg0NTEwOTM3NDI1NTEwNC83Yzk2YjgzNjQ1ODg1MjY1MWI4MTMwMTI4NjI5NzIwOS5wbmciLCJjdXN0b21fY2xhaW1zIjp7Imdsb2JhbF9uYW1lIjoiQ2hhcmxlcyBUYXlsb3IifSwiZW1haWwiOiJjaGFybGVzdGF5bG9yOTVAZ21haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImZ1bGxfbmFtZSI6Im5pbmphcGVuZ3VpbjciLCJpc3MiOiJodHRwczovL2Rpc2NvcmQuY29tL2FwaSIsIm5hbWUiOiJuaW5qYXBlbmd1aW43IzAiLCJwaG9uZV92ZXJpZmllZCI6ZmFsc2UsInBpY3R1cmUiOiJodHRwczovL2Nkbi5kaXNjb3JkYXBwLmNvbS9hdmF0YXJzLzIxNTg0NTEwOTM3NDI1NTEwNC83Yzk2YjgzNjQ1ODg1MjY1MWI4MTMwMTI4NjI5NzIwOS5wbmciLCJwcm92aWRlcl9pZCI6IjIxNTg0NTEwOTM3NDI1NTEwNCIsInN1YiI6IjIxNTg0NTEwOTM3NDI1NTEwNCJ9LCJyb2xlIjoiYXV0aGVudGljYXRlZCIsImFhbCI6ImFhbDEiLCJhbXIiOlt7Im1ldGhvZCI6Im9hdXRoIiwidGltZXN0YW1wIjoxNzE2MDc4MjM4fV0sInNlc3Npb25faWQiOiJhZWQxMzhiZi1mMThmLTQ2NzQtOWZlOC1jOWFlNzQ1MDRjZjAiLCJpc19hbm9ueW1vdXMiOmZhbHNlfQ.5iTs_RJN6qEcgdEgCcENaS6VOxvUBulaIUgXcZwgkXc","token_type":"bearer","expires_in":3600,"expires_at":1716081838,"refresh_token":"XxoLoyPD2XfU3DyfYYdgpQ","user":{"id":"4753ab82-fe2f-49bb-83f3-aaa4e5abed53","aud":"authenticated","role":"authenticated","email":"charlestaylor95@gmail.com","email_confirmed_at":"2024-05-17T20:18:10.576435Z","phone":"","confirmed_at":"2024-05-17T20:18:10.576435Z","last_sign_in_at":"2024-05-19T00:23:58.630452632Z","app_metadata":{"provider":"email","providers":["email","discord"]},"user_metadata":{"avatar_url":"https://cdn.discordapp.com/avatars/215845109374255104/7c96b836458852651b81301286297209.png","custom_claims":{"global_name":"Charles Taylor"},"email":"charlestaylor95@gmail.com","email_verified":true,"full_name":"ninjapenguin7","iss":"https://discord.com/api","name":"ninjapenguin7#0","phone_verified":false,"picture":"https://cdn.discordapp.com/avatars/215845109374255104/7c96b836458852651b81301286297209.png","provider_id":"215845109374255104","sub":"215845109374255104"},"identities":[{"identity_id":"cd4a536a-b9ac-4032-9d21-8c2d27c10b0a","id":"4753ab82-fe2f-49bb-83f3-aaa4e5abed53","user_id":"4753ab82-fe2f-49bb-83f3-aaa4e5abed53","identity_data":{"email":"charlestaylor95@gmail.com","email_verified":false,"phone_verified":false,"sub":"4753ab82-fe2f-49bb-83f3-aaa4e5abed53"},"provider":"email","last_sign_in_at":"2024-05-17T20:18:10.574566Z","created_at":"2024-05-17T20:18:10.574596Z","updated_at":"2024-05-17T20:18:10.574596Z","email":"charlestaylor95@gmail.com"},{"identity_id":"9dfa85b7-c577-4c59-8583-8823bfe9146d","id":"215845109374255104","user_id":"4753ab82-fe2f-49bb-83f3-aaa4e5abed53","identity_data":{"avatar_url":"https://cdn.discordapp.com/avatars/215845109374255104/7c96b836458852651b81301286297209.png","custom_claims":{"global_name":"Charles Taylor"},"email":"charlestaylor95@gmail.com","email_verified":true,"full_name":"ninjapenguin7","iss":"https://discord.com/api","name":"ninjapenguin7#0","phone_verified":false,"picture":"https://cdn.discordapp.com/avatars/215845109374255104/7c96b836458852651b81301286297209.png","provider_id":"215845109374255104","sub":"215845109374255104"},"provider":"discord","last_sign_in_at":"2024-05-18T03:34:36.587713Z","created_at":"2024-05-18T03:34:36.587759Z","updated_at":"2024-05-19T00:23:58.615645Z","email":"charlestaylor95@gmail.com"}],"created_at":"2024-05-17T20:18:10.572403Z","updated_at":"2024-05-19T00:23:58.632534Z","is_anonymous":false},"provider_token":"0fyU2AZq4Pbkyg7j3T4UKPLQaeFOTN","provider_refresh_token":"XHSVwOm9ZqSuUSThSpNqb0228y2Cvl"} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 48486ab..56e2b8f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,12 +6,6 @@ async fn main() { #[cfg(feature = "dotenv")] dotenv::dotenv().expect(".env not found"); - /* - tracing_subscriber::fmt() - .with_max_level(tracing::Level::DEBUG) - .init(); - */ - citadels::logger::init(); let host = "0.0.0.0:8080"; diff --git a/src/server/routes.rs b/src/server/routes.rs index 15c1240..e7d6839 100644 --- a/src/server/routes.rs +++ b/src/server/routes.rs @@ -28,7 +28,6 @@ use serde::Deserialize; use std::borrow::{Borrow, Cow}; use std::collections::{HashMap, HashSet}; use tower_cookies::{CookieManagerLayer, Cookies}; -use tower_http::trace::TraceLayer; pub fn get_router(state: AppState) -> Router { let mut router = Router::new() @@ -52,13 +51,13 @@ pub fn get_router(state: AppState) -> Router { .route("/game/action", post(submit_game_action)) .route("/game/menu/:menu", get(get_game_menu)); - if cfg!(feature = "dev") { + #[cfg(feature = "dev")] + { use tower_http::services::ServeDir; router = router.nest_service("/public", ServeDir::new("public")); } router - .layer(TraceLayer::new_for_http()) .layer(SessionCookieLayer::new()) .layer(CookieManagerLayer::new()) .with_state(state)