From 1c366611d9850c3ff061d8b5c9f1d7808411e735 Mon Sep 17 00:00:00 2001 From: shockrah Date: Sat, 8 May 2021 01:59:31 -0700 Subject: [PATCH] + Server tags are now stored in json format(still in the environment variable mind you Lazy static initialization still allocates once per run so the above is jank but fine(mostly) [] Should probably come up with a cleaner way of passing this data around The above is very low on the priority list of things to do + Now injecting permisions + id via the claim structure which is passed to the route dispatcher ! For now this is unused further down the decision tree however I'm going to sprinkle in its incorporation as it lets us avoid string conversions which is p nice --- json-api/src/main.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/json-api/src/main.rs b/json-api/src/main.rs index a1e1a38..66588b1 100644 --- a/json-api/src/main.rs +++ b/json-api/src/main.rs @@ -58,7 +58,8 @@ async fn route_dispatcher( path: &str, body: Body, params: HashMap, - headers: HeaderMap) { + headers: HeaderMap, + claims: Option/* Faster id/perms access from here */) { const GET: &Method = &Method::GET; const POST: &Method = &Method::POST; @@ -87,6 +88,8 @@ async fn route_dispatcher( (POST, routes::SET_NEW_ADMIN) => admin::new_admin(pool, resp, params).await, /* META ROUTE */ (GET, routes::META) => meta::server_meta(resp).await, + /* Federated Routes */ + (GET, routes::GET_NEIGHBORS) => meta::server_neighbors(pool, resp).await, _ => { println!("[HTTP]\tNOT FOUND: {}: {}", meth, path); *resp.status_mut() = StatusCode::NOT_FOUND @@ -109,15 +112,18 @@ async fn main_responder(request: Request) -> Result, hyper: None }; - if let Some(params) = params_opt { - match auth::wall_entry(path, &DB_POOL, ¶ms).await { - OpenAuth | Good => { - // route dispatch has its own more comprehensive logging - route_dispatcher(&DB_POOL, &mut response, &method, path, body, params, headers).await; + if let Some(qs) = params_opt { + match auth::wall_entry(path, &DB_POOL, &qs).await { + OpenAuth => { + route_dispatcher(&DB_POOL, &mut response, &method, path, body, qs, headers, None).await; }, - LoginValid => { + // Only with typical routes do we have to inject the permissions + Good(claim) => { + route_dispatcher(&DB_POOL, &mut response, &method, path, body, qs, headers, Some(claim)).await; + }, + LoginValid(member) => { println!("[HTTP] POST /login"); - auth::login_get_jwt(&mut response, params).await; + auth::login_get_jwt(&DB_POOL, &mut response, member).await; }, NoKey | BadKey => { *response.status_mut() = StatusCode::UNAUTHORIZED; @@ -225,6 +231,13 @@ fn init_config() -> Result<(), Box> { set_var("PUBLIC_URL", fields.public_url); set_var("PUBLIC_WS_URL", fields.public_ws_url); + // NOTE: the debug print actually prints out what looks to be valid json + // so we're just going to leverage that for passing this bs around + let tags_json = match fields.tags { + Some(t) => format!("{:?}", t), + None => format!("[]") + }; + set_var("SERVER_TAGS", tags_json); Ok(()) }