chore(deps): update axum (#1637)

This commit is contained in:
Conrad Ludgate 2024-01-28 13:33:45 +00:00 committed by GitHub
parent 4b20544474
commit bdcb143996
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 147 additions and 84 deletions

142
Cargo.lock generated
View File

@ -282,15 +282,12 @@ dependencies = [
"config",
"eyre",
"fs-err",
"http 0.2.11",
"hyper 1.1.0",
"hyper-rustls",
"metrics",
"metrics-exporter-prometheus",
"rand",
"reqwest",
"rustls",
"rustls-pemfile",
"rustls-pemfile 2.0.0",
"semver",
"serde",
"serde_json",
@ -338,18 +335,19 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "axum"
version = "0.6.20"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf"
checksum = "1236b4b292f6c4d6dc34604bb5120d85c3fe1d1aa596bd5cc52ca054d13e7b9e"
dependencies = [
"async-trait",
"axum-core",
"bitflags 1.3.2",
"bytes",
"futures-util",
"http 0.2.11",
"http-body 0.4.6",
"hyper 0.14.28",
"http 1.0.0",
"http-body 1.0.0",
"http-body-util",
"hyper 1.1.0",
"hyper-util",
"itoa",
"matchit",
"memchr",
@ -366,42 +364,50 @@ dependencies = [
"tower",
"tower-layer",
"tower-service",
"tracing",
]
[[package]]
name = "axum-core"
version = "0.3.4"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c"
checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3"
dependencies = [
"async-trait",
"bytes",
"futures-util",
"http 0.2.11",
"http-body 0.4.6",
"http 1.0.0",
"http-body 1.0.0",
"http-body-util",
"mime",
"pin-project-lite",
"rustversion",
"sync_wrapper",
"tower-layer",
"tower-service",
"tracing",
]
[[package]]
name = "axum-server"
version = "0.5.1"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "447f28c85900215cc1bea282f32d4a2f22d55c5a300afdfbc661c8d6a632e063"
checksum = "c1ad46c3ec4e12f4a4b6835e173ba21c25e484c9d02b49770bf006ce5367c036"
dependencies = [
"arc-swap",
"bytes",
"futures-util",
"http 0.2.11",
"http-body 0.4.6",
"hyper 0.14.28",
"http 1.0.0",
"http-body 1.0.0",
"http-body-util",
"hyper 1.1.0",
"hyper-util",
"pin-project-lite",
"rustls",
"rustls-pemfile",
"rustls-pemfile 2.0.0",
"tokio",
"tokio-rustls",
"tower",
"tower-service",
]
@ -1310,6 +1316,25 @@ dependencies = [
"tracing",
]
[[package]]
name = "h2"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "31d030e59af851932b72ceebadf4a2b5986dba4c3b99dd2493f8273a0f151943"
dependencies = [
"bytes",
"fnv",
"futures-core",
"futures-sink",
"futures-util",
"http 1.0.0",
"indexmap 2.1.0",
"slab",
"tokio",
"tokio-util",
"tracing",
]
[[package]]
name = "hashbrown"
version = "0.12.3"
@ -1436,10 +1461,17 @@ dependencies = [
]
[[package]]
name = "http-range-header"
version = "0.3.1"
name = "http-body-util"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "add0ab9360ddbd88cfeb3bd9574a1d85cfdfa14db10b3e21d3700dbc4328758f"
checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840"
dependencies = [
"bytes",
"futures-util",
"http 1.0.0",
"http-body 1.0.0",
"pin-project-lite",
]
[[package]]
name = "httparse"
@ -1469,7 +1501,7 @@ dependencies = [
"futures-channel",
"futures-core",
"futures-util",
"h2",
"h2 0.3.24",
"http 0.2.11",
"http-body 0.4.6",
"httparse",
@ -1490,8 +1522,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75"
dependencies = [
"bytes",
"futures-channel",
"futures-util",
"h2 0.4.2",
"http 1.0.0",
"http-body 1.0.0",
"httparse",
"httpdate",
"itoa",
"pin-project-lite",
"tokio",
]
@ -1505,13 +1543,29 @@ dependencies = [
"futures-util",
"http 0.2.11",
"hyper 0.14.28",
"log",
"rustls",
"rustls-native-certs",
"tokio",
"tokio-rustls",
]
[[package]]
name = "hyper-util"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bdea9aac0dbe5a9240d68cfd9501e2db94222c6dc06843e06640b9e07f0fdc67"
dependencies = [
"bytes",
"futures-channel",
"futures-util",
"http 1.0.0",
"http-body 1.0.0",
"hyper 1.1.0",
"pin-project-lite",
"socket2",
"tokio",
"tracing",
]
[[package]]
name = "idna"
version = "0.5.0"
@ -2515,7 +2569,7 @@ dependencies = [
"encoding_rs",
"futures-core",
"futures-util",
"h2",
"h2 0.3.24",
"http 0.2.11",
"http-body 0.4.6",
"hyper 0.14.28",
@ -2529,7 +2583,7 @@ dependencies = [
"pin-project-lite",
"rustls",
"rustls-native-certs",
"rustls-pemfile",
"rustls-pemfile 1.0.4",
"serde",
"serde_json",
"serde_urlencoded",
@ -2672,7 +2726,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9aace74cb666635c918e9c12bc0d348266037aa8eb599b5cba565709a8dff00"
dependencies = [
"openssl-probe",
"rustls-pemfile",
"rustls-pemfile 1.0.4",
"schannel",
"security-framework",
]
@ -2686,6 +2740,22 @@ dependencies = [
"base64 0.21.7",
]
[[package]]
name = "rustls-pemfile"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "35e4980fa29e4c4b212ffb3db068a564cbf560e51d3944b7c88bd8bf5bec64f4"
dependencies = [
"base64 0.21.7",
"rustls-pki-types",
]
[[package]]
name = "rustls-pki-types"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e9d979b3ce68192e42760c7810125eb6cf2ea10efae545a156063e61f314e2a"
[[package]]
name = "rustls-webpki"
version = "0.101.7"
@ -3074,7 +3144,7 @@ dependencies = [
"paste",
"percent-encoding",
"rustls",
"rustls-pemfile",
"rustls-pemfile 1.0.4",
"serde",
"serde_json",
"sha2",
@ -3559,17 +3629,15 @@ dependencies = [
[[package]]
name = "tower-http"
version = "0.4.4"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61c5bb1d698276a2443e5ecfabc1008bf15a36c12e6a7176e7bf089ea9131140"
checksum = "0da193277a4e2c33e59e09b5861580c33dd0a637c3883d0fa74ba40c0374af2e"
dependencies = [
"bitflags 2.4.2",
"bytes",
"futures-core",
"futures-util",
"http 0.2.11",
"http-body 0.4.6",
"http-range-header",
"http 1.0.0",
"http-body 1.0.0",
"http-body-util",
"pin-project-lite",
"tower-layer",
"tower-service",

View File

@ -25,17 +25,14 @@ base64 = { workspace = true }
rand = { workspace = true }
tokio = { workspace = true }
async-trait = { workspace = true }
axum = "0.6.4"
axum-server = { version = "0.5.1", features = ["tls-rustls"] }
http = "0.2"
hyper = "1.1"
hyper-rustls = "0.24"
axum = "0.7.4"
axum-server = { version = "0.6.0", features = ["tls-rustls"] }
fs-err = { workspace = true }
tower = "0.4"
tower-http = { version = "0.4", features = ["trace"] }
tower-http = { version = "0.5.1", features = ["trace"] }
reqwest = { workspace = true }
rustls = "0.21"
rustls-pemfile = "1.0"
rustls-pemfile = "2.0"
argon2 = "0.5.3"
semver = { workspace = true }
metrics-exporter-prometheus = "0.12.1"

View File

@ -2,10 +2,9 @@ use std::{collections::HashMap, convert::TryFrom};
use axum::{
extract::{Path, Query, State},
http::HeaderMap,
http::{HeaderMap, StatusCode},
Json,
};
use http::StatusCode;
use metrics::counter;
use time::{Month, UtcOffset};
use tracing::{debug, error, instrument};
@ -215,7 +214,7 @@ pub async fn calendar<DB: Database>(
error: ErrorResponse {
reason: e.to_string().into(),
},
status: http::StatusCode::BAD_REQUEST,
status: StatusCode::BAD_REQUEST,
})?;
let period = match focus {

View File

@ -1,6 +1,6 @@
use atuin_common::api::{ErrorResponse, IndexResponse};
use atuin_server_database::Database;
use axum::{extract::State, response::IntoResponse, Json};
use axum::{extract::State, http, response::IntoResponse, Json};
use crate::router::AppState;

View File

@ -1,5 +1,4 @@
use axum::{response::IntoResponse, Json};
use http::StatusCode;
use axum::{http::StatusCode, response::IntoResponse, Json};
use serde_json::json;
use tracing::instrument;

View File

@ -1,5 +1,4 @@
use axum::{extract::State, Json};
use http::StatusCode;
use axum::{extract::State, http::StatusCode, Json};
use tracing::instrument;
use super::{ErrorResponse, ErrorResponseStatus, RespExt};

View File

@ -8,9 +8,9 @@ use argon2::{
};
use axum::{
extract::{Path, State},
http::StatusCode,
Json,
};
use http::StatusCode;
use metrics::counter;
use rand::rngs::OsRng;
use tracing::{debug, error, info, instrument};

View File

@ -1,5 +1,4 @@
use axum::{extract::Query, extract::State, Json};
use http::StatusCode;
use axum::{extract::Query, extract::State, http::StatusCode, Json};
use metrics::counter;
use serde::Deserialize;
use tracing::{error, instrument};

View File

@ -1,12 +1,11 @@
#![forbid(unsafe_code)]
use std::future::Future;
use std::net::SocketAddr;
use std::sync::Arc;
use std::{future::Future, net::TcpListener};
use atuin_server_database::Database;
use axum::Router;
use axum::Server;
use axum::{serve, Router};
use axum_server::Handle;
use eyre::{Context, Result};
@ -21,6 +20,7 @@ pub use settings::Settings;
pub mod settings;
use tokio::net::TcpListener;
use tokio::signal;
#[cfg(target_family = "unix")]
@ -55,7 +55,9 @@ pub async fn launch<Db: Database>(
} else {
launch_with_tcp_listener::<Db>(
settings,
TcpListener::bind(addr).context("could not connect to socket")?,
TcpListener::bind(addr)
.await
.context("could not connect to socket")?,
shutdown_signal(),
)
.await
@ -65,13 +67,11 @@ pub async fn launch<Db: Database>(
pub async fn launch_with_tcp_listener<Db: Database>(
settings: Settings<Db::Settings>,
listener: TcpListener,
shutdown: impl Future<Output = ()>,
shutdown: impl Future<Output = ()> + Send + 'static,
) -> Result<()> {
let r = make_router::<Db>(settings).await?;
Server::from_tcp(listener)
.context("could not launch server")?
.serve(r.into_make_service())
serve(listener, r.into_make_service())
.with_graceful_shutdown(shutdown)
.await?;
@ -115,7 +115,9 @@ async fn launch_with_tls<Db: Database>(
// The separate listener means it's much easier to ensure metrics are not accidentally exposed to
// the public.
pub async fn launch_metrics_server(host: String, port: u16) -> Result<()> {
let listener = TcpListener::bind((host, port)).context("failed to bind metrics tcp")?;
let listener = TcpListener::bind((host, port))
.await
.context("failed to bind metrics tcp")?;
let recorder_handle = metrics::setup_metrics_recorder();
@ -124,9 +126,7 @@ pub async fn launch_metrics_server(host: String, port: u16) -> Result<()> {
axum::routing::get(move || std::future::ready(recorder_handle.render())),
);
Server::from_tcp(listener)
.context("could not launch server")?
.serve(router.into_make_service())
serve(listener, router.into_make_service())
.with_graceful_shutdown(shutdown_signal())
.await?;

View File

@ -1,6 +1,10 @@
use std::time::Instant;
use axum::{extract::MatchedPath, http::Request, middleware::Next, response::IntoResponse};
use axum::{
extract::{MatchedPath, Request},
middleware::Next,
response::IntoResponse,
};
use metrics_exporter_prometheus::{Matcher, PrometheusBuilder, PrometheusHandle};
pub fn setup_metrics_recorder() -> PrometheusHandle {
@ -21,7 +25,7 @@ pub fn setup_metrics_recorder() -> PrometheusHandle {
/// Middleware to record some common HTTP metrics
/// Generic over B to allow for arbitrary body types (eg Vec<u8>, Streams, a deserialized thing, etc)
/// Someday tower-http might provide a metrics middleware: https://github.com/tower-rs/tower-http/issues/57
pub async fn track_metrics<B>(req: Request<B>, next: Next<B>) -> impl IntoResponse {
pub async fn track_metrics(req: Request, next: Next) -> impl IntoResponse {
let start = Instant::now();
let path = if let Some(matched_path) = req.extensions().get::<MatchedPath>() {

View File

@ -1,15 +1,14 @@
use async_trait::async_trait;
use atuin_common::api::{ErrorResponse, ATUIN_CARGO_VERSION, ATUIN_HEADER_VERSION};
use axum::{
extract::FromRequestParts,
http::Request,
extract::{FromRequestParts, Request},
http::{self, request::Parts},
middleware::Next,
response::{IntoResponse, Response},
routing::{delete, get, post},
Router,
};
use eyre::Result;
use http::request::Parts;
use tower::ServiceBuilder;
use tower_http::trace::TraceLayer;
@ -81,7 +80,7 @@ async fn teapot() -> impl IntoResponse {
(http::StatusCode::NOT_FOUND, "404 not found")
}
async fn clacks_overhead<B>(request: Request<B>, next: Next<B>) -> Response {
async fn clacks_overhead(request: Request, next: Next) -> Response {
let mut response = next.run(request).await;
let gnu_terry_value = "GNU Terry Pratchett, Kris Nova";
@ -94,7 +93,7 @@ async fn clacks_overhead<B>(request: Request<B>, next: Next<B>) -> Response {
}
/// Ensure that we only try and sync with clients on the same major version
async fn semver<B>(request: Request<B>, next: Next<B>) -> Response {
async fn semver(request: Request, next: Next) -> Response {
let mut response = next.run(request).await;
response
.headers_mut()

View File

@ -116,10 +116,9 @@ impl Tls {
.with_context(|| format!("tls.cert_path {:?} is missing", self.cert_path))?;
let mut reader = std::io::BufReader::new(cert_file);
let certs: Vec<_> = rustls_pemfile::certs(&mut reader)
.with_context(|| format!("tls.cert_path {:?} is invalid", self.cert_path))?
.into_iter()
.map(rustls::Certificate)
.collect();
.map(|c| c.map(|c| rustls::Certificate(c.to_vec())))
.collect::<Result<Vec<_>, _>>()
.with_context(|| format!("tls.cert_path {:?} is invalid", self.cert_path))?;
if certs.is_empty() {
bail!(
@ -136,6 +135,8 @@ impl Tls {
.with_context(|| format!("tls.pkey_path {:?} is missing", self.pkey_path))?;
let mut reader = std::io::BufReader::new(pkey_file);
let keys = rustls_pemfile::pkcs8_private_keys(&mut reader)
.map(|c| c.map(|c| rustls::PrivateKey(c.secret_pkcs8_der().to_vec())))
.collect::<Result<Vec<_>, _>>()
.with_context(|| format!("tls.pkey_path {:?} is not PKCS8-encoded", self.pkey_path))?;
if keys.is_empty() {
@ -145,8 +146,6 @@ impl Tls {
);
}
let key = rustls::PrivateKey(keys[0].clone());
Ok(key)
Ok(keys[0].clone())
}
}

View File

@ -1,4 +1,4 @@
use std::{env, net::TcpListener, time::Duration};
use std::{env, time::Duration};
use atuin_client::api_client;
use atuin_common::{api::AddHistoryRequest, utils::uuid_v7};
@ -6,7 +6,7 @@ use atuin_server::{launch_with_tcp_listener, Settings as ServerSettings};
use atuin_server_postgres::{Postgres, PostgresSettings};
use futures_util::TryFutureExt;
use time::OffsetDateTime;
use tokio::{sync::oneshot, task::JoinHandle};
use tokio::{net::TcpListener, sync::oneshot, task::JoinHandle};
use tracing::{dispatcher, Dispatch};
use tracing_subscriber::{layer::SubscriberExt, EnvFilter};
@ -42,7 +42,7 @@ async fn start_server(path: &str) -> (String, oneshot::Sender<()>, JoinHandle<()
};
let (shutdown_tx, shutdown_rx) = tokio::sync::oneshot::channel();
let listener = TcpListener::bind("127.0.0.1:0").unwrap();
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
let addr = listener.local_addr().unwrap();
let server = tokio::spawn(async move {
let _tracing_guard = dispatcher::set_default(&dispatch);