Skip to content

Commit

Permalink
chore!: Update to http 1.0, hyper 1.0, axum 0.7 and more
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsvante committed Dec 6, 2023
1 parent 3a28911 commit c77af3e
Show file tree
Hide file tree
Showing 10 changed files with 719 additions and 607 deletions.
1,204 changes: 655 additions & 549 deletions Cargo.lock

Large diffs are not rendered by default.

67 changes: 34 additions & 33 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,56 @@ homepage = "https://github.com/hyperkliv/samling"

[dependencies]
argon2 = "0.5.2"
async-trait = "0.1.73"
axum = { version = "0.6.20", features = ["headers", "macros"] }
base64 = "0.21.3"
bytes = { version = "1.4.0", features = ["serde"] }
clap = { version = "4.4.2", features = ["derive", "env"], optional = true }
cornucopia_async = { version = "0.4.0", features = ["with-serde_json-1"] }
csv = "1.2.2"
deadpool-postgres = "0.10.5"
async-trait = "0.1.74"
axum = { version = "0.7.2", features = ["macros"] }
axum-extra = { version = "0.9.0", features = ["typed-header"] }
base64 = "0.21.5"
bytes = { version = "1.5.0", features = ["serde"] }
clap = { version = "4.4.11", features = ["derive", "env"], optional = true }
cornucopia_async = { git = "https://github.com/cornucopia-rs/cornucopia.git", features = ["with-serde_json-1"] }
csv = "1.3.0"
deadpool-postgres = "0.11.0"
derive_more = "0.99.17"
dotenvy = "0.15.7"
futures = "0.3.28"
governor = "0.5.1"
http = "0.2.9"
hyper = { version = "0.14.27", features = ["server", "tcp", "stream", "http1", "http2"] }
futures = "0.3.29"
governor = "0.6.0"
http = "1.0.0"
hyper = { version = "1.0.1", features = ["server", "http1", "http2"] }
include_dir = "0.7.3"
indexmap = "1.9.3"
itertools = "0.10.5"
jsonwebtoken = "8.3.0"
indexmap = { version = "2.1.0", features = ["serde"] }
itertools = "0.12.0"
jsonwebtoken = "9.2.0"
log = "0.4.20"
mimalloc = { version = "0.1.38", default-features = false, optional = true }
mimalloc = { version = "0.1.39", default-features = false, optional = true }
mime = "0.3.17"
mime_guess = "2.0.4"
num_enum = "0.6.1"
num_enum = "0.7.1"
once_cell = "1.18.0"
password-hash = { version = "0.5.0", features = ["std"] }
postgres-types = { version = "0.2.6", features = ["derive", "with-time-0_3", "with-serde_json-1"] }
rand = "0.8.5"
reqwest = { version = "0.11.20", features = ["rustls-tls", "json", "stream", "multipart"], default-features = false }
rust_decimal = { version = "1.32.0", features = ["db-tokio-postgres", "db-postgres", "serde-with-float"] }
rust_xlsxwriter = "0.39.0"
schemars = { version = "0.8.13", features = ["derive", "preserve_order", "bytes", "url", "rust_decimal"] }
sentry = { version = "0.31.6", default-features = false, features = ["rustls", "tracing", "backtrace", "contexts", "panic", "tokio", "reqwest", "tower"] }
serde = { version = "1.0.188", features = ["derive"] }
serde_json = { version = "1.0.105", features = ["preserve_order"] }
reqwest = { version = "0.11.22", features = ["rustls-tls", "json", "stream", "multipart"], default-features = false }
rust_decimal = { version = "1.33.1", features = ["db-tokio-postgres", "db-postgres", "serde-with-float"] }
rust_xlsxwriter = "0.56.0"
schemars = { version = "0.8.16", features = ["derive", "preserve_order", "bytes", "url", "rust_decimal"] }
sentry = { version = "0.32.0", default-features = false, features = ["rustls", "tracing", "backtrace", "contexts", "panic", "tokio", "reqwest", "tower"] }
serde = { version = "1.0.193", features = ["derive"] }
serde_json = { version = "1.0.108", features = ["preserve_order"] }
serde_path_to_error = "0.1.14"
slug = "0.1.4"
slug = "0.1.5"
smol_str = { version = "0.2.0", features = ["serde"] }
strum = { version = "0.24.1", features = ["derive"] }
thiserror = "1.0.48"
strum = { version = "0.25.0", features = ["derive"] }
thiserror = "1.0.50"
# TODO: Remove `serde-well-known`, it's being deprecated. See this commit:
# https://github.com/time-rs/time/commit/110e17bb8461816551f7197a2aa2e34c981fa22d
time = { version = "0.3.28", features = ["serde", "serde-human-readable", "serde-well-known"] }
tokio = { version = "1.32.0", default-features = false, features = ["signal", "macros", "rt-multi-thread"] }
time = { version = "0.3.30", features = ["serde", "serde-human-readable", "serde-well-known"] }
tokio = { version = "1.34.0", default-features = false, features = ["signal", "macros", "rt-multi-thread"] }
tokio-postgres = "0.7.10"
tower = "0.4.13"
tower-http = { version = "0.4.4", default-features = false, features = ["fs", "trace", "cors", "compression-full"] }
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", optional = true }
url = { version = "2.4.1", features = ["serde"] }
tower-http = { version = "0.5.0", default-features = false, features = ["fs", "trace", "cors", "compression-full"] }
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", optional = true }
url = { version = "2.5.0", features = ["serde"] }

