Skip to content

Commit 072fa47

Browse files
committed
NTEX migration start
1 parent 5b00ac1 commit 072fa47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

111 files changed

+3694
-3895
lines changed

Cargo.lock

Lines changed: 386 additions & 528 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/labrinth/Cargo.toml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ name = "labrinth"
1111
path = "src/main.rs"
1212

1313
[dependencies]
14-
actix-web = "4.4.1"
15-
actix-rt = "2.9.0"
16-
actix-multipart = "0.6.1"
17-
actix-cors = "0.7.0"
18-
actix-ws = "0.3.0"
19-
actix-files = "0.6.5"
20-
actix-web-prom = { version = "0.8.0", features = ["process"] }
21-
governor = "0.6.3"
14+
ntex = { version = "2.0", features = ["tokio", "compress"] }
15+
# actix-rt = "2.9.0"
16+
ntex-multipart = "2.0.0"
17+
ntex-cors = "2.0.0"
18+
# actix-ws = "0.3.0"
19+
ntex-files = "2.0.0"
20+
# actix-web-prom = { version = "0.8.0", features = ["process"] }
21+
governor = "0.8.0"
2222

2323
tokio = { version = "1.35.1", features = ["sync"] }
2424
tokio-stream = "0.1.14"
@@ -97,15 +97,15 @@ maxminddb = "0.24.0"
9797
flate2 = "1.0.25"
9898
tar = "0.4.38"
9999

100-
sentry = { version = "0.34.0", default-features = false, features = [
101-
"backtrace",
102-
"contexts",
103-
"debug-images",
104-
"panic",
105-
"rustls",
106-
"reqwest",
107-
] }
108-
sentry-actix = "0.34.0"
100+
#sentry = { version = "0.34.0", default-features = false, features = [
101+
# "backtrace",
102+
# "contexts",
103+
# "debug-images",
104+
# "panic",
105+
# "rustls",
106+
# "reqwest",
107+
#] }
108+
#sentry-actix = "0.34.0"
109109

110110
image = "0.24.6"
111111
color-thief = "0.2.2"

apps/labrinth/src/auth/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ pub use validate::{check_is_moderator_from_headers, get_user_from_headers};
1515

1616
use crate::file_hosting::FileHostingError;
1717
use crate::models::error::ApiError;
18-
use actix_web::http::StatusCode;
19-
use actix_web::HttpResponse;
18+
use ntex::http::StatusCode;
19+
use ntex::web::{HttpRequest, HttpResponse};
2020
use thiserror::Error;
2121

2222
#[derive(Error, Debug)]
@@ -51,7 +51,7 @@ pub enum AuthenticationError {
5151
Url,
5252
}
5353

