Skip to content

Commit 4db329c

Browse files
committed
Shave an enormous yak
1 parent 7bd412c commit 4db329c

12 files changed

Lines changed: 448 additions & 1377 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,18 @@ members = [
4949
[workspace.dependencies]
5050
Inflector = "*"
5151
askama = {version = "0.12.1", features = ["with-axum"]}
52-
askama_axum = "0.3.0"
53-
async-graphql = {version = "~6.0.10", features = ["tracing", "dataloader", "chrono"]}
54-
async-graphql-axum = "~6.0.10"
55-
async-graphql-value = {version = "~6.0.10"}
52+
askama_axum = "0.4.0"
53+
async-graphql = {git = "https://github.com/async-graphql/async-graphql.git", features = ["tracing", "dataloader", "chrono"]}
54+
async-graphql-axum = {git = "https://github.com/async-graphql/async-graphql.git"}
55+
async-graphql-value = {git = "https://github.com/async-graphql/async-graphql.git"}
5656
async-trait = "*"
57-
aws-config = "0.57.1"
58-
aws-sdk-sesv2 = "0.35.0"
57+
aws-config = "1.1.1"
58+
aws-sdk-sesv2 = "1.7.0"
59+
aws-smithy-runtime-api = "*"
5960
aws-smithy-types = "*"
60-
axum = {version = "~0.6.20", features = ["multipart", "macros", "headers"]}
61-
axum-extra = {version = "~0.8.0", features = ["cookie"]}
62-
axum-server = {version = "0.5.1", features = ["tls-rustls"]}
61+
axum = {version = "~0.7.2", features = ["multipart", "macros"]}
62+
axum-extra = {version = "~0.9.0", features = ["cookie"]}
63+
axum-server = {git = "https://github.com/programatik29/axum-server.git", features = ["tls-rustls"]}
6364
base64 = "0.21.5"
6465
bcrypt = "0.15.0"
6566
bumpalo = "3.14.0"
@@ -72,8 +73,8 @@ dyn-clone = "1.0.16"
7273
futures = "0.3.29"
7374
hex = "0.4.3"
7475
html-escape = "0.2.13"
75-
http = "0.2.9"
76-
hyper = "0.14.27"
76+
http = "1.0.0"
77+
hyper = "1.0.1"
7778
i18n-embed = {version = "0.14.1", features = ["fluent-system"]}
7879
i18n-embed-fl = "0.7"
7980
ics = "0.5.8"
@@ -131,8 +132,8 @@ syn = "2.0.39"
131132
time = "0.3.30"
132133
tokio = {version = "~1.34.0", features = ["rt-multi-thread", "macros", "signal", "tracing"]}
133134
tower = {version = "0.4.13", features = ["limit", "make"]}
134-
tower-http = {version = "0.4.4", features = ["catch-panic", "compression-br", "compression-deflate", "compression-gzip", "trace"]}
135-
tower-sessions = "~0.4.1"
135+
tower-http = {version = "0.5.0", features = ["catch-panic", "compression-br", "compression-deflate", "compression-gzip", "trace"]}
136+
tower-sessions = "~0.7.0"
136137
tracing = "0.1.40"
137138
tuple-conv = "~1.0.1"
138139
twilio = "1.0.3"
@@ -146,6 +147,7 @@ tokio-console = ["dep:console-subscriber", "tokio/full", "tokio/tracing"]
146147

147148
[dependencies]
148149
async-graphql = {workspace = true}
150+
async-graphql-axum = {workspace = true}
149151
axum = {workspace = true}
150152
chrono = {workspace = true}
151153
chrono-tz = {workspace = true}

crates/intercode_email/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ version = "0.1.0"
99
async-graphql = {workspace = true}
1010
aws-config = {workspace = true}
1111
aws-sdk-sesv2 = {workspace = true}
12+
aws-smithy-runtime-api = {workspace = true}
1213
aws-smithy-types = {workspace = true}
1314
http = {workspace = true}
1415
intercode_entities = {workspace = true}

crates/intercode_email/src/send_email.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
use aws_config::SdkConfig;
1+
use aws_config::{BehaviorVersion, SdkConfig};
22
use aws_sdk_sesv2::{
33
error::SdkError,
44
operation::send_email::{SendEmailError, SendEmailOutput},
55
types::{Body, Content, Destination, EmailContent, Message},
66
};
7-
use aws_smithy_types::body::SdkBody;
8-
use http::Response;
7+
use aws_smithy_runtime_api::client::orchestrator::HttpResponse;
98
use tokio::sync::OnceCell;
109

1110
static AWS_CONFIG: OnceCell<SdkConfig> = OnceCell::const_new();
1211
static SES_CLIENT: OnceCell<aws_sdk_sesv2::Client> = OnceCell::const_new();
1312

1413
async fn get_aws_config() -> &'static SdkConfig {
15-
AWS_CONFIG.get_or_init(aws_config::load_from_env).await
14+
AWS_CONFIG
15+
.get_or_init(|| aws_config::load_defaults(BehaviorVersion::latest()))
16+
.await
1617
}
1718

