diff options
author | Conrad Ludgate <conradludgate@gmail.com> | 2024-01-28 13:33:45 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-28 13:33:45 +0000 |
commit | bdcb143996567c9540fb411bc53448355665747b (patch) | |
tree | c8152a7cfdf0f2d45c5f7e15a17b577206698340 /atuin-server | |
parent | 4b20544474088259c580faa015876cb535dbff36 (diff) |
chore(deps): update axum (#1637)
Diffstat (limited to 'atuin-server')
-rw-r--r-- | atuin-server/Cargo.toml | 11 | ||||
-rw-r--r-- | atuin-server/src/handlers/history.rs | 5 | ||||
-rw-r--r-- | atuin-server/src/handlers/mod.rs | 2 | ||||
-rw-r--r-- | atuin-server/src/handlers/record.rs | 3 | ||||
-rw-r--r-- | atuin-server/src/handlers/status.rs | 3 | ||||
-rw-r--r-- | atuin-server/src/handlers/user.rs | 2 | ||||
-rw-r--r-- | atuin-server/src/handlers/v0/record.rs | 3 | ||||
-rw-r--r-- | atuin-server/src/lib.rs | 24 | ||||
-rw-r--r-- | atuin-server/src/metrics.rs | 8 | ||||
-rw-r--r-- | atuin-server/src/router.rs | 9 | ||||
-rw-r--r-- | atuin-server/src/settings.rs | 13 |
11 files changed, 39 insertions, 44 deletions
diff --git a/atuin-server/Cargo.toml b/atuin-server/Cargo.toml index 7882fc7a7..18f8c280c 100644 --- a/atuin-server/Cargo.toml +++ b/atuin-server/Cargo.toml @@ -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" diff --git a/atuin-server/src/handlers/history.rs b/atuin-server/src/handlers/history.rs index cdee39882..05bbe7404 100644 --- a/atuin-server/src/handlers/history.rs +++ b/atuin-server/src/handlers/history.rs @@ -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 { diff --git a/atuin-server/src/handlers/mod.rs b/atuin-server/src/handlers/mod.rs index b66a20bf5..a10e622dd 100644 --- a/atuin-server/src/handlers/mod.rs +++ b/atuin-server/src/handlers/mod.rs @@ -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; diff --git a/atuin-server/src/handlers/record.rs b/atuin-server/src/handlers/record.rs index b5c07c5b8..bf454949b 100644 --- a/atuin-server/src/handlers/record.rs +++ b/atuin-server/src/handlers/record.rs @@ -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; diff --git a/atuin-server/src/handlers/status.rs b/atuin-server/src/handlers/status.rs index d9b6afafa..3c22232c3 100644 --- a/atuin-server/src/handlers/status.rs +++ b/atuin-server/src/handlers/status.rs @@ -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}; diff --git a/atuin-server/src/handlers/user.rs b/atuin-server/src/handlers/user.rs index 535c740f1..fb281ab3d 100644 --- a/atuin-server/src/handlers/user.rs +++ b/atuin-server/src/handlers/user.rs @@ -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}; diff --git a/atuin-server/src/handlers/v0/record.rs b/atuin-server/src/handlers/v0/record.rs index 438dd4590..e1b5d29c0 100644 --- a/atuin-server/src/handlers/v0/record.rs +++ b/atuin-server/src/handlers/v0/record.rs @@ -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}; diff --git a/atuin-server/src/lib.rs b/atuin-server/src/lib.rs index b505a8ec3..a0c104dc0 100644 --- a/atuin-server/src/lib.rs +++ b/atuin-server/src/lib.rs @@ -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?; diff --git a/atuin-server/src/metrics.rs b/atuin-server/src/metrics.rs index 2e3e6894a..0a7ac6bde 100644 --- a/atuin-server/src/metrics.rs +++ b/atuin-server/src/metrics.rs @@ -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>() { diff --git a/atuin-server/src/router.rs b/atuin-server/src/router.rs index 500e1a29a..8509058f9 100644 --- a/atuin-server/src/router.rs +++ b/atuin-server/src/router.rs @@ -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() diff --git a/atuin-server/src/settings.rs b/atuin-server/src/settings.rs index 1b1520133..2d00df360 100644 --- a/atuin-server/src/settings.rs +++ b/atuin-server/src/settings.rs @@ -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()) } } |