[features]
default = ["cli"]
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# https://github.com/emerzon/alpine-mimalloc/blob/master/Dockerfile
# NOTE: This has to be activated from within the Rust code,
# e.g. with https://crates.io/crates/mimalloc.
ARG API_BASE_IMAGE=lukemathwalker/cargo-chef:0.1.62-rust-1.72.0-alpine3.18
ARG API_BASE_IMAGE=lukemathwalker/cargo-chef:0.1.62-rust-1.74.0-alpine3.18


### Mimalloc compilation
Expand Down
9 changes: 4 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ use std::net::SocketAddr;

use axum::extract::{DefaultBodyLimit, State};
use axum::http::Method;
use axum::{Json, Server};
use axum::Json;
use deadpool_postgres::Pool;
use http::header::{AUTHORIZATION, CONTENT_DISPOSITION, CONTENT_TYPE};
use http::HeaderValue;
use tokio::net::TcpListener;
use tower_http::compression::CompressionLayer;
use tower_http::cors::CorsLayer;
use tower_http::trace::TraceLayer;
Expand Down Expand Up @@ -85,10 +86,8 @@ pub async fn serve(
.layer(DefaultBodyLimit::max(10 * 1024 * 1024));

tracing::info!("Listening on {}", address);

Server::bind(&address)
.serve(app.into_make_service())
.await?;
let listener = TcpListener::bind(address).await?;
axum::serve(listener, app).await?;
Ok(())
}

Expand Down
5 changes: 3 additions & 2 deletions src/auth/signing.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use std::fmt;

