diff --git a/Cargo.lock b/Cargo.lock index 94b1e22d..49a123c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1776,6 +1776,21 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "foreign-types" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" +dependencies = [ + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-shared" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" + [[package]] name = "form_urlencoded" version = "1.2.1" @@ -2331,6 +2346,22 @@ dependencies = [ "tower-service", ] +[[package]] +name = "hyper-tls" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" +dependencies = [ + "bytes", + "http-body-util", + "hyper 1.4.0", + "hyper-util", + "native-tls", + "tokio", + "tokio-native-tls", + "tower-service", +] + [[package]] name = "hyper-util" version = "0.1.6" @@ -2727,6 +2758,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "ipnet" +version = "2.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" + [[package]] name = "ipnetwork" version = "0.20.0" @@ -3304,7 +3341,7 @@ dependencies = [ "convert_case", "csv", "futures-util", - "hyper 1.4.0", + "reqwest", "serde", "tokio", "tracing", @@ -3764,6 +3801,23 @@ dependencies = [ "version_check", ] +[[package]] +name = "native-tls" +version = "0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" +dependencies = [ + "libc", + "log", + "openssl", + "openssl-probe", + "openssl-sys", + "schannel", + "security-framework", + "security-framework-sys", + "tempfile", +] + [[package]] name = "nom" version = "7.1.3" @@ -3935,12 +3989,50 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" +[[package]] +name = "openssl" +version = "0.10.64" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" +dependencies = [ + "bitflags 2.6.0", + "cfg-if", + "foreign-types", + "libc", + "once_cell", + "openssl-macros", + "openssl-sys", +] + +[[package]] +name = "openssl-macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.68", +] + [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-sys" +version = "0.9.102" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" +dependencies = [ + "cc", + "libc", + "pkg-config", + "vcpkg", +] + [[package]] name = "opentelemetry" version = "0.23.0" @@ -4763,6 +4855,49 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +[[package]] +name = "reqwest" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7d6d2a27d57148378eb5e111173f4276ad26340ecc5c49a4a2152167a2d6a37" +dependencies = [ + "base64 0.22.1", + "bytes", + "encoding_rs", + "futures-core", + "futures-util", + "h2 0.4.5", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.4.0", + "hyper-rustls", + "hyper-tls", + "hyper-util", + "ipnet", + "js-sys", + "log", + "mime", + "native-tls", + "once_cell", + "percent-encoding", + "pin-project-lite", + "rustls-pemfile 2.1.2", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper 1.0.1", + "system-configuration", + "tokio", + "tokio-native-tls", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winreg", +] + [[package]] name = "rfc6979" version = "0.4.0" @@ -5875,6 +6010,27 @@ dependencies = [ "syn 2.0.68", ] +[[package]] +name = "system-configuration" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" +dependencies = [ + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "target-lexicon" version = "0.12.14" @@ -6009,6 +6165,16 @@ dependencies = [ "syn 2.0.68", ] +[[package]] +name = "tokio-native-tls" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" +dependencies = [ + "native-tls", + "tokio", +] + [[package]] name = "tokio-rustls" version = "0.25.0" @@ -7040,6 +7206,16 @@ dependencies = [ "memchr", ] +[[package]] +name = "winreg" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" +dependencies = [ + "cfg-if", + "windows-sys 0.48.0", +] + [[package]] name = "wiremock" version = "0.6.0" diff --git a/crates/iana-codegen/Cargo.toml b/crates/iana-codegen/Cargo.toml index 8b2fdab2..d5da9eba 100644 --- a/crates/iana-codegen/Cargo.toml +++ b/crates/iana-codegen/Cargo.toml @@ -18,8 +18,8 @@ camino.workspace = true convert_case = "0.6.0" csv = "1.3.0" futures-util = "0.3.30" -hyper.workspace = true +reqwest = "0.12.5" serde.workspace = true -tokio.workspace= true +tokio.workspace = true tracing.workspace = true tracing-subscriber.workspace = true diff --git a/crates/iana-codegen/src/main.rs b/crates/iana-codegen/src/main.rs index 39893773..7d97e378 100644 --- a/crates/iana-codegen/src/main.rs +++ b/crates/iana-codegen/src/main.rs @@ -12,14 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -use std::{collections::HashMap, fmt::Display, sync::Arc}; +use std::{collections::HashMap, fmt::Display}; use camino::{Utf8Path, Utf8PathBuf}; +use reqwest::Client; use tokio::io::AsyncWriteExt; use tracing::Level; -type Client = hyper::Client; - mod gen; pub mod jose; pub mod oauth; @@ -27,7 +26,7 @@ pub mod traits; #[derive(Debug)] struct File { - client: Arc, + client: Client, registry_name: &'static str, registry_url: &'static str, sections: Vec
, @@ -42,7 +41,7 @@ fn resolve_path(relative: impl AsRef) -> Utf8PathBuf { impl File { #[tracing::instrument(skip(client))] - fn new(registry_name: &'static str, registry_url: &'static str, client: Arc) -> Self { + fn new(registry_name: &'static str, registry_url: &'static str, client: Client) -> Self { tracing::info!("Generating file from IANA registry"); Self { client, @@ -142,7 +141,7 @@ use self::traits::{EnumEntry, EnumMember, Section}; #[tracing::instrument(skip_all, fields(%path))] async fn generate_jose( - client: &Arc, + client: &Client, path: impl AsRef + std::fmt::Display, ) -> anyhow::Result<()> { let path = resolve_path(path); @@ -173,7 +172,7 @@ async fn generate_jose( #[tracing::instrument(skip_all, fields(%path))] async fn generate_oauth( - client: &Arc, + client: &Client, path: impl AsRef + std::fmt::Display, ) -> anyhow::Result<()> { let path = resolve_path(path); @@ -182,7 +181,7 @@ async fn generate_oauth( let file = File::new( "OAuth Parameters", "https://www.iana.org/assignments/jose/jose.xhtml", - client.clone(), + client, ) .load::() .await? @@ -208,7 +207,6 @@ async fn main() -> anyhow::Result<()> { .init(); let client = Client::new(); - let client = Arc::new(client); let iana_crate_root = Utf8Path::new("crates/iana/"); diff --git a/crates/iana-codegen/src/traits.rs b/crates/iana-codegen/src/traits.rs index 7c900608..d4ecfd39 100644 --- a/crates/iana-codegen/src/traits.rs +++ b/crates/iana-codegen/src/traits.rs @@ -15,7 +15,6 @@ use anyhow::Context; use async_trait::async_trait; use convert_case::{Case, Casing}; -use hyper::http; use serde::de::DeserializeOwned; use super::Client; @@ -74,23 +73,23 @@ pub trait EnumEntry: DeserializeOwned + Send + Sync { async fn fetch(client: &Client) -> anyhow::Result> { tracing::info!("Fetching CSV"); - let request = http::Request::get(Self::URL) - .header("User-Agent", "mas-iana-codegen/0.1") - .body(hyper::Body::empty())?; let response = client - .request(request) + .get(Self::URL) + .header("User-Agent", "mas-iana-codegen/0.1") + .send() .await .context(format!("can't the CSV at {}", Self::URL))?; let status = response.status(); anyhow::ensure!(status.is_success(), "HTTP status code is not 200: {status}"); - let body = hyper::body::to_bytes(response.into_body()) + let body = response + .text() .await .context(format!("can't the CSV body at {}", Self::URL))?; - let parsed: Result, _> = csv::Reader::from_reader(body.as_ref()) + let parsed: Result, _> = csv::Reader::from_reader(body.as_bytes()) .into_deserialize() .filter_map(|item: Result| { item.map(|item| {