From bd843541e5d07b2856f671bfd2052d9b7e3ec954 Mon Sep 17 00:00:00 2001 From: Jake Meyer Date: Sat, 12 Oct 2024 16:59:06 -0700 Subject: [PATCH] bump deps and upgrade to rust v1.81 --- .github/workflows/ci.yml | 19 ++++--------------- Cargo.toml | 41 +++++++++++++++++++++------------------- Dockerfile | 2 +- src/api/mod.rs | 7 ++----- src/api/ratelimit.rs | 12 ++++++++---- 5 files changed, 37 insertions(+), 44 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb03f19..a60b618 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,6 @@ name: CI on: [push, pull_request] env: - IMAGE_NAME: sandbox CARGO_TERM_COLOR: always jobs: @@ -15,29 +14,19 @@ jobs: uses: actions/checkout@v4 - name: Install stable toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true + uses: dtolnay/rust-toolchain@stable - name: Caching uses: Swatinem/rust-cache@v2 - name: Run rustfmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check + run: cargo fmt -- --check - name: Run clippy - uses: actions-rs/cargo@v1 - with: - command: clippy + run: cargo clippy --all-targets --all-features - name: Run tests - uses: actions-rs/cargo@v1 - with: - command: test + run: cargo test --all-targets --all-features push-image: name: Push Image diff --git a/Cargo.toml b/Cargo.toml index e1dcb6a..639099f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,25 +4,28 @@ version = "0.1.0" edition = "2021" [dependencies] -anyhow = "1.0.75" -async-stripe = { version = "0.25.2", default-features = false, features = ["runtime-tokio-hyper-rustls", "billing", "connect", "webhook-events", "uuid", "stream", "checkout"] } -axum = { version = "0.6.20", features = ["http2", "headers"] } -chrono = { version = "0.4.31", features = ["serde"] } -dashmap = "5.5.3" +anyhow = "1.0.89" +async-stripe = { version = "0.39.1", default-features = false, features = ["runtime-tokio-hyper-rustls", "billing", "connect", "webhook-events", "uuid", "stream", "checkout"] } +axum = { version = "0.7.7", features = ["http2"] } +chrono = { version = "0.4.38", features = ["serde"] } +dashmap = "6.1.0" dotenvy = "0.15.7" -figment = { version = "0.10.12", features = ["env"] } -jsonwebtoken = { version = "9.1.0", default-features = false } -owasp-headers = "0.1.2" -reqwest = { version = "0.11.22", default-features = false, features = ["rustls-tls", "trust-dns"] } -sea-orm = { version = "0.12.7", features = [ "sqlx-postgres", "runtime-tokio-rustls", "macros", "with-json", "with-chrono", "with-uuid" ] } -serde = { version = "1.0.193", features = ["derive"] } -serde_json = "1.0.108" -serde_with = "3.4.0" -thiserror = "1.0.50" -tokio = { version = "1.34.0", features = ["full"] } -tower = "0.4.13" -tower-default-headers = "0.1.1" -tower-http = { version = "0.4.4", features = ["trace", "cors", "compression-full", "request-id", "timeout"] } +figment = { version = "0.10.19", features = ["env"] } +jsonwebtoken = { version = "9.3.0", default-features = false } +reqwest = { version = "0.12.8", default-features = false, features = ["rustls-tls", "trust-dns"] } +sea-orm = { version = "1.0.1", features = [ "sqlx-postgres", "runtime-tokio-rustls", "macros", "with-json", "with-chrono", "with-uuid" ] } +serde = { version = "1.0.210", features = ["derive"] } +serde_json = "1.0.128" +serde_with = "3.11.0" +thiserror = "1.0.64" +tokio = { version = "1.40.0", features = ["full"] } +tower = "0.5.1" +tower-http = { version = "0.6.1", features = ["trace", "cors", "compression-full", "request-id", "timeout", "set-header"] } tracing = "0.1.40" tracing-subscriber = { version = "0.3.18", features = ["env-filter"] } -uuid = { version = "1.6.1", features = ["serde", "v7"] } +uuid = { version = "1.10.0", features = ["serde", "v7"] } + +[profile.release] +strip = true +lto = true +codegen-units = 1 diff --git a/Dockerfile b/Dockerfile index 21aa7ec..0cdc293 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.74.0-alpine AS base +FROM rust:1.81.0-alpine AS base RUN apk add musl-dev musl-utils RUN cargo install cargo-chef diff --git a/src/api/mod.rs b/src/api/mod.rs index 716cfe1..d28d52a 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -13,7 +13,6 @@ use sea_orm::{ConnectOptions, Database, DatabaseConnection}; use std::net::{IpAddr, SocketAddr}; use std::sync::Arc; use tokio::{select, signal}; -use tower_default_headers::DefaultHeadersLayer; use tower_http::compression::CompressionLayer; use tower_http::cors::CorsLayer; use tower_http::request_id::{MakeRequestUuid, PropagateRequestIdLayer, SetRequestIdLayer}; @@ -115,13 +114,11 @@ pub async fn serve(config: Config) -> Result<()> { .layer(CorsLayer::new()) .layer(PropagateRequestIdLayer::x_request_id()) .layer(SetRequestIdLayer::x_request_id(MakeRequestUuid)) - .layer(DefaultHeadersLayer::new(owasp_headers::headers())) .with_state(state.clone()); info!("Listening on {}", addr); - axum::Server::try_bind(&addr)? - .http1_header_read_timeout(config.request_timeout) - .serve(app.into_make_service()) + let listener = tokio::net::TcpListener::bind(&addr).await?; + axum::serve(listener, app) .with_graceful_shutdown(shutdown_signal(state.clone())) .await?; Ok(()) diff --git a/src/api/ratelimit.rs b/src/api/ratelimit.rs index dc96957..8e76d8e 100644 --- a/src/api/ratelimit.rs +++ b/src/api/ratelimit.rs @@ -3,7 +3,11 @@ use std::{ sync::Arc, }; -use axum::{extract::State, http::Request, middleware::Next, response::IntoResponse}; +use axum::{ + extract::{Request, State}, + middleware::Next, + response::IntoResponse, +}; use crate::{error::Error, token_bucket::TokenBucket}; @@ -12,10 +16,10 @@ use super::ApiContext; const IP_HEADER: &str = "X-Real-IP"; const DEFAULT_IP: IpAddr = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)); -pub async fn limiter( +pub async fn limiter( State(ctx): State>, - req: Request, - next: Next, + req: Request, + next: Next, ) -> Result { let ip = req .headers()