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 <mail@tazj.in>
This commit is contained in:
parent
5387cc9e7d
commit
a0c4b91955
7 changed files with 1936 additions and 6664 deletions
3141
web/converse/Cargo.lock
generated
3141
web/converse/Cargo.lock
generated
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -2,11 +2,11 @@
|
||||||
name = "converse"
|
name = "converse"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
authors = ["Vincent Ambo <mail@tazj.in>"]
|
authors = ["Vincent Ambo <mail@tazj.in>"]
|
||||||
license = "AGPL-3.0-or-later"
|
license = "GPL-3.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix = "0.5"
|
actix = "0.7"
|
||||||
actix-web = "0.6"
|
actix-web = "0.7"
|
||||||
askama = "0.6"
|
askama = "0.6"
|
||||||
chrono = { version = "0.4", features = ["serde"] }
|
chrono = { version = "0.4", features = ["serde"] }
|
||||||
comrak = "0.2"
|
comrak = "0.2"
|
||||||
|
@ -21,7 +21,7 @@ mime_guess = "2.0.0-alpha"
|
||||||
pq-sys = "=0.4.4"
|
pq-sys = "=0.4.4"
|
||||||
r2d2 = "0.8"
|
r2d2 = "0.8"
|
||||||
rand = "0.4"
|
rand = "0.4"
|
||||||
reqwest = "0.8"
|
reqwest = "0.9"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
|
|
|
@ -1,18 +1,7 @@
|
||||||
# This Nix derivation imports the generated Carnix sources and builds
|
{ pkgs, ... }:
|
||||||
# Converse.
|
|
||||||
#
|
|
||||||
# To work around an issue in Carnix ([1] & [2]) the attributes of the
|
|
||||||
# comrak crate have been overridden with a dummy environment variable
|
|
||||||
# to simulate a Cargo-based build. This requires a manual change to
|
|
||||||
# `Cargo.nix` when updating dependencies.
|
|
||||||
#
|
|
||||||
# [1]: https://nest.pijul.com/pmeunier/carnix/discussions/2
|
|
||||||
# [2]: https://nest.pijul.com/pmeunier/carnix/discussions/3
|
|
||||||
|
|
||||||
{ pkgs ? import <nixpkgs> {}, ... }:
|
pkgs.naersk.buildPackage {
|
||||||
|
src = ./.;
|
||||||
let cargo = pkgs.callPackage ./Cargo.nix {};
|
buildInputs = with pkgs; [ openssl postgresql.lib ];
|
||||||
in {
|
nativeBuildInputs = [ pkgs.pkgconfig ];
|
||||||
# Build is not yet fixed up for the depot.
|
|
||||||
meta.ci = false;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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.
|
/// Represents the state carried by the web server actors.
|
||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
/// Address of the database actor
|
/// Address of the database actor
|
||||||
pub db: Addr<Syn, DbExecutor>,
|
pub db: Addr<DbExecutor>,
|
||||||
|
|
||||||
/// Address of the OIDC actor
|
/// Address of the OIDC actor
|
||||||
pub oidc: Addr<Syn, OidcExecutor>,
|
pub oidc: Addr<OidcExecutor>,
|
||||||
|
|
||||||
/// Address of the rendering actor
|
/// Address of the rendering actor
|
||||||
pub renderer: Addr<Syn, Renderer>,
|
pub renderer: Addr<Renderer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn forum_index(state: State<AppState>) -> ConverseResponse {
|
pub fn forum_index(state: State<AppState>) -> ConverseResponse {
|
||||||
|
@ -113,9 +113,9 @@ pub struct NewThreadForm {
|
||||||
|
|
||||||
/// This handler receives a "New thread"-form and redirects the user
|
/// This handler receives a "New thread"-form and redirects the user
|
||||||
/// to the new thread after creation.
|
/// to the new thread after creation.
|
||||||
pub fn submit_thread(state: State<AppState>,
|
pub fn submit_thread((state, input, req): (State<AppState>,
|
||||||
input: Form<NewThreadForm>,
|
Form<NewThreadForm>,
|
||||||
req: HttpRequest<AppState>) -> ConverseResponse {
|
HttpRequest<AppState>)) -> ConverseResponse {
|
||||||
// Trim whitespace out of inputs:
|
// Trim whitespace out of inputs:
|
||||||
let input = NewThreadForm {
|
let input = NewThreadForm {
|
||||||
title: input.title.trim().into(),
|
title: input.title.trim().into(),
|
||||||
|
@ -328,7 +328,7 @@ impl EmbeddedFile for App<AppState> {
|
||||||
pub struct RequireLogin;
|
pub struct RequireLogin;
|
||||||
|
|
||||||
impl <S> Middleware<S> for RequireLogin {
|
impl <S> Middleware<S> for RequireLogin {
|
||||||
fn start(&self, req: &mut HttpRequest<S>) -> actix_web::Result<Started> {
|
fn start(&self, req: &HttpRequest<S>) -> actix_web::Result<Started> {
|
||||||
let logged_in = req.identity().is_some();
|
let logged_in = req.identity().is_some();
|
||||||
let is_oidc_req = req.path().starts_with("/oidc");
|
let is_oidc_req = req.path().starts_with("/oidc");
|
||||||
|
|
||||||
|
|
|
@ -90,7 +90,7 @@ fn config_default(name: &str, default: &str) -> String {
|
||||||
env::var(name).unwrap_or(default.into())
|
env::var(name).unwrap_or(default.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_db_executor() -> Addr<Syn, DbExecutor> {
|
fn start_db_executor() -> Addr<DbExecutor> {
|
||||||
info!("Initialising database connection pool ...");
|
info!("Initialising database connection pool ...");
|
||||||
let db_url = config("DATABASE_URL");
|
let db_url = config("DATABASE_URL");
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ fn start_db_executor() -> Addr<Syn, DbExecutor> {
|
||||||
SyncArbiter::start(2, move || DbExecutor(pool.clone()))
|
SyncArbiter::start(2, move || DbExecutor(pool.clone()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn schedule_search_refresh(db: Addr<Syn, DbExecutor>) {
|
fn schedule_search_refresh(db: Addr<DbExecutor>) {
|
||||||
use tokio::prelude::*;
|
use tokio::prelude::*;
|
||||||
use tokio::timer::Interval;
|
use tokio::timer::Interval;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
@ -114,7 +114,7 @@ fn schedule_search_refresh(db: Addr<Syn, DbExecutor>) {
|
||||||
thread::spawn(|| tokio::run(task));
|
thread::spawn(|| tokio::run(task));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_oidc_executor(base_url: &str) -> Addr<Syn, OidcExecutor> {
|
fn start_oidc_executor(base_url: &str) -> Addr<OidcExecutor> {
|
||||||
info!("Initialising OIDC integration ...");
|
info!("Initialising OIDC integration ...");
|
||||||
let oidc_url = config("OIDC_DISCOVERY_URL");
|
let oidc_url = config("OIDC_DISCOVERY_URL");
|
||||||
let oidc_config = oidc::load_oidc(&oidc_url)
|
let oidc_config = oidc::load_oidc(&oidc_url)
|
||||||
|
@ -130,7 +130,7 @@ fn start_oidc_executor(base_url: &str) -> Addr<Syn, OidcExecutor> {
|
||||||
oidc.start()
|
oidc.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_renderer() -> Addr<Syn, Renderer> {
|
fn start_renderer() -> Addr<Renderer> {
|
||||||
let comrak = comrak::ComrakOptions{
|
let comrak = comrak::ComrakOptions{
|
||||||
github_pre_lang: true,
|
github_pre_lang: true,
|
||||||
ext_strikethrough: true,
|
ext_strikethrough: true,
|
||||||
|
@ -155,9 +155,9 @@ fn gen_session_key() -> [u8; 64] {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_http_server(base_url: String,
|
fn start_http_server(base_url: String,
|
||||||
db_addr: Addr<Syn, DbExecutor>,
|
db_addr: Addr<DbExecutor>,
|
||||||
oidc_addr: Addr<Syn, OidcExecutor>,
|
oidc_addr: Addr<OidcExecutor>,
|
||||||
renderer_addr: Addr<Syn, Renderer>) {
|
renderer_addr: Addr<Renderer>) {
|
||||||
info!("Initialising HTTP server ...");
|
info!("Initialising HTTP server ...");
|
||||||
let bind_host = config_default("CONVERSE_BIND_HOST", "127.0.0.1:4567");
|
let bind_host = config_default("CONVERSE_BIND_HOST", "127.0.0.1:4567");
|
||||||
let key = gen_session_key();
|
let key = gen_session_key();
|
||||||
|
@ -182,14 +182,14 @@ fn start_http_server(base_url: String,
|
||||||
.middleware(identity)
|
.middleware(identity)
|
||||||
.resource("/", |r| r.method(Method::GET).with(forum_index))
|
.resource("/", |r| r.method(Method::GET).with(forum_index))
|
||||||
.resource("/thread/new", |r| r.method(Method::GET).with(new_thread))
|
.resource("/thread/new", |r| r.method(Method::GET).with(new_thread))
|
||||||
.resource("/thread/submit", |r| r.method(Method::POST).with3(submit_thread))
|
.resource("/thread/submit", |r| r.method(Method::POST).with(submit_thread))
|
||||||
.resource("/thread/reply", |r| r.method(Method::POST).with3(reply_thread))
|
.resource("/thread/reply", |r| r.method(Method::POST).with(reply_thread))
|
||||||
.resource("/thread/{id}", |r| r.method(Method::GET).with3(forum_thread))
|
.resource("/thread/{id}", |r| r.method(Method::GET).with(forum_thread))
|
||||||
.resource("/post/{id}/edit", |r| r.method(Method::GET).with3(edit_form))
|
.resource("/post/{id}/edit", |r| r.method(Method::GET).with(edit_form))
|
||||||
.resource("/post/edit", |r| r.method(Method::POST).with3(edit_post))
|
.resource("/post/edit", |r| r.method(Method::POST).with(edit_post))
|
||||||
.resource("/search", |r| r.method(Method::GET).with2(search_forum))
|
.resource("/search", |r| r.method(Method::GET).with(search_forum))
|
||||||
.resource("/oidc/login", |r| r.method(Method::GET).with(login))
|
.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.css", include_bytes!("../static/highlight.css"))
|
||||||
.static_file("/static/highlight.js", include_bytes!("../static/highlight.js"))
|
.static_file("/static/highlight.js", include_bytes!("../static/highlight.js"))
|
||||||
.static_file("/static/styles.css", include_bytes!("../static/styles.css"));
|
.static_file("/static/styles.css", include_bytes!("../static/styles.css"));
|
||||||
|
|
|
@ -27,8 +27,6 @@ use reqwest;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use url_serde;
|
use url_serde;
|
||||||
use errors::*;
|
use errors::*;
|
||||||
use reqwest::header::Authorization;
|
|
||||||
use hyper::header::Bearer;
|
|
||||||
|
|
||||||
/// This structure represents the contents of an OIDC discovery
|
/// This structure represents the contents of an OIDC discovery
|
||||||
/// document.
|
/// document.
|
||||||
|
@ -130,7 +128,7 @@ impl Handler<RetrieveToken> for OidcExecutor {
|
||||||
let token: TokenResponse = response.json()?;
|
let token: TokenResponse = response.json()?;
|
||||||
|
|
||||||
let user: Userinfo = client.get(&self.oidc_config.userinfo_endpoint)
|
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()?
|
.send()?
|
||||||
.json()?;
|
.json()?;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue