Skip to content

Commit 21b58ef

Browse files
Update axum (#2713)
# Description of Changes ~~Axum now has what we need out of it for a websocket wrapper, so we no longer need to duplicate `util/flat_csv.rs` and `util/websocket.rs`, meaning we have less code to maintain.~~ Nevermind, we know send raw frames, which axum's wrapper does not support. Makes this PR simpler. # Expected complexity level and risk 2 - upgrading a dependency is a risk, but looking through the [changelog](https://github.com/tokio-rs/axum/blob/main/axum/CHANGELOG.md#080) there isn't anything that should affect us. # Testing <!-- Describe any testing you've done, and any testing you'd like your reviewers to do, so that you're confident that all the changes work as expected! --> - [x] tests pass <!-- maybe a test you want to do --> - [ ] <!-- maybe a test you want a reviewer to do, so they can check it off when they're satisfied. --> Co-authored-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
1 parent ddba47f commit 21b58ef

8 files changed

Lines changed: 23 additions & 47 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ arrayvec = "0.7.2"
156156
async-channel = "2.5"
157157
async-stream = "0.3.6"
158158
async-trait = "0.1.68"
159-
axum = { version = "0.7", features = ["tracing"] }
160-
axum-extra = { version = "0.9", features = ["typed-header"] }
159+
axum = { version = "0.8.4", features = ["tracing"] }
160+
axum-extra = { version = "0.10", features = ["typed-header"] }
161161
backtrace = "0.3.66"
162162
base64 = "0.21.2"
163163
bigdecimal = "0.4.7"

crates/client-api/src/auth.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ pub struct SpacetimeAuthHeader {
385385
auth: Option<SpacetimeAuth>,
386386
}
387387

388-
#[async_trait::async_trait]
389388
impl<S: NodeDelegate + Send + Sync> axum::extract::FromRequestParts<S> for SpacetimeAuthHeader {
390389
type Rejection = AuthorizationRejection;
391390
async fn from_request_parts(parts: &mut request::Parts, state: &S) -> Result<Self, Self::Rejection> {
@@ -461,7 +460,6 @@ impl SpacetimeAuthHeader {
461460

462461
pub struct SpacetimeAuthRequired(pub SpacetimeAuth);
463462

464-
#[async_trait::async_trait]
465463
impl<S: NodeDelegate + Send + Sync> axum::extract::FromRequestParts<S> for SpacetimeAuthRequired {
466464
type Rejection = AuthorizationRejection;
467465
async fn from_request_parts(parts: &mut request::Parts, state: &S) -> Result<Self, Self::Rejection> {

crates/client-api/src/routes/database.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ pub async fn reset<S: NodeDelegate + ControlStateDelegate + Authorization>(
643643
host_type,
644644
}): Query<ResetDatabaseQueryParams>,
645645
Extension(auth): Extension<SpacetimeAuth>,
646-
program_bytes: Option<Bytes>,
646+
program_bytes: Bytes,
647647
) -> axum::response::Result<axum::Json<PublishResult>> {
648648
let database_identity = name_or_identity.resolve(&ctx).await?;
649649
let database = worker_ctx_find_database(&ctx, &database_identity)
@@ -658,7 +658,7 @@ pub async fn reset<S: NodeDelegate + ControlStateDelegate + Authorization>(
658658
&auth.claims.identity,
659659
DatabaseResetDef {
660660
database_identity,
661-
program_bytes,
661+
program_bytes: Some(program_bytes),
662662
num_replicas,
663663
host_type: Some(host_type),
664664
},
@@ -743,7 +743,7 @@ pub async fn publish<S: NodeDelegate + ControlStateDelegate + Authorization>(
743743
host_type,
744744
}),
745745
Extension(auth),
746-
Some(program_bytes),
746+
program_bytes,
747747
)
748748
.await;
749749
}
@@ -1271,7 +1271,7 @@ where
12711271
.route("/names", self.names_put)
12721272
.route("/identity", self.identity_get)
12731273
.route("/subscribe", self.subscribe_get)
1274-
.route("/call/:reducer", self.call_reducer_procedure_post)
1274+
.route("/call/{reducer}", self.call_reducer_procedure_post)
12751275
.route("/schema", self.schema_get)
12761276
.route("/logs", self.logs_get)
12771277
.route("/sql", self.sql_post)
@@ -1281,7 +1281,7 @@ where
12811281

12821282
axum::Router::new()
12831283
.route("/", self.root_post)
1284-
.nest("/:name_or_identity", db_router)
1284+
.nest("/{name_or_identity}", db_router)
12851285
.route_layer(axum::middleware::from_fn_with_state(ctx, anon_auth_middleware::<S>))
12861286
}
12871287
}

crates/client-api/src/routes/energy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ where
131131
{
132132
use axum::routing::get;
133133
axum::Router::new().route(
134-
"/:identity",
134+
"/{identity}",
135135
get(get_energy_balance::<S>)
136136
.put(set_energy_balance::<S>)
137137
.post(add_energy::<S>),

crates/client-api/src/routes/identity.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ where
175175
.route("/", self.create_post)
176176
.route("/public-key", self.public_key_get)
177177
.route("/websocket-token", self.websocket_token_post)
178-
.route("/:identity/verify", self.verify_get)
179-
.route("/:identity/databases", self.databases_get)
178+
.route("/{identity}/verify", self.verify_get)
179+
.route("/{identity}/databases", self.databases_get)
180180
}
181181
}

crates/client-api/src/util.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use crate::{log_and_500, ControlStateReadAccess};
2121

2222
pub struct ByteStringBody(pub ByteString);
2323

24-
#[async_trait::async_trait]
2524
impl<S: Send + Sync> FromRequest<S> for ByteStringBody {
2625
type Rejection = axum::response::Response;
2726

@@ -165,8 +164,7 @@ impl fmt::Display for NameOrIdentity {
165164

166165
pub struct EmptyBody;
167166

168-
#[async_trait::async_trait]
169-
impl<S> FromRequest<S> for EmptyBody {
167+
impl<S: Sync> FromRequest<S> for EmptyBody {
170168
type Rejection = axum::response::Response;
171169
async fn from_request(req: Request, _state: &S) -> Result<Self, Self::Rejection> {
172170
let body = req.into_body();

crates/client-api/src/util/websocket.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ pub enum WebSocketUpgradeRejection {
7878
KeyMissing,
7979
}
8080

81-
#[async_trait::async_trait]
82-
impl<S> FromRequestParts<S> for WebSocketUpgrade {
81+
impl<S: Sync> FromRequestParts<S> for WebSocketUpgrade {
8382
type Rejection = WebSocketUpgradeRejection;
8483
async fn from_request_parts(parts: &mut http::request::Parts, _state: &S) -> Result<Self, Self::Rejection> {
8584
use WebSocketUpgradeRejection::*;

0 commit comments

Comments
 (0)