From a0c4b91955662297ec5bd9249a9488ea6d52defc Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Mon, 5 Apr 2021 17:22:48 +0200 Subject: fix(web/converse): Bare minimum changes to build in 2021 This project depends on Tokio, via actix, and both of those are bad ideas. This wasn't as clear 3 years ago as it is now, but to demonstrate it the project has amassed issues which required at least this minimum of changes to be buildable in 2021 (using a modern rustc). Yes, this adds dozens of new dependencies again (because of a top-level update) but don't worry: They will be gone when I'm done here. Change-Id: I1dde9dc0325da7bdcb6608359fab33e27692dc1d Reviewed-on: https://cl.tvl.fyi/c/depot/+/2857 Tested-by: BuildkiteCI Reviewed-by: tazjin --- web/converse/src/handlers.rs | 14 +++++++------- web/converse/src/main.rs | 28 ++++++++++++++-------------- web/converse/src/oidc.rs | 4 +--- 3 files changed, 22 insertions(+), 24 deletions(-) (limited to 'web/converse/src') diff --git a/web/converse/src/handlers.rs b/web/converse/src/handlers.rs index efdffb3f9102..d558afbe1242 100644 --- a/web/converse/src/handlers.rs +++ b/web/converse/src/handlers.rs @@ -46,13 +46,13 @@ const NEW_THREAD_LENGTH_ERR: &'static str = "Title and body can not be empty!"; /// Represents the state carried by the web server actors. pub struct AppState { /// Address of the database actor - pub db: Addr, + pub db: Addr, /// Address of the OIDC actor - pub oidc: Addr, + pub oidc: Addr, /// Address of the rendering actor - pub renderer: Addr, + pub renderer: Addr, } pub fn forum_index(state: State) -> ConverseResponse { @@ -113,9 +113,9 @@ pub struct NewThreadForm { /// This handler receives a "New thread"-form and redirects the user /// to the new thread after creation. -pub fn submit_thread(state: State, - input: Form, - req: HttpRequest) -> ConverseResponse { +pub fn submit_thread((state, input, req): (State, + Form, + HttpRequest)) -> ConverseResponse { // Trim whitespace out of inputs: let input = NewThreadForm { title: input.title.trim().into(), @@ -328,7 +328,7 @@ impl EmbeddedFile for App { pub struct RequireLogin; impl Middleware for RequireLogin { - fn start(&self, req: &mut HttpRequest) -> actix_web::Result { + fn start(&self, req: &HttpRequest) -> actix_web::Result { let logged_in = req.identity().is_some(); let is_oidc_req = req.path().starts_with("/oidc"); diff --git a/web/converse/src/main.rs b/web/converse/src/main.rs index 55d84b981b64..5c8a188fc31b 100644 --- a/web/converse/src/main.rs +++ b/web/converse/src/main.rs @@ -90,7 +90,7 @@ fn config_default(name: &str, default: &str) -> String { env::var(name).unwrap_or(default.into()) } -fn start_db_executor() -> Addr { +fn start_db_executor() -> Addr { info!("Initialising database connection pool ..."); let db_url = config("DATABASE_URL"); @@ -100,7 +100,7 @@ fn start_db_executor() -> Addr { SyncArbiter::start(2, move || DbExecutor(pool.clone())) } -fn schedule_search_refresh(db: Addr) { +fn schedule_search_refresh(db: Addr) { use tokio::prelude::*; use tokio::timer::Interval; use std::time::{Duration, Instant}; @@ -114,7 +114,7 @@ fn schedule_search_refresh(db: Addr) { thread::spawn(|| tokio::run(task)); } -fn start_oidc_executor(base_url: &str) -> Addr { +fn start_oidc_executor(base_url: &str) -> Addr { info!("Initialising OIDC integration ..."); let oidc_url = config("OIDC_DISCOVERY_URL"); let oidc_config = oidc::load_oidc(&oidc_url) @@ -130,7 +130,7 @@ fn start_oidc_executor(base_url: &str) -> Addr { oidc.start() } -fn start_renderer() -> Addr { +fn start_renderer() -> Addr { let comrak = comrak::ComrakOptions{ github_pre_lang: true, ext_strikethrough: true, @@ -155,9 +155,9 @@ fn gen_session_key() -> [u8; 64] { } fn start_http_server(base_url: String, - db_addr: Addr, - oidc_addr: Addr, - renderer_addr: Addr) { + db_addr: Addr, + oidc_addr: Addr, + renderer_addr: Addr) { info!("Initialising HTTP server ..."); let bind_host = config_default("CONVERSE_BIND_HOST", "127.0.0.1:4567"); let key = gen_session_key(); @@ -182,14 +182,14 @@ fn start_http_server(base_url: String, .middleware(identity) .resource("/", |r| r.method(Method::GET).with(forum_index)) .resource("/thread/new", |r| r.method(Method::GET).with(new_thread)) - .resource("/thread/submit", |r| r.method(Method::POST).with3(submit_thread)) - .resource("/thread/reply", |r| r.method(Method::POST).with3(reply_thread)) - .resource("/thread/{id}", |r| r.method(Method::GET).with3(forum_thread)) - .resource("/post/{id}/edit", |r| r.method(Method::GET).with3(edit_form)) - .resource("/post/edit", |r| r.method(Method::POST).with3(edit_post)) - .resource("/search", |r| r.method(Method::GET).with2(search_forum)) + .resource("/thread/submit", |r| r.method(Method::POST).with(submit_thread)) + .resource("/thread/reply", |r| r.method(Method::POST).with(reply_thread)) + .resource("/thread/{id}", |r| r.method(Method::GET).with(forum_thread)) + .resource("/post/{id}/edit", |r| r.method(Method::GET).with(edit_form)) + .resource("/post/edit", |r| r.method(Method::POST).with(edit_post)) + .resource("/search", |r| r.method(Method::GET).with(search_forum)) .resource("/oidc/login", |r| r.method(Method::GET).with(login)) - .resource("/oidc/callback", |r| r.method(Method::POST).with3(callback)) + .resource("/oidc/callback", |r| r.method(Method::POST).with(callback)) .static_file("/static/highlight.css", include_bytes!("../static/highlight.css")) .static_file("/static/highlight.js", include_bytes!("../static/highlight.js")) .static_file("/static/styles.css", include_bytes!("../static/styles.css")); diff --git a/web/converse/src/oidc.rs b/web/converse/src/oidc.rs index 970aeb92aa47..849143596895 100644 --- a/web/converse/src/oidc.rs +++ b/web/converse/src/oidc.rs @@ -27,8 +27,6 @@ use reqwest; use url::Url; use url_serde; use errors::*; -use reqwest::header::Authorization; -use hyper::header::Bearer; /// This structure represents the contents of an OIDC discovery /// document. @@ -130,7 +128,7 @@ impl Handler for OidcExecutor { let token: TokenResponse = response.json()?; let user: Userinfo = client.get(&self.oidc_config.userinfo_endpoint) - .header(Authorization(Bearer { token: token.access_token })) + .header("Authorization", format!("Bearer {}", token.access_token )) .send()? .json()?; -- cgit 1.4.1