use async_trait::async_trait;
use axum::{
extract::{FromRequestParts, TypedHeader},
use axum::extract::FromRequestParts;
use axum_extra::{
headers::{authorization::Bearer, Authorization},
TypedHeader,
};
use http::request::Parts;
use itertools::Itertools;
Expand Down
2 changes: 1 addition & 1 deletion src/auth/sso/microsoft.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use bytes::Bytes;
use http::StatusCode;
use jsonwebtoken::{
jwk::{AlgorithmParameters, JwkSet},
DecodingKey, Validation,
};
use reqwest::StatusCode;
use schemars::JsonSchema;
use serde::Deserialize;

Expand Down
12 changes: 6 additions & 6 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use std::{
};

use clap::Parser;
use http::{
header::{HeaderName, CONTENT_TYPE},
HeaderMap, HeaderValue,
use reqwest::{
header::{HeaderName, HeaderValue, CONTENT_TYPE},
Method,
};
use tokio::signal::unix::SignalKind;
use tracing::{debug, error, info, metadata::LevelFilter, Level};
Expand Down Expand Up @@ -94,7 +94,7 @@ enum Subcommand {
env = "CORS_ALLOWED_ORIGINS",
value_delimiter = ','
)]
cors_allowed_origins: Vec<HeaderValue>,
cors_allowed_origins: Vec<http::header::HeaderValue>,
/// Migrate to latest database schema version on startup. Only use when running 1 process of the app!
#[arg(long, env)]
db_auto_migrate: bool,
Expand All @@ -120,7 +120,7 @@ enum Subcommand {
host: String,
#[arg(short = 's', long, env = "SAMLING_SCHEME", default_value = "http")]
scheme: String,
method: http::Method,
method: Method,
api_path: String,
#[arg(short = 'd', long)]
data: Option<PathBuf>,
Expand Down Expand Up @@ -474,7 +474,7 @@ pub async fn run() -> CliResult<()> {
pretty,
headers,
} => {
let mut header_map = HeaderMap::from_iter(headers);
let mut header_map = reqwest::header::HeaderMap::from_iter(headers);
let content_type = header_map
.entry(CONTENT_TYPE)
.or_insert("application/json".try_into().unwrap());
Expand Down
11 changes: 7 additions & 4 deletions src/cloudflare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ use governor::{
state::{InMemoryState, NotKeyed},
Quota, RateLimiter,
};
use http::HeaderMap;
use once_cell::sync::OnceCell;
use rand::{distributions::Alphanumeric, Rng};
use reqwest::multipart::{self};
use reqwest::{
header::{HeaderMap, HeaderValue, AUTHORIZATION},
multipart::{self},
StatusCode,
};
use serde::Deserialize;
use tracing::log::debug;
use url::Url;
Expand Down Expand Up @@ -53,7 +56,7 @@ impl CloudflareApi {
custom_images_domain: Option<String>,
) -> Result<Self> {
let mut default_headers = HeaderMap::new();
default_headers.append("Authorization", format!("Bearer {token}").parse()?);
default_headers.append(AUTHORIZATION, HeaderValue::from_str(&token)?);
let client = reqwest::ClientBuilder::new()
.timeout(Duration::from_secs(30))
.default_headers(default_headers)
Expand Down Expand Up @@ -133,7 +136,7 @@ impl CloudflareApi {
&body,
)?)
}
Err(err) => Err(if err.status() == Some(http::StatusCode::CONFLICT) {
Err(err) => Err(if err.status() == Some(StatusCode::CONFLICT) {
Error::ImageAlreadyExists(id.to_owned())
} else {
let body = resp.text().await?;
Expand Down
8 changes: 4 additions & 4 deletions src/cornucopia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3764,8 +3764,8 @@ FROM
'url',
image.url
)
ORDER BY image.position ASC, image.uploaded_at DESC) FILTER (WHERE image.id IS NOT NULL
), '[]'::jsonb) AS \"images\"
ORDER BY image.position ASC, image.uploaded_at DESC
) FILTER (WHERE image.id IS NOT NULL), '[]'::jsonb) AS \"images\"
FROM
color
INNER JOIN style ON style.id = color.style_id
Expand Down Expand Up @@ -3835,8 +3835,8 @@ ORDER BY
'url',
image.url
)
ORDER BY image.position ASC, image.uploaded_at DESC) FILTER (WHERE image.id IS NOT NULL
), '[]'::jsonb) AS \"images\"
ORDER BY image.position ASC, image.uploaded_at DESC
) FILTER (WHERE image.id IS NOT NULL), '[]'::jsonb) AS \"images\"
FROM
color
INNER JOIN style ON style.id = color.style_id
Expand Down
6 changes: 4 additions & 2 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use axum::{
response::{IntoResponse, Response},
Json,
};
use http::header::InvalidHeaderValue;
use reqwest::header::InvalidHeaderValue;
use schemars::JsonSchema;
use serde::Serialize;

Expand Down Expand Up @@ -67,7 +67,9 @@ pub enum Error {
#[error("base64: {0}")]
Base64DecodeError(#[from] base64::DecodeError),
#[error("Invalid header error: {0}")]
InvalidHttpHeaderValue(#[from] InvalidHeaderValue),
InvalidHttpHeaderValue(#[from] http::header::InvalidHeaderValue),
#[error("Invalid header error: {0}")]
InvalidReqwestHttpHeaderValue(#[from] InvalidHeaderValue),
#[error("tokio-postgres error: {0}")]
DbError(#[from] tokio_postgres::Error),
#[error("Deadpool pool error: {0}")]
Expand Down

0 comments on commit c77af3e

Please sign in to comment.