+ 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
This commit is contained in:
parent
c850d42ce1
commit
1c366611d9
@ -58,7 +58,8 @@ async fn route_dispatcher(
|
|||||||
path: &str,
|
path: &str,
|
||||||
body: Body,
|
body: Body,
|
||||||
params: HashMap<String, String>,
|
params: HashMap<String, String>,
|
||||||
headers: HeaderMap) {
|
headers: HeaderMap,
|
||||||
|
claims: Option<auth::Claim>/* Faster id/perms access from here */) {
|
||||||
|
|
||||||
const GET: &Method = &Method::GET;
|
const GET: &Method = &Method::GET;
|
||||||
const POST: &Method = &Method::POST;
|
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,
|
(POST, routes::SET_NEW_ADMIN) => admin::new_admin(pool, resp, params).await,
|
||||||
/* META ROUTE */
|
/* META ROUTE */
|
||||||
(GET, routes::META) => meta::server_meta(resp).await,
|
(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);
|
println!("[HTTP]\tNOT FOUND: {}: {}", meth, path);
|
||||||
*resp.status_mut() = StatusCode::NOT_FOUND
|
*resp.status_mut() = StatusCode::NOT_FOUND
|
||||||
@ -109,15 +112,18 @@ async fn main_responder(request: Request<Body>) -> Result<Response<Body>, hyper:
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(params) = params_opt {
|
if let Some(qs) = params_opt {
|
||||||
match auth::wall_entry(path, &DB_POOL, ¶ms).await {
|
match auth::wall_entry(path, &DB_POOL, &qs).await {
|
||||||
OpenAuth | Good => {
|
OpenAuth => {
|
||||||
// route dispatch has its own more comprehensive logging
|
route_dispatcher(&DB_POOL, &mut response, &method, path, body, qs, headers, None).await;
|
||||||
route_dispatcher(&DB_POOL, &mut response, &method, path, body, params, headers).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");
|
println!("[HTTP] POST /login");
|
||||||
auth::login_get_jwt(&mut response, params).await;
|
auth::login_get_jwt(&DB_POOL, &mut response, member).await;
|
||||||
},
|
},
|
||||||
NoKey | BadKey => {
|
NoKey | BadKey => {
|
||||||
*response.status_mut() = StatusCode::UNAUTHORIZED;
|
*response.status_mut() = StatusCode::UNAUTHORIZED;
|
||||||
@ -225,6 +231,13 @@ fn init_config() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
set_var("PUBLIC_URL", fields.public_url);
|
set_var("PUBLIC_URL", fields.public_url);
|
||||||
set_var("PUBLIC_WS_URL", fields.public_ws_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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user