1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-31 09:24:31 +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

View File

@ -12,8 +12,8 @@ camino = "1.1.4"
convert_case = "0.6.0"
csv = "1.2.1"
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"] }
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-subscriber = "0.3.16"

View File

@ -62,7 +62,7 @@ pub struct WebEncryptionSignatureAlgorithm {
impl EnumEntry for WebEncryptionSignatureAlgorithm {
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] = &[
s(
"JsonWebSignatureAlg",
@ -126,7 +126,7 @@ pub struct WebEncryptionCompressionAlgorithm {
impl EnumEntry for WebEncryptionCompressionAlgorithm {
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(
"JsonWebEncryptionCompressionAlgorithm",
"JSON Web Encryption Compression Algorithm",
@ -161,7 +161,7 @@ pub struct 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")];
fn key(&self) -> Option<&'static str> {
@ -193,7 +193,7 @@ pub struct 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] = &[
s(
"JsonWebKeyEcEllipticCurve",
@ -236,7 +236,7 @@ pub struct 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")];
fn key(&self) -> Option<&'static str> {
@ -266,7 +266,7 @@ pub struct 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")];
fn key(&self) -> Option<&'static str> {

View File

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

View File

@ -35,7 +35,7 @@ pub struct 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")];
fn key(&self) -> Option<&'static str> {
@ -59,7 +59,7 @@ pub struct 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(
"OAuthAuthorizationEndpointResponseType",
"OAuth Authorization Endpoint Response Type",
@ -98,7 +98,7 @@ pub struct TokenTypeHint {
impl EnumEntry for TokenTypeHint {
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")];
fn key(&self) -> Option<&'static str> {
@ -112,7 +112,7 @@ impl EnumEntry for TokenTypeHint {
impl EnumEntry for TokenEndpointAuthenticationMethod {
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(
"OAuthClientAuthenticationMethod",
"OAuth Token Endpoint Authentication Method",
@ -140,7 +140,7 @@ pub struct PkceCodeChallengeMethod {
impl EnumEntry for PkceCodeChallengeMethod {
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] =
&[s("PkceCodeChallengeMethod", "PKCE Code Challenge Method")];

View File

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

View File

@ -19,7 +19,7 @@
/// 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)]
#[non_exhaustive]
pub enum JsonWebSignatureAlg {
@ -365,7 +365,7 @@ impl schemars::JsonSchema for JsonWebSignatureAlg {
/// 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)]
#[non_exhaustive]
pub enum JsonWebEncryptionAlg {
@ -783,7 +783,7 @@ impl schemars::JsonSchema for JsonWebEncryptionAlg {
/// 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)]
#[non_exhaustive]
pub enum JsonWebEncryptionEnc {
@ -967,7 +967,7 @@ impl schemars::JsonSchema for JsonWebEncryptionEnc {
/// 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)]
#[non_exhaustive]
pub enum JsonWebEncryptionCompressionAlgorithm {
@ -1061,7 +1061,7 @@ impl schemars::JsonSchema for JsonWebEncryptionCompressionAlgorithm {
/// 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)]
#[non_exhaustive]
pub enum JsonWebKeyType {
@ -1209,7 +1209,7 @@ impl schemars::JsonSchema for JsonWebKeyType {
/// 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)]
#[non_exhaustive]
pub enum JsonWebKeyEcEllipticCurve {
@ -1357,7 +1357,7 @@ impl schemars::JsonSchema for JsonWebKeyEcEllipticCurve {
/// 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)]
#[non_exhaustive]
pub enum JsonWebKeyOkpEllipticCurve {
@ -1505,7 +1505,7 @@ impl schemars::JsonSchema for JsonWebKeyOkpEllipticCurve {
/// 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)]
#[non_exhaustive]
pub enum JsonWebKeyUse {
@ -1617,7 +1617,7 @@ impl schemars::JsonSchema for JsonWebKeyUse {
/// 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)]
#[non_exhaustive]
pub enum JsonWebKeyOperation {

View File

@ -19,7 +19,7 @@
/// 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)]
#[non_exhaustive]
pub enum OAuthAccessTokenType {
@ -128,7 +128,7 @@ impl schemars::JsonSchema for OAuthAccessTokenType {
/// 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)]
pub enum OAuthAuthorizationEndpointResponseType {
/// `code`
@ -287,7 +287,7 @@ impl schemars::JsonSchema for OAuthAuthorizationEndpointResponseType {
/// 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)]
#[non_exhaustive]
pub enum OAuthTokenTypeHint {
@ -396,7 +396,7 @@ impl schemars::JsonSchema for OAuthTokenTypeHint {
/// 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)]
#[non_exhaustive]
pub enum OAuthClientAuthenticationMethod {
@ -549,7 +549,7 @@ impl schemars::JsonSchema for OAuthClientAuthenticationMethod {
/// 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)]
#[non_exhaustive]
pub enum PkceCodeChallengeMethod {