1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-08-07 17:03:01 +03:00

Remove the dependency on reqwest in the iana-codegen crate

This commit is contained in:
Quentin Gliech
2023-04-18 20:21:58 +02:00
parent 4baa15bbd3
commit 5f54965d80
8 changed files with 46 additions and 36 deletions

2
Cargo.lock generated
View File

@@ -3394,7 +3394,7 @@ dependencies = [
"convert_case", "convert_case",
"csv", "csv",
"futures-util", "futures-util",
"reqwest", "hyper",
"serde", "serde",
"tokio", "tokio",
"tracing", "tracing",

View File

@@ -12,8 +12,8 @@ camino = "1.1.4"
convert_case = "0.6.0" convert_case = "0.6.0"
csv = "1.2.1" csv = "1.2.1"
futures-util = "0.3.28" futures-util = "0.3.28"
reqwest = { version = "0.11.16", features = ["blocking", "rustls-tls"], default-features = false } hyper = { version = "0.14.16", features = ["tcp", "client", "http1"] }
serde = { version = "1.0.160", features = ["derive"] } serde = { version = "1.0.160", features = ["derive"] }
tokio = { version = "1.27.0", features = ["full"] } tokio = { version = "1.27.0", features = ["macros", "rt-multi-thread", "fs", "io-util"] }
tracing = "0.1.37" tracing = "0.1.37"
tracing-subscriber = "0.3.16" tracing-subscriber = "0.3.16"

View File

@@ -62,7 +62,7 @@ pub struct WebEncryptionSignatureAlgorithm {
impl EnumEntry for WebEncryptionSignatureAlgorithm { impl EnumEntry for WebEncryptionSignatureAlgorithm {
const URL: &'static str = const URL: &'static str =
"https://www.iana.org/assignments/jose/web-signature-encryption-algorithms.csv"; "http://www.iana.org/assignments/jose/web-signature-encryption-algorithms.csv";
const SECTIONS: &'static [Section] = &[ const SECTIONS: &'static [Section] = &[
s( s(
"JsonWebSignatureAlg", "JsonWebSignatureAlg",
@@ -126,7 +126,7 @@ pub struct WebEncryptionCompressionAlgorithm {
impl EnumEntry for WebEncryptionCompressionAlgorithm { impl EnumEntry for WebEncryptionCompressionAlgorithm {
const URL: &'static str = const URL: &'static str =
"https://www.iana.org/assignments/jose/web-encryption-compression-algorithms.csv"; "http://www.iana.org/assignments/jose/web-encryption-compression-algorithms.csv";
const SECTIONS: &'static [Section] = &[s( const SECTIONS: &'static [Section] = &[s(
"JsonWebEncryptionCompressionAlgorithm", "JsonWebEncryptionCompressionAlgorithm",
"JSON Web Encryption Compression Algorithm", "JSON Web Encryption Compression Algorithm",
@@ -161,7 +161,7 @@ pub struct WebKeyType {
} }
impl EnumEntry for WebKeyType { impl EnumEntry for WebKeyType {
const URL: &'static str = "https://www.iana.org/assignments/jose/web-key-types.csv"; const URL: &'static str = "http://www.iana.org/assignments/jose/web-key-types.csv";
const SECTIONS: &'static [Section] = &[s("JsonWebKeyType", "JSON Web Key Type")]; const SECTIONS: &'static [Section] = &[s("JsonWebKeyType", "JSON Web Key Type")];
fn key(&self) -> Option<&'static str> { fn key(&self) -> Option<&'static str> {
@@ -193,7 +193,7 @@ pub struct WebKeyEllipticCurve {
} }
impl EnumEntry for WebKeyEllipticCurve { impl EnumEntry for WebKeyEllipticCurve {
const URL: &'static str = "https://www.iana.org/assignments/jose/web-key-elliptic-curve.csv"; const URL: &'static str = "http://www.iana.org/assignments/jose/web-key-elliptic-curve.csv";
const SECTIONS: &'static [Section] = &[ const SECTIONS: &'static [Section] = &[
s( s(
"JsonWebKeyEcEllipticCurve", "JsonWebKeyEcEllipticCurve",
@@ -236,7 +236,7 @@ pub struct WebKeyUse {
} }
impl EnumEntry for WebKeyUse { impl EnumEntry for WebKeyUse {
const URL: &'static str = "https://www.iana.org/assignments/jose/web-key-use.csv"; const URL: &'static str = "http://www.iana.org/assignments/jose/web-key-use.csv";
const SECTIONS: &'static [Section] = &[s("JsonWebKeyUse", "JSON Web Key Use")]; const SECTIONS: &'static [Section] = &[s("JsonWebKeyUse", "JSON Web Key Use")];
fn key(&self) -> Option<&'static str> { fn key(&self) -> Option<&'static str> {
@@ -266,7 +266,7 @@ pub struct WebKeyOperation {
} }
impl EnumEntry for WebKeyOperation { impl EnumEntry for WebKeyOperation {
const URL: &'static str = "https://www.iana.org/assignments/jose/web-key-operations.csv"; const URL: &'static str = "http://www.iana.org/assignments/jose/web-key-operations.csv";
const SECTIONS: &'static [Section] = &[s("JsonWebKeyOperation", "JSON Web Key Operation")]; const SECTIONS: &'static [Section] = &[s("JsonWebKeyOperation", "JSON Web Key Operation")];
fn key(&self) -> Option<&'static str> { fn key(&self) -> Option<&'static str> {

View File

@@ -19,10 +19,11 @@
use std::{collections::HashMap, fmt::Display, sync::Arc}; use std::{collections::HashMap, fmt::Display, sync::Arc};
use camino::{Utf8Path, Utf8PathBuf}; use camino::{Utf8Path, Utf8PathBuf};
use reqwest::Client;
use tokio::io::AsyncWriteExt; use tokio::io::AsyncWriteExt;
use tracing::Level; use tracing::Level;
type Client = hyper::Client<hyper::client::HttpConnector>;
mod gen; mod gen;
pub mod jose; pub mod jose;
pub mod oauth; pub mod oauth;
@@ -208,7 +209,7 @@ async fn main() -> anyhow::Result<()> {
.pretty() .pretty()
.init(); .init();
let client = Client::builder().user_agent("iana-parser/0.0.1").build()?; let client = Client::new();
let client = Arc::new(client); let client = Arc::new(client);
let iana_crate_root = Utf8Path::new("crates/iana/"); let iana_crate_root = Utf8Path::new("crates/iana/");

View File

@@ -35,7 +35,7 @@ pub struct AccessTokenType {
} }
impl EnumEntry for AccessTokenType { impl EnumEntry for AccessTokenType {
const URL: &'static str = "https://www.iana.org/assignments/oauth-parameters/token-types.csv"; const URL: &'static str = "http://www.iana.org/assignments/oauth-parameters/token-types.csv";
const SECTIONS: &'static [Section] = &[s("OAuthAccessTokenType", "OAuth Access Token Type")]; const SECTIONS: &'static [Section] = &[s("OAuthAccessTokenType", "OAuth Access Token Type")];
fn key(&self) -> Option<&'static str> { fn key(&self) -> Option<&'static str> {
@@ -59,7 +59,7 @@ pub struct AuthorizationEndpointResponseType {
} }
impl EnumEntry for AuthorizationEndpointResponseType { impl EnumEntry for AuthorizationEndpointResponseType {
const URL: &'static str = "https://www.iana.org/assignments/oauth-parameters/endpoint.csv"; const URL: &'static str = "http://www.iana.org/assignments/oauth-parameters/endpoint.csv";
const SECTIONS: &'static [Section] = &[s( const SECTIONS: &'static [Section] = &[s(
"OAuthAuthorizationEndpointResponseType", "OAuthAuthorizationEndpointResponseType",
"OAuth Authorization Endpoint Response Type", "OAuth Authorization Endpoint Response Type",
@@ -98,7 +98,7 @@ pub struct TokenTypeHint {
impl EnumEntry for TokenTypeHint { impl EnumEntry for TokenTypeHint {
const URL: &'static str = const URL: &'static str =
"https://www.iana.org/assignments/oauth-parameters/token-type-hint.csv"; "http://www.iana.org/assignments/oauth-parameters/token-type-hint.csv";
const SECTIONS: &'static [Section] = &[s("OAuthTokenTypeHint", "OAuth Token Type Hint")]; const SECTIONS: &'static [Section] = &[s("OAuthTokenTypeHint", "OAuth Token Type Hint")];
fn key(&self) -> Option<&'static str> { fn key(&self) -> Option<&'static str> {
@@ -112,7 +112,7 @@ impl EnumEntry for TokenTypeHint {
impl EnumEntry for TokenEndpointAuthenticationMethod { impl EnumEntry for TokenEndpointAuthenticationMethod {
const URL: &'static str = const URL: &'static str =
"https://www.iana.org/assignments/oauth-parameters/token-endpoint-auth-method.csv"; "http://www.iana.org/assignments/oauth-parameters/token-endpoint-auth-method.csv";
const SECTIONS: &'static [Section] = &[s( const SECTIONS: &'static [Section] = &[s(
"OAuthClientAuthenticationMethod", "OAuthClientAuthenticationMethod",
"OAuth Token Endpoint Authentication Method", "OAuth Token Endpoint Authentication Method",
@@ -140,7 +140,7 @@ pub struct PkceCodeChallengeMethod {
impl EnumEntry for PkceCodeChallengeMethod { impl EnumEntry for PkceCodeChallengeMethod {
const URL: &'static str = const URL: &'static str =
"https://www.iana.org/assignments/oauth-parameters/pkce-code-challenge-method.csv"; "http://www.iana.org/assignments/oauth-parameters/pkce-code-challenge-method.csv";
const SECTIONS: &'static [Section] = const SECTIONS: &'static [Section] =
&[s("PkceCodeChallengeMethod", "PKCE Code Challenge Method")]; &[s("PkceCodeChallengeMethod", "PKCE Code Challenge Method")];

View File

@@ -15,9 +15,11 @@
use anyhow::Context; use anyhow::Context;
use async_trait::async_trait; use async_trait::async_trait;
use convert_case::{Case, Casing}; use convert_case::{Case, Casing};
use reqwest::Client; use hyper::http;
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
use super::Client;
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Section { pub struct Section {
pub key: &'static str, pub key: &'static str,
@@ -72,12 +74,19 @@ pub trait EnumEntry: DeserializeOwned + Send + Sync {
async fn fetch(client: &Client) -> anyhow::Result<Vec<(&'static str, EnumMember)>> { async fn fetch(client: &Client) -> anyhow::Result<Vec<(&'static str, EnumMember)>> {
tracing::info!("Fetching CSV"); tracing::info!("Fetching CSV");
let body = client let request = http::Request::get(Self::URL)
.get(Self::URL) .header("User-Agent", "mas-iana-codegen/0.1")
.send() .body(hyper::Body::empty())?;
let response = client
.request(request)
.await .await
.context(format!("can't the CSV at {}", Self::URL))? .context(format!("can't the CSV at {}", Self::URL))?;
.bytes()
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())
.await .await
.context(format!("can't the CSV body at {}", Self::URL))?; .context(format!("can't the CSV body at {}", Self::URL))?;

View File

@@ -19,7 +19,7 @@
/// JSON Web Signature "alg" parameter /// JSON Web Signature "alg" parameter
/// ///
/// Source: <https://www.iana.org/assignments/jose/web-signature-encryption-algorithms.csv> /// Source: <http://www.iana.org/assignments/jose/web-signature-encryption-algorithms.csv>
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum JsonWebSignatureAlg { pub enum JsonWebSignatureAlg {
@@ -365,7 +365,7 @@ impl schemars::JsonSchema for JsonWebSignatureAlg {
/// JSON Web Encryption "alg" parameter /// JSON Web Encryption "alg" parameter
/// ///
/// Source: <https://www.iana.org/assignments/jose/web-signature-encryption-algorithms.csv> /// Source: <http://www.iana.org/assignments/jose/web-signature-encryption-algorithms.csv>
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum JsonWebEncryptionAlg { pub enum JsonWebEncryptionAlg {
@@ -783,7 +783,7 @@ impl schemars::JsonSchema for JsonWebEncryptionAlg {
/// JSON Web Encryption "enc" parameter /// JSON Web Encryption "enc" parameter
/// ///
/// Source: <https://www.iana.org/assignments/jose/web-signature-encryption-algorithms.csv> /// Source: <http://www.iana.org/assignments/jose/web-signature-encryption-algorithms.csv>
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum JsonWebEncryptionEnc { pub enum JsonWebEncryptionEnc {
@@ -967,7 +967,7 @@ impl schemars::JsonSchema for JsonWebEncryptionEnc {
/// JSON Web Encryption Compression Algorithm /// JSON Web Encryption Compression Algorithm
/// ///
/// Source: <https://www.iana.org/assignments/jose/web-encryption-compression-algorithms.csv> /// Source: <http://www.iana.org/assignments/jose/web-encryption-compression-algorithms.csv>
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum JsonWebEncryptionCompressionAlgorithm { pub enum JsonWebEncryptionCompressionAlgorithm {
@@ -1061,7 +1061,7 @@ impl schemars::JsonSchema for JsonWebEncryptionCompressionAlgorithm {
/// JSON Web Key Type /// JSON Web Key Type
/// ///
/// Source: <https://www.iana.org/assignments/jose/web-key-types.csv> /// Source: <http://www.iana.org/assignments/jose/web-key-types.csv>
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum JsonWebKeyType { pub enum JsonWebKeyType {
@@ -1209,7 +1209,7 @@ impl schemars::JsonSchema for JsonWebKeyType {
/// JSON Web Key EC Elliptic Curve /// JSON Web Key EC Elliptic Curve
/// ///
/// Source: <https://www.iana.org/assignments/jose/web-key-elliptic-curve.csv> /// Source: <http://www.iana.org/assignments/jose/web-key-elliptic-curve.csv>
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum JsonWebKeyEcEllipticCurve { pub enum JsonWebKeyEcEllipticCurve {
@@ -1357,7 +1357,7 @@ impl schemars::JsonSchema for JsonWebKeyEcEllipticCurve {
/// JSON Web Key OKP Elliptic Curve /// JSON Web Key OKP Elliptic Curve
/// ///
/// Source: <https://www.iana.org/assignments/jose/web-key-elliptic-curve.csv> /// Source: <http://www.iana.org/assignments/jose/web-key-elliptic-curve.csv>
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum JsonWebKeyOkpEllipticCurve { pub enum JsonWebKeyOkpEllipticCurve {
@@ -1505,7 +1505,7 @@ impl schemars::JsonSchema for JsonWebKeyOkpEllipticCurve {
/// JSON Web Key Use /// JSON Web Key Use
/// ///
/// Source: <https://www.iana.org/assignments/jose/web-key-use.csv> /// Source: <http://www.iana.org/assignments/jose/web-key-use.csv>
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum JsonWebKeyUse { pub enum JsonWebKeyUse {
@@ -1617,7 +1617,7 @@ impl schemars::JsonSchema for JsonWebKeyUse {
/// JSON Web Key Operation /// JSON Web Key Operation
/// ///
/// Source: <https://www.iana.org/assignments/jose/web-key-operations.csv> /// Source: <http://www.iana.org/assignments/jose/web-key-operations.csv>
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum JsonWebKeyOperation { pub enum JsonWebKeyOperation {

View File

@@ -19,7 +19,7 @@
/// OAuth Access Token Type /// OAuth Access Token Type
/// ///
/// Source: <https://www.iana.org/assignments/oauth-parameters/token-types.csv> /// Source: <http://www.iana.org/assignments/oauth-parameters/token-types.csv>
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum OAuthAccessTokenType { pub enum OAuthAccessTokenType {
@@ -128,7 +128,7 @@ impl schemars::JsonSchema for OAuthAccessTokenType {
/// OAuth Authorization Endpoint Response Type /// OAuth Authorization Endpoint Response Type
/// ///
/// Source: <https://www.iana.org/assignments/oauth-parameters/endpoint.csv> /// Source: <http://www.iana.org/assignments/oauth-parameters/endpoint.csv>
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum OAuthAuthorizationEndpointResponseType { pub enum OAuthAuthorizationEndpointResponseType {
/// `code` /// `code`
@@ -287,7 +287,7 @@ impl schemars::JsonSchema for OAuthAuthorizationEndpointResponseType {
/// OAuth Token Type Hint /// OAuth Token Type Hint
/// ///
/// Source: <https://www.iana.org/assignments/oauth-parameters/token-type-hint.csv> /// Source: <http://www.iana.org/assignments/oauth-parameters/token-type-hint.csv>
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum OAuthTokenTypeHint { pub enum OAuthTokenTypeHint {
@@ -396,7 +396,7 @@ impl schemars::JsonSchema for OAuthTokenTypeHint {
/// OAuth Token Endpoint Authentication Method /// OAuth Token Endpoint Authentication Method
/// ///
/// Source: <https://www.iana.org/assignments/oauth-parameters/token-endpoint-auth-method.csv> /// Source: <http://www.iana.org/assignments/oauth-parameters/token-endpoint-auth-method.csv>
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum OAuthClientAuthenticationMethod { pub enum OAuthClientAuthenticationMethod {
@@ -549,7 +549,7 @@ impl schemars::JsonSchema for OAuthClientAuthenticationMethod {
/// PKCE Code Challenge Method /// PKCE Code Challenge Method
/// ///
/// Source: <https://www.iana.org/assignments/oauth-parameters/pkce-code-challenge-method.csv> /// Source: <http://www.iana.org/assignments/oauth-parameters/pkce-code-challenge-method.csv>
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[non_exhaustive] #[non_exhaustive]
pub enum PkceCodeChallengeMethod { pub enum PkceCodeChallengeMethod {