1819
async fn get_ses_client() -> &'static aws_sdk_sesv2::Client {
@@ -30,7 +31,7 @@ pub async fn send_email(
3031
subject: &str,
3132
body_html: Option<&str>,
3233
body_text: Option<&str>,
33-
) -> Result<SendEmailOutput, SdkError<SendEmailError, Response<SdkBody>>> {
34+
) -> Result<SendEmailOutput, SdkError<SendEmailError, HttpResponse>> {
3435
let client = get_ses_client().await;
3536
let mut body = Body::builder();
3637
if let Some(body_html) = body_html {

crates/intercode_graphql/src/actions/graphql.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@ use async_graphql::{
66
EmptySubscription, Schema,
77
};
88
use async_graphql_axum::{GraphQLBatchRequest, GraphQLResponse};
9-
use axum::{
10-
extract::State,
11-
response::{self, IntoResponse},
12-
};
9+
use axum::response::{self, IntoResponse};
1310
use intercode_graphql_core::liquid_renderer::{LiquidRenderer, LiquidRendererFromRequest};
1411
use intercode_graphql_loaders::LoaderManager;
1512
use intercode_server::AuthorizationInfoAndQueryDataFromRequest;
1613

1714
pub type IntercodeSchema = Schema<api::QueryRoot, api::MutationRoot, EmptySubscription>;
1815

19-
pub async fn graphql_handler(
20-
State(schema): State<IntercodeSchema>,
16+
pub async fn graphql_handler_inner(
17+
schema: IntercodeSchema,
2118
AuthorizationInfoAndQueryDataFromRequest(authorization_info, query_data): AuthorizationInfoAndQueryDataFromRequest,
2219
LiquidRendererFromRequest(liquid_renderer): LiquidRendererFromRequest,
2320
req: GraphQLBatchRequest,

crates/intercode_server/src/app.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use axum::extract::FromRef;
77
use axum::BoxError;
88
use axum::{middleware::from_fn_with_state, routing::IntoMakeService, Extension, Router};
99
use http::StatusCode;
10-
use hyper::body::HttpBody;
1110
use sea_orm::DatabaseConnection;
1211
use tower::limit::ConcurrencyLimitLayer;
1312
use tower::ServiceBuilder;
@@ -21,12 +20,11 @@ use crate::{
2120
request_bound_transaction::request_bound_transaction,
2221
};
2322

24-
pub fn build_app<S, F, B>(state: S, build_routes: F) -> Result<IntoMakeService<Router<(), B>>>
23+
pub fn build_app<S, F>(state: S, build_routes: F) -> Result<IntoMakeService<Router>>
2524
where
2625
S: Clone + Send + Sync + 'static,
2726
Arc<DatabaseConnection>: FromRef<S>,
28-
F: FnOnce(Router<S, B>) -> Router<S, B>,
29-
B: HttpBody + Send + Sync + Unpin + 'static,
27+
F: FnOnce(Router<S>) -> Router<S>,
3028
{
3129
let secret_bytes = hex::decode(env::var("SECRET_KEY_BASE")?)?;
3230
let secret: [u8; 64] = secret_bytes[0..64].try_into().unwrap_or_else(|_| {
@@ -39,7 +37,7 @@ where
3937
let csrf_config = CsrfConfig::new(&secret);
4038
let session_layer = SessionWithDbStoreFromTxLayer::new();
4139

42-
let app: Router<S, B> = Router::new();
40+
let app: Router<S> = Router::new();
4341
let app = build_routes(app);
4442

4543
let session_service = ServiceBuilder::new()

crates/intercode_server/src/csrf.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use async_trait::async_trait;
55
use axum::{
6-
extract::FromRequestParts,
6+
extract::{FromRequestParts, Request},
77
http::{self, StatusCode},
88
middleware::Next,
99
response::{IntoResponse, IntoResponseParts, Response, ResponseParts},
@@ -14,7 +14,7 @@ use axum_extra::extract::{
1414
};
1515
use base64::Engine;
1616
use csrf::{ChaCha20Poly1305CsrfProtection, CsrfCookie, CsrfProtection, CsrfToken};
17-
use http::{request::Parts, Request};
17+
use http::request::Parts;
1818
use std::{
1919
borrow::Cow,
2020
fmt::{Debug, Display},
@@ -185,7 +185,7 @@ impl CsrfData {
185185
let lifespan = OffsetDateTime::now_utc() + self.config.lifespan;
186186

187187
let mut cookie_builder =
188-
Cookie::build(self.config.cookie_name.clone(), self.cookie.b64_string())
188+
Cookie::build((self.config.cookie_name.clone(), self.cookie.b64_string()))
189189
.path(self.config.cookie_path.clone())
190190
.secure(self.config.cookie_secure)
191191
.http_only(self.config.cookie_http_only)
@@ -197,15 +197,15 @@ impl CsrfData {
197197
.same_site(self.config.cookie_same_site);
198198
}
199199

200-
cookie_builder.finish()
200+
cookie_builder.build()
201201
}
202202
}
203203

204-
pub async fn csrf_middleware<B: Send>(
204+
pub async fn csrf_middleware(
205205
token: CsrfData,
206206
jar: CookieJar,
207-
req: Request<B>,
208-
next: Next<B>,
207+
req: Request,
208+
next: Next,
209209
) -> Result<Response, (StatusCode, String)> {
210210
let future = next.run(req);
211211
let response = future.await;

crates/intercode_server/src/form_or_multipart.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
use std::error::Error;
2-
31
use axum::{
42
async_trait,
5-
body::{Bytes, HttpBody},
63
extract::{FromRequest, Multipart},
74
Form,
85
};
9-
use http::{Request, StatusCode};
6+
use http::StatusCode;
107
use once_cell::sync::Lazy;
118
use regex::bytes::Regex;
129

@@ -18,16 +15,13 @@ pub enum FormOrMultipart<T> {
1815
}
1916

2017
#[async_trait]
21-
impl<T, S: Send + Sync, B: Send + Sync + 'static> FromRequest<S, B> for FormOrMultipart<T>
18+
impl<T, S: Send + Sync> FromRequest<S> for FormOrMultipart<T>
2219
where
23-
Form<T>: FromRequest<S, B>,
24-
B: HttpBody,
25-
Bytes: From<<B as HttpBody>::Data>,
26-
<B as HttpBody>::Error: Error + Send + Sync,
20+
Form<T>: FromRequest<S>,
2721
{
2822
type Rejection = StatusCode;
2923

30-
async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
24+
async fn from_request(req: axum::extract::Request, state: &S) -> Result<Self, Self::Rejection> {
3125
if let Some(content_type) = req.headers().get("content-type") {
3226
let content_type = content_type
3327
.to_str()

crates/intercode_server/src/request_bound_transaction.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use std::sync::Arc;
22

33
use axum::{
4-
extract::State,
4+
extract::{Request, State},
55
middleware::Next,
66
response::{IntoResponse, Response},
77
};
8-
use http::{Request, StatusCode};
8+
use http::StatusCode;
99
use sea_orm::{DatabaseConnection, DbErr, TransactionTrait};
1010
use seawater::ConnectionWrapper;
1111

12-
async fn run_request_bound_transaction<B>(
13-
mut request: Request<B>,
14-
next: Next<B>,
12+
async fn run_request_bound_transaction(
13+
mut request: Request,
14+
next: Next,
1515
db: &DatabaseConnection,
1616
) -> Result<Response, DbErr> {
1717
let extensions_mut = request.extensions_mut();
@@ -38,10 +38,10 @@ async fn run_request_bound_transaction<B>(
3838
Ok(response)
3939
}
4040

41-
pub async fn request_bound_transaction<B>(
41+
pub async fn request_bound_transaction(
4242
State(db_conn): State<Arc<DatabaseConnection>>,
43-
request: Request<B>,
44-
next: Next<B>,
43+
request: Request,
44+
next: Next,
4545
) -> Response {
4646
run_request_bound_transaction(request, next, &db_conn)
4747
.await

crates/intercode_server/src/server.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ use std::net::{IpAddr, Ipv4Addr, SocketAddr};
33
use std::time::Duration;
44

55
use async_graphql::Result;
6-
use axum_server::service::MakeServiceRef;
6+
use axum_server::service::MakeService;
77
use axum_server::tls_rustls::{RustlsAcceptor, RustlsConfig};
88
use axum_server::{Handle, Server};
99
use http::Request;
10-
use hyper::server::conn::AddrStream;
10+
use hyper::body::Incoming;
1111
use opentelemetry::global::shutdown_tracer_provider;
1212
use tokio::time::sleep;
1313
use tracing::log::*;
@@ -70,7 +70,7 @@ async fn graceful_shutdown(handle: Handle) {
7070
}
7171
}
7272

73-
pub async fn serve<M: MakeServiceRef<AddrStream, Request<hyper::Body>>>(app: M) -> Result<()> {
73+
pub async fn serve<M: MakeService<SocketAddr, Request<Incoming>>>(app: M) -> Result<()> {
7474
let addr = SocketAddr::new(
7575
IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
7676
env::var("PORT")

0 commit comments

Comments
 (0)