You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-29 22:01:14 +03:00
Remove the dependency on reqwest in the iana-codegen crate
This commit is contained in:
@ -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> {
|
||||
|
@ -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/");
|
||||
|
@ -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")];
|
||||
|
||||
|
@ -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))?;
|
||||
|
||||
|
Reference in New Issue
Block a user