mirror of
https://github.com/element-hq/matrix-authentication-service.git
synced 2026-08-28 05:14:17 +00:00
Remove optional features from the mas-policy crate
This commit is contained in:
@@ -15,7 +15,7 @@ workspace = true
|
||||
anyhow.workspace = true
|
||||
arc-swap.workspace = true
|
||||
opa-wasm.workspace = true
|
||||
schemars = { workspace = true, optional = true }
|
||||
schemars.workspace = true
|
||||
serde_json.workspace = true
|
||||
serde.workspace = true
|
||||
thiserror.workspace = true
|
||||
@@ -25,9 +25,5 @@ tracing.workspace = true
|
||||
mas-data-model.workspace = true
|
||||
oauth2-types.workspace = true
|
||||
|
||||
[features]
|
||||
jsonschema = ["dep:schemars"]
|
||||
|
||||
[[bin]]
|
||||
name = "schema"
|
||||
required-features = ["jsonschema"]
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
// Please see LICENSE in the repository root for full details.
|
||||
|
||||
#![expect(
|
||||
clippy::disallowed_types,
|
||||
reason = "We use Path/PathBuf instead of camino here for simplicity"
|
||||
)]
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use mas_policy::model::{
|
||||
@@ -12,17 +17,14 @@ use mas_policy::model::{
|
||||
use schemars::{JsonSchema, r#gen::SchemaSettings};
|
||||
|
||||
fn write_schema<T: JsonSchema>(out_dir: Option<&Path>, file: &str) {
|
||||
let mut writer: Box<dyn std::io::Write> = match out_dir {
|
||||
Some(out_dir) => {
|
||||
let path = out_dir.join(file);
|
||||
eprintln!("Writing to {path:?}");
|
||||
let file = std::fs::File::create(path).expect("Failed to create file");
|
||||
Box::new(std::io::BufWriter::new(file))
|
||||
}
|
||||
None => {
|
||||
eprintln!("--- {file} ---");
|
||||
Box::new(std::io::stdout())
|
||||
}
|
||||
let mut writer: Box<dyn std::io::Write> = if let Some(out_dir) = out_dir {
|
||||
let path = out_dir.join(file);
|
||||
eprintln!("Writing to {path:?}");
|
||||
let file = std::fs::File::create(path).expect("Failed to create file");
|
||||
Box::new(std::io::BufWriter::new(file))
|
||||
} else {
|
||||
eprintln!("--- {file} ---");
|
||||
Box::new(std::io::stdout())
|
||||
};
|
||||
|
||||
let settings = SchemaSettings::draft07().with(|s| {
|
||||
|
||||
+14
-31
@@ -13,12 +13,12 @@ use std::net::IpAddr;
|
||||
|
||||
use mas_data_model::{Client, User};
|
||||
use oauth2_types::{registration::VerifiedClientMetadata, scope::Scope};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// A well-known policy code.
|
||||
#[derive(Deserialize, Debug, Clone, Copy)]
|
||||
#[derive(Deserialize, Debug, Clone, Copy, JsonSchema)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
|
||||
pub enum Code {
|
||||
/// The username is too short.
|
||||
UsernameTooShort,
|
||||
@@ -71,8 +71,7 @@ impl Code {
|
||||
}
|
||||
|
||||
/// A single violation of a policy.
|
||||
#[derive(Deserialize, Debug)]
|
||||
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
|
||||
#[derive(Deserialize, Debug, JsonSchema)]
|
||||
pub struct Violation {
|
||||
pub msg: String,
|
||||
pub redirect_uri: Option<String>,
|
||||
@@ -111,9 +110,8 @@ impl EvaluationResult {
|
||||
}
|
||||
|
||||
/// Identity of the requester
|
||||
#[derive(Serialize, Debug, Default)]
|
||||
#[derive(Serialize, Debug, Default, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
|
||||
pub struct Requester {
|
||||
/// IP address of the entity making the request
|
||||
pub ip_address: Option<IpAddr>,
|
||||
@@ -122,8 +120,7 @@ pub struct Requester {
|
||||
pub user_agent: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
|
||||
#[derive(Serialize, Debug, JsonSchema)]
|
||||
pub enum RegistrationMethod {
|
||||
#[serde(rename = "password")]
|
||||
Password,
|
||||
@@ -133,9 +130,8 @@ pub enum RegistrationMethod {
|
||||
}
|
||||
|
||||
/// Input for the user registration policy.
|
||||
#[derive(Serialize, Debug)]
|
||||
#[derive(Serialize, Debug, JsonSchema)]
|
||||
#[serde(tag = "registration_method")]
|
||||
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
|
||||
pub struct RegisterInput<'a> {
|
||||
pub registration_method: RegistrationMethod,
|
||||
|
||||
@@ -148,21 +144,16 @@ pub struct RegisterInput<'a> {
|
||||
}
|
||||
|
||||
/// Input for the client registration policy.
|
||||
#[derive(Serialize, Debug)]
|
||||
#[derive(Serialize, Debug, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
|
||||
pub struct ClientRegistrationInput<'a> {
|
||||
#[cfg_attr(
|
||||
feature = "jsonschema",
|
||||
schemars(with = "std::collections::HashMap<String, serde_json::Value>")
|
||||
)]
|
||||
#[schemars(with = "std::collections::HashMap<String, serde_json::Value>")]
|
||||
pub client_metadata: &'a VerifiedClientMetadata,
|
||||
pub requester: Requester,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
#[derive(Serialize, Debug, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
|
||||
pub enum GrantType {
|
||||
AuthorizationCode,
|
||||
ClientCredentials,
|
||||
@@ -171,23 +162,16 @@ pub enum GrantType {
|
||||
}
|
||||
|
||||
/// Input for the authorization grant policy.
|
||||
#[derive(Serialize, Debug)]
|
||||
#[derive(Serialize, Debug, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
|
||||
pub struct AuthorizationGrantInput<'a> {
|
||||
#[cfg_attr(
|
||||
feature = "jsonschema",
|
||||
schemars(with = "Option<std::collections::HashMap<String, serde_json::Value>>")
|
||||
)]
|
||||
#[schemars(with = "Option<std::collections::HashMap<String, serde_json::Value>>")]
|
||||
pub user: Option<&'a User>,
|
||||
|
||||
#[cfg_attr(
|
||||
feature = "jsonschema",
|
||||
schemars(with = "std::collections::HashMap<String, serde_json::Value>")
|
||||
)]
|
||||
#[schemars(with = "std::collections::HashMap<String, serde_json::Value>")]
|
||||
pub client: &'a Client,
|
||||
|
||||
#[cfg_attr(feature = "jsonschema", schemars(with = "String"))]
|
||||
#[schemars(with = "String")]
|
||||
pub scope: &'a Scope,
|
||||
|
||||
pub grant_type: GrantType,
|
||||
@@ -196,9 +180,8 @@ pub struct AuthorizationGrantInput<'a> {
|
||||
}
|
||||
|
||||
/// Input for the email add policy.
|
||||
#[derive(Serialize, Debug)]
|
||||
#[derive(Serialize, Debug, JsonSchema)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))]
|
||||
pub struct EmailInput<'a> {
|
||||
pub email: &'a str,
|
||||
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ cargo run -p mas-config > "${CONFIG_SCHEMA}"
|
||||
cargo run -p mas-handlers --bin graphql-schema > "${GRAPHQL_SCHEMA}"
|
||||
cargo run -p mas-handlers --bin api-schema > "${API_SCHEMA}"
|
||||
cargo run -p mas-i18n-scan -- --update "${BASE_DIR}/templates/" "${BASE_DIR}/translations/en.json"
|
||||
OUT_DIR="${POLICIES_SCHEMA}" cargo run -p mas-policy --features jsonschema
|
||||
OUT_DIR="${POLICIES_SCHEMA}" cargo run -p mas-policy
|
||||
|
||||
cd "${BASE_DIR}/frontend"
|
||||
npm run format
|
||||
|
||||
Reference in New Issue
Block a user