54-
impl actix_web::ResponseError for AuthenticationError {
54+
impl ntex::web::WebResponseError for AuthenticationError {
5555
fn status_code(&self) -> StatusCode {
5656
match self {
5757
AuthenticationError::Env(..) => StatusCode::INTERNAL_SERVER_ERROR,
@@ -77,8 +77,8 @@ impl actix_web::ResponseError for AuthenticationError {
7777
}
7878
}
7979

80-
fn error_response(&self) -> HttpResponse {
81-
HttpResponse::build(self.status_code()).json(ApiError {
80+
fn error_response(&self, _req: &HttpRequest) -> HttpResponse {
81+
HttpResponse::build(self.status_code()).json(&ApiError {
8282
error: self.error_name(),
8383
description: self.to_string(),
8484
})

apps/labrinth/src/auth/oauth/errors.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use super::ValidatedRedirectUri;
22
use crate::auth::AuthenticationError;
33
use crate::models::error::ApiError;
44
use crate::models::ids::DecodingError;
5-
use actix_web::http::{header::LOCATION, StatusCode};
6-
use actix_web::HttpResponse;
5+
use ntex::http::{header::LOCATION, StatusCode};
6+
use ntex::web::{HttpRequest, HttpResponse};
77

88
#[derive(thiserror::Error, Debug)]
99
#[error("{}", .error_type)]
@@ -55,7 +55,7 @@ impl OAuthError {
5555
}
5656
}
5757

58-
impl actix_web::ResponseError for OAuthError {
58+
impl ntex::web::WebResponseError for OAuthError {
5959
fn status_code(&self) -> StatusCode {
6060
match self.error_type {
6161
OAuthErrorType::AuthenticationError(_)
@@ -83,7 +83,7 @@ impl actix_web::ResponseError for OAuthError {
8383
}
8484
}
8585

86-
fn error_response(&self) -> HttpResponse {
86+
fn error_response(&self, _req: &HttpRequest) -> HttpResponse {
8787
if let Some(ValidatedRedirectUri(mut redirect_uri)) =
8888
self.valid_redirect_uri.clone()
8989
{
@@ -99,10 +99,10 @@ impl actix_web::ResponseError for OAuthError {
9999
}
100100

101101
HttpResponse::Ok()
102-
.append_header((LOCATION, redirect_uri.clone()))
102+
.header(LOCATION, redirect_uri.clone())
103103
.body(redirect_uri)
104104
} else {
105-
HttpResponse::build(self.status_code()).json(ApiError {
105+
HttpResponse::build(self.status_code()).json(&ApiError {
106106
error: &self.error_type.error_name(),
107107
description: self.error_type.to_string(),
108108
})

apps/labrinth/src/auth/oauth/mod.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ use crate::models;
1414
use crate::models::ids::OAuthClientId;
1515
use crate::models::pats::Scopes;
1616
use crate::queue::session::AuthQueue;
17-
use actix_web::http::header::LOCATION;
18-
use actix_web::web::{Data, Query, ServiceConfig};
19-
use actix_web::{get, post, web, HttpRequest, HttpResponse};
2017
use chrono::Duration;
18+
use ntex::http::header::LOCATION;
19+
use ntex::http::header::{CACHE_CONTROL, PRAGMA};
20+
use ntex::web::ServiceConfig;
21+
use ntex::web::{self, get, post, HttpRequest, HttpResponse};
2122
use rand::distributions::Alphanumeric;
2223
use rand::{Rng, SeedableRng};
2324
use rand_chacha::ChaCha20Rng;
24-
use reqwest::header::{CACHE_CONTROL, PRAGMA};
2525
use serde::{Deserialize, Serialize};
2626
use sqlx::postgres::PgPool;
2727

@@ -59,14 +59,14 @@ pub struct OAuthClientAccessRequest {
5959
#[get("authorize")]
6060
pub async fn init_oauth(
6161
req: HttpRequest,
62-
Query(oauth_info): Query<OAuthInit>,
63-
pool: Data<PgPool>,
64-
redis: Data<RedisPool>,
65-
session_queue: Data<AuthQueue>,
62+
web::types::Query(oauth_info): web::types::Query<OAuthInit>,
63+
pool: web::types::State<PgPool>,
64+
redis: web::types::State<RedisPool>,
65+
session_queue: web::types::State<AuthQueue>,
6666
) -> Result<HttpResponse, OAuthError> {
6767
let user = get_user_from_headers(
6868
&req,
69-
&**pool,
69+
&*pool,
7070
&redis,
7171
&session_queue,
7272
Some(&[Scopes::USER_AUTH_WRITE]),
@@ -75,7 +75,7 @@ pub async fn init_oauth(
7575
.1;
7676

7777
let client_id = oauth_info.client_id.into();
78-
let client = DBOAuthClient::get(client_id, &**pool).await?;
78+
let client = DBOAuthClient::get(client_id, &*pool).await?;
7979

8080
if let Some(client) = client {
8181
let redirect_uri = ValidatedRedirectUri::validate(
@@ -107,7 +107,7 @@ pub async fn init_oauth(
107107
}
108108

109109
let existing_authorization =
110-
OAuthClientAuthorization::get(client.id, user.id.into(), &**pool)
110+
OAuthClientAuthorization::get(client.id, user.id.into(), &*pool)
111111
.await
112112
.map_err(|e| {
113113
OAuthError::redirect(e, &oauth_info.state, &redirect_uri)
@@ -154,7 +154,7 @@ pub async fn init_oauth(
154154
flow_id,
155155
requested_scopes,
156156
};
157-
Ok(HttpResponse::Ok().json(access_request))
157+
Ok(HttpResponse::Ok().json(&access_request))
158158
}
159159
}
160160
} else {
@@ -172,10 +172,10 @@ pub struct RespondToOAuthClientScopes {
172172
#[post("accept")]
173173
pub async fn accept_client_scopes(
174174
req: HttpRequest,
175-
accept_body: web::Json<RespondToOAuthClientScopes>,
176-
pool: Data<PgPool>,
177-
redis: Data<RedisPool>,
178-
session_queue: Data<AuthQueue>,
175+
accept_body: web::types::Json<RespondToOAuthClientScopes>,
176+
pool: web::types::State<PgPool>,
177+
redis: web::types::State<RedisPool>,
178+
session_queue: web::types::State<AuthQueue>,
179179
) -> Result<HttpResponse, OAuthError> {
180180
accept_or_reject_client_scopes(
181181
true,
@@ -191,10 +191,10 @@ pub async fn accept_client_scopes(
191191
#[post("reject")]
192192
pub async fn reject_client_scopes(
193193
req: HttpRequest,
194-
body: web::Json<RespondToOAuthClientScopes>,
195-
pool: Data<PgPool>,
196-
redis: Data<RedisPool>,
197-
session_queue: Data<AuthQueue>,
194+
body: web::types::Json<RespondToOAuthClientScopes>,
195+
pool: web::types::State<PgPool>,
196+
redis: web::types::State<RedisPool>,
197+
session_queue: web::types::State<AuthQueue>,
198198
) -> Result<HttpResponse, OAuthError> {
199199
accept_or_reject_client_scopes(false, req, body, pool, redis, session_queue)
200200
.await
@@ -221,12 +221,12 @@ pub struct TokenResponse {
221221
/// Per IETF RFC6749 Section 4.1.3 (https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.3)
222222
pub async fn request_token(
223223
req: HttpRequest,
224-
req_params: web::Form<TokenRequest>,
225-
pool: Data<PgPool>,
226-
redis: Data<RedisPool>,
224+
req_params: web::types::Form<TokenRequest>,
225+
pool: web::types::State<PgPool>,
226+
redis: web::types::State<RedisPool>,
227227
) -> Result<HttpResponse, OAuthError> {
228228
let req_client_id = req_params.client_id;
229-
let client = DBOAuthClient::get(req_client_id.into(), &**pool).await?;
229+
let client = DBOAuthClient::get(req_client_id.into(), &*pool).await?;
230230
if let Some(client) = client {
231231
authenticate_client_token_request(&req, &client)?;
232232

@@ -294,9 +294,9 @@ pub async fn request_token(
294294

295295
// IETF RFC6749 Section 5.1 (https://datatracker.ietf.org/doc/html/rfc6749#section-5.1)
296296
Ok(HttpResponse::Ok()
297-
.append_header((CACHE_CONTROL, "no-store"))
298-
.append_header((PRAGMA, "no-cache"))
299-
.json(TokenResponse {
297+
.header(CACHE_CONTROL, "no-store")
298+
.header(PRAGMA, "no-cache")
299+
.json(&TokenResponse {
300300
access_token: token,
301301
token_type: "Bearer".to_string(),
302302
expires_in: time_until_expiration.num_seconds(),
@@ -314,14 +314,14 @@ pub async fn request_token(
314314
pub async fn accept_or_reject_client_scopes(
315315
accept: bool,
316316
req: HttpRequest,
317-
body: web::Json<RespondToOAuthClientScopes>,
318-
pool: Data<PgPool>,
319-
redis: Data<RedisPool>,
320-
session_queue: Data<AuthQueue>,
317+
body: web::types::Json<RespondToOAuthClientScopes>,
318+
pool: web::types::State<PgPool>,
319+
redis: web::types::State<RedisPool>,
320+
session_queue: web::types::State<AuthQueue>,
321321
) -> Result<HttpResponse, OAuthError> {
322322
let current_user = get_user_from_headers(
323323
&req,
324-
&**pool,
324+
&*pool,
325325
&redis,
326326
&session_queue,
327327
Some(&[Scopes::SESSION_ACCESS]),
@@ -449,7 +449,7 @@ async fn init_oauth_code_flow(
449449

450450
// IETF RFC 6749 Section 4.1.2 (https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2)
451451
Ok(HttpResponse::Ok()
452-
.append_header((LOCATION, redirect_uri.clone()))
452+
.header(LOCATION, redirect_uri.clone())
453453
.body(redirect_uri))
454454
}
455455

apps/labrinth/src/auth/templates/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::auth::AuthenticationError;
2-
use actix_web::http::StatusCode;
3-
use actix_web::{HttpResponse, ResponseError};
2+
use ntex::http::StatusCode;
3+
use ntex::web::{HttpRequest, HttpResponse, WebResponseError};
44
use std::fmt::{Debug, Display, Formatter};
55

66
pub struct Success<'a> {
@@ -13,7 +13,7 @@ impl Success<'_> {
1313
let html = include_str!("success.html");
1414

1515
HttpResponse::Ok()
16-
.append_header(("Content-Type", "text/html; charset=utf-8"))
16+
.header("Content-Type", "text/html; charset=utf-8")
1717
.body(
1818
html.replace("{{ icon }}", self.icon)
1919
.replace("{{ name }}", self.name),
@@ -41,17 +41,17 @@ impl Display for ErrorPage {
4141
impl ErrorPage {
4242
pub fn render(&self) -> HttpResponse {
4343
HttpResponse::Ok()
44-
.append_header(("Content-Type", "text/html; charset=utf-8"))
44+
.header("Content-Type", "text/html; charset=utf-8")
4545
.body(self.to_string())
4646
}
4747
}
4848

49-
impl actix_web::ResponseError for ErrorPage {
49+
impl WebResponseError for ErrorPage {
5050
fn status_code(&self) -> StatusCode {
5151
self.code
5252
}
5353

54-
fn error_response(&self) -> HttpResponse {
54+
fn error_response(&self, _req: &HttpRequest) -> HttpResponse {
5555
self.render()
5656
}
5757
}

apps/labrinth/src/auth/validate.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ use crate::models::pats::Scopes;
66
use crate::models::users::User;
77
use crate::queue::session::AuthQueue;
88
use crate::routes::internal::session::get_session_metadata;
9-
use actix_web::http::header::{HeaderValue, AUTHORIZATION};
10-
use actix_web::HttpRequest;
119
use chrono::Utc;
10+
use ntex::http::header::{HeaderValue, AUTHORIZATION};
11+
use ntex::web::HttpRequest;
1212

1313
pub async fn get_user_from_headers<'a, E>(
1414
req: &HttpRequest,
@@ -18,7 +18,7 @@ pub async fn get_user_from_headers<'a, E>(
1818
required_scopes: Option<&[Scopes]>,
1919
) -> Result<(Scopes, User), AuthenticationError>
2020
where
21-
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
21+
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy + Send + Sync,
2222
{
2323
// Fetch DB user record and minos user from headers
2424
let (scopes, db_user) = get_user_record_from_bearer_token(
@@ -52,7 +52,7 @@ pub async fn get_user_record_from_bearer_token<'a, 'b, E>(
5252
session_queue: &AuthQueue,
5353
) -> Result<Option<(Scopes, user_item::User)>, AuthenticationError>
5454
where
55-
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
55+
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy + Send + Sync,
5656
{
5757
let token = if let Some(token) = token {
5858
token
@@ -174,7 +174,7 @@ pub async fn check_is_moderator_from_headers<'a, 'b, E>(
174174
required_scopes: Option<&[Scopes]>,
175175
) -> Result<User, AuthenticationError>
176176
where
177-
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy,
177+
E: sqlx::Executor<'a, Database = sqlx::Postgres> + Copy + Send + Sync,
178178
{
179179
let user = get_user_from_headers(
180180
req,

0 commit comments

Comments
 (0)