Skip to content

Commit 16f443e

Browse files
committed
Merge branch 'main' into rei/policy_driven_session_limit
2 parents 08959fa + a20cd1d commit 16f443e

File tree

30 files changed

+2751
-5370
lines changed

30 files changed

+2751
-5370
lines changed

Cargo.lock

Lines changed: 48 additions & 59 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ members = ["crates/*"]
99
resolver = "2"
1010

1111
# Updated in the CI with a `sed` command
12-
package.version = "1.6.0-rc.0"
12+
package.version = "1.6.0"
1313
package.license = "AGPL-3.0-only OR LicenseRef-Element-Commercial"
1414
package.authors = ["Element Backend Team"]
1515
package.edition = "2024"
@@ -34,39 +34,39 @@ broken_intra_doc_links = "deny"
3434
[workspace.dependencies]
3535

3636
# Workspace crates
37-
mas-axum-utils = { path = "./crates/axum-utils/", version = "=1.6.0-rc.0" }
38-
mas-cli = { path = "./crates/cli/", version = "=1.6.0-rc.0" }
39-
mas-config = { path = "./crates/config/", version = "=1.6.0-rc.0" }
40-
mas-context = { path = "./crates/context/", version = "=1.6.0-rc.0" }
41-
mas-data-model = { path = "./crates/data-model/", version = "=1.6.0-rc.0" }
42-
mas-email = { path = "./crates/email/", version = "=1.6.0-rc.0" }
43-
mas-graphql = { path = "./crates/graphql/", version = "=1.6.0-rc.0" }
44-
mas-handlers = { path = "./crates/handlers/", version = "=1.6.0-rc.0" }
45-
mas-http = { path = "./crates/http/", version = "=1.6.0-rc.0" }
46-
mas-i18n = { path = "./crates/i18n/", version = "=1.6.0-rc.0" }
47-
mas-i18n-scan = { path = "./crates/i18n-scan/", version = "=1.6.0-rc.0" }
48-
mas-iana = { path = "./crates/iana/", version = "=1.6.0-rc.0" }
49-
mas-iana-codegen = { path = "./crates/iana-codegen/", version = "=1.6.0-rc.0" }
50-
mas-jose = { path = "./crates/jose/", version = "=1.6.0-rc.0" }
51-
mas-keystore = { path = "./crates/keystore/", version = "=1.6.0-rc.0" }
52-
mas-listener = { path = "./crates/listener/", version = "=1.6.0-rc.0" }
53-
mas-matrix = { path = "./crates/matrix/", version = "=1.6.0-rc.0" }
54-
mas-matrix-synapse = { path = "./crates/matrix-synapse/", version = "=1.6.0-rc.0" }
55-
mas-oidc-client = { path = "./crates/oidc-client/", version = "=1.6.0-rc.0" }
56-
mas-policy = { path = "./crates/policy/", version = "=1.6.0-rc.0" }
57-
mas-router = { path = "./crates/router/", version = "=1.6.0-rc.0" }
58-
mas-spa = { path = "./crates/spa/", version = "=1.6.0-rc.0" }
59-
mas-storage = { path = "./crates/storage/", version = "=1.6.0-rc.0" }
60-
mas-storage-pg = { path = "./crates/storage-pg/", version = "=1.6.0-rc.0" }
61-
mas-tasks = { path = "./crates/tasks/", version = "=1.6.0-rc.0" }
62-
mas-templates = { path = "./crates/templates/", version = "=1.6.0-rc.0" }
63-
mas-tower = { path = "./crates/tower/", version = "=1.6.0-rc.0" }
64-
oauth2-types = { path = "./crates/oauth2-types/", version = "=1.6.0-rc.0" }
65-
syn2mas = { path = "./crates/syn2mas", version = "=1.6.0-rc.0" }
37+
mas-axum-utils = { path = "./crates/axum-utils/", version = "=1.6.0" }
38+
mas-cli = { path = "./crates/cli/", version = "=1.6.0" }
39+
mas-config = { path = "./crates/config/", version = "=1.6.0" }
40+
mas-context = { path = "./crates/context/", version = "=1.6.0" }
41+
mas-data-model = { path = "./crates/data-model/", version = "=1.6.0" }
42+
mas-email = { path = "./crates/email/", version = "=1.6.0" }
43+
mas-graphql = { path = "./crates/graphql/", version = "=1.6.0" }
44+
mas-handlers = { path = "./crates/handlers/", version = "=1.6.0" }
45+
mas-http = { path = "./crates/http/", version = "=1.6.0" }
46+
mas-i18n = { path = "./crates/i18n/", version = "=1.6.0" }
47+
mas-i18n-scan = { path = "./crates/i18n-scan/", version = "=1.6.0" }
48+
mas-iana = { path = "./crates/iana/", version = "=1.6.0" }
49+
mas-iana-codegen = { path = "./crates/iana-codegen/", version = "=1.6.0" }
50+
mas-jose = { path = "./crates/jose/", version = "=1.6.0" }
51+
mas-keystore = { path = "./crates/keystore/", version = "=1.6.0" }
52+
mas-listener = { path = "./crates/listener/", version = "=1.6.0" }
53+
mas-matrix = { path = "./crates/matrix/", version = "=1.6.0" }
54+
mas-matrix-synapse = { path = "./crates/matrix-synapse/", version = "=1.6.0" }
55+
mas-oidc-client = { path = "./crates/oidc-client/", version = "=1.6.0" }
56+
mas-policy = { path = "./crates/policy/", version = "=1.6.0" }
57+
mas-router = { path = "./crates/router/", version = "=1.6.0" }
58+
mas-spa = { path = "./crates/spa/", version = "=1.6.0" }
59+
mas-storage = { path = "./crates/storage/", version = "=1.6.0" }
60+
mas-storage-pg = { path = "./crates/storage-pg/", version = "=1.6.0" }
61+
mas-tasks = { path = "./crates/tasks/", version = "=1.6.0" }
62+
mas-templates = { path = "./crates/templates/", version = "=1.6.0" }
63+
mas-tower = { path = "./crates/tower/", version = "=1.6.0" }
64+
oauth2-types = { path = "./crates/oauth2-types/", version = "=1.6.0" }
65+
syn2mas = { path = "./crates/syn2mas", version = "=1.6.0" }
6666

6767
# OpenAPI schema generation and validation
6868
[workspace.dependencies.aide]
69-
version = "0.14.2"
69+
version = "0.15.1"
7070
features = ["axum", "axum-extra", "axum-extra-query", "axum-json", "macros"]
7171

7272
# An `Arc` that can be atomically updated
@@ -336,7 +336,7 @@ features = ["yaml", "json"]
336336
# IP network address types
337337
[workspace.dependencies.ipnetwork]
338338
version = "0.20.0"
339-
features = ["serde", "schemars"]
339+
features = ["serde"]
340340

341341
# Iterator utilities
342342
[workspace.dependencies.itertools]
@@ -541,8 +541,8 @@ version = "0.4.5"
541541

542542
# JSON Schema generation
543543
[workspace.dependencies.schemars]
544-
version = "0.8.22"
545-
features = ["url", "chrono", "preserve_order"]
544+
version = "0.9.0"
545+
features = ["url2", "chrono04", "preserve_order"]
546546

547547
# SEC1 encoding format
548548
[workspace.dependencies.sec1]

crates/cli/src/server.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,23 @@ fn make_http_span<B>(req: &Request<B>) -> Span {
136136
span.record(USER_AGENT_ORIGINAL, user_agent);
137137
}
138138

139-
// Extract the parent span context from the request headers
140-
let parent_context = opentelemetry::global::get_text_map_propagator(|propagator| {
141-
let extractor = HeaderExtractor(req.headers());
142-
let context = opentelemetry::Context::new();
143-
propagator.extract_with_context(&context, &extractor)
144-
});
145-
146-
if let Err(err) = span.set_parent(parent_context) {
147-
tracing::error!(
148-
error = &err as &dyn std::error::Error,
149-
"Failed to set parent context on span"
150-
);
139+
// In case the span is disabled by any of tracing layers, e.g. if `RUST_LOG`
140+
// is set to `warn`, `set_parent` will fail. So we only try to set the
141+
// parent context if the span is not disabled.
142+
if !span.is_disabled() {
143+
// Extract the parent span context from the request headers
144+
let parent_context = opentelemetry::global::get_text_map_propagator(|propagator| {
145+
let extractor = HeaderExtractor(req.headers());
146+
let context = opentelemetry::Context::new();
147+
propagator.extract_with_context(&context, &extractor)
148+
});
149+
150+
if let Err(err) = span.set_parent(parent_context) {
151+
tracing::error!(
152+
error = &err as &dyn std::error::Error,
153+
"Failed to set parent context on span"
154+
);
155+
}
151156
}
152157

153158
span

crates/config/src/bin/schema.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,10 @@
44
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
55
// Please see LICENSE files in the repository root for full details.
66

7-
use schemars::r#gen::SchemaSettings;
7+
use schemars::generate::SchemaSettings;
88

99
fn main() {
10-
let settings = SchemaSettings::draft07().with(|s| {
11-
s.option_nullable = false;
12-
s.option_add_null_type = false;
13-
});
14-
let generator = settings.into_generator();
10+
let generator = SchemaSettings::draft07().into_generator();
1511
let schema = generator.into_root_schema_for::<mas_config::RootConfig>();
1612

1713
serde_json::to_writer_pretty(std::io::stdout(), &schema).expect("Failed to serialize schema");

crates/config/src/schema.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,22 @@
66

77
//! Useful JSON Schema definitions
88
9-
use schemars::{
10-
JsonSchema,
11-
r#gen::SchemaGenerator,
12-
schema::{InstanceType, Schema, SchemaObject},
13-
};
9+
use std::borrow::Cow;
10+
11+
use schemars::{JsonSchema, Schema, SchemaGenerator, json_schema};
1412

1513
/// A network hostname
1614
pub struct Hostname;
1715

1816
impl JsonSchema for Hostname {
19-
fn schema_name() -> String {
20-
"Hostname".to_string()
17+
fn schema_name() -> Cow<'static, str> {
18+
Cow::Borrowed("Hostname")
2119
}
2220

23-
fn json_schema(generator: &mut SchemaGenerator) -> Schema {
24-
hostname(generator)
21+
fn json_schema(_generator: &mut SchemaGenerator) -> Schema {
22+
json_schema!({
23+
"type": "string",
24+
"format": "hostname",
25+
})
2526
}
2627
}
27-
28-
fn hostname(_gen: &mut SchemaGenerator) -> Schema {
29-
Schema::Object(SchemaObject {
30-
instance_type: Some(InstanceType::String.into()),
31-
format: Some("hostname".to_owned()),
32-
..SchemaObject::default()
33-
})
34-
}

crates/config/src/sections/http.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,6 @@ fn default_public_base() -> Url {
2323
"http://[::]:8080".parse().unwrap()
2424
}
2525

26-
fn http_address_example_1() -> &'static str {
27-
"[::1]:8080"
28-
}
29-
fn http_address_example_2() -> &'static str {
30-
"[::]:8080"
31-
}
32-
fn http_address_example_3() -> &'static str {
33-
"127.0.0.1:8080"
34-
}
35-
fn http_address_example_4() -> &'static str {
36-
"0.0.0.0:8080"
37-
}
38-
3926
#[cfg(not(any(feature = "docker", feature = "dist")))]
4027
fn http_listener_assets_path_default() -> Utf8PathBuf {
4128
"./frontend/dist/".into()
@@ -111,10 +98,10 @@ pub enum BindConfig {
11198
Address {
11299
/// Host and port on which to listen
113100
#[schemars(
114-
example = "http_address_example_1",
115-
example = "http_address_example_2",
116-
example = "http_address_example_3",
117-
example = "http_address_example_4"
101+
example = &"[::1]:8080",
102+
example = &"[::]:8080",
103+
example = &"127.0.0.1:8080",
104+
example = &"0.0.0.0:8080",
118105
)]
119106
address: String,
120107
},
@@ -354,6 +341,7 @@ pub struct HttpConfig {
354341
/// List of trusted reverse proxies that can set the `X-Forwarded-For`
355342
/// header
356343
#[serde(default = "default_trusted_proxies")]
344+
#[schemars(with = "Vec<String>", inner(ip))]
357345
pub trusted_proxies: Vec<IpNetwork>,
358346

359347
/// Public URL base from where the authentication service is reachable

crates/config/src/sections/secrets.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ use tracing::info;
2020

2121
use super::ConfigurationSection;
2222

23-
fn example_secret() -> &'static str {
24-
"0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff"
25-
}
26-
2723
/// Password config option.
2824
///
2925
/// It either holds the password value directly or references a file where the
@@ -209,7 +205,7 @@ struct EncryptionRaw {
209205
#[schemars(
210206
with = "Option<String>",
211207
regex(pattern = r"[0-9a-fA-F]{64}"),
212-
example = "example_secret"
208+
example = &"0000111122223333444455556666777788889999aaaabbbbccccddddeeeeffff"
213209
)]
214210
#[serde_as(as = "Option<serde_with::hex::Hex>")]
215211
#[serde(skip_serializing_if = "Option::is_none")]

crates/config/src/sections/telemetry.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ use url::Url;
1111

1212
use super::ConfigurationSection;
1313

14-
fn sample_rate_example() -> f64 {
15-
0.5
16-
}
17-
1814
/// Propagation format for incoming and outgoing requests
1915
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)]
2016
#[serde(rename_all = "lowercase")]
@@ -70,7 +66,7 @@ pub struct TracingConfig {
7066
///
7167
/// Defaults to `1.0` if not set.
7268
#[serde(skip_serializing_if = "Option::is_none")]
73-
#[schemars(example = "sample_rate_example", range(min = 0.0, max = 1.0))]
69+
#[schemars(example = 0.5, range(min = 0.0, max = 1.0))]
7470
pub sample_rate: Option<f64>,
7571
}
7672

@@ -123,41 +119,33 @@ impl MetricsConfig {
123119
}
124120
}
125121

126-
fn sentry_dsn_example() -> &'static str {
127-
"https://public@host:port/1"
128-
}
129-
130-
fn sentry_environment_example() -> &'static str {
131-
"production"
132-
}
133-
134122
/// Configuration related to the Sentry integration
135123
#[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)]
136124
pub struct SentryConfig {
137125
/// Sentry DSN
138-
#[schemars(url, example = "sentry_dsn_example")]
126+
#[schemars(url, example = &"https://public@host:port/1")]
139127
#[serde(skip_serializing_if = "Option::is_none")]
140128
pub dsn: Option<String>,
141129

142130
/// Environment to use when sending events to Sentry
143131
///
144132
/// Defaults to `production` if not set.
145-
#[schemars(example = "sentry_environment_example")]
133+
#[schemars(example = &"production")]
146134
#[serde(skip_serializing_if = "Option::is_none")]
147135
pub environment: Option<String>,
148136

149137
/// Sample rate for event submissions
150138
///
151139
/// Defaults to `1.0` if not set.
152140
#[serde(skip_serializing_if = "Option::is_none")]
153-
#[schemars(example = "sample_rate_example", range(min = 0.0, max = 1.0))]
141+
#[schemars(example = 0.5, range(min = 0.0, max = 1.0))]
154142
pub sample_rate: Option<f32>,
155143

156144
/// Sample rate for tracing transactions
157145
///
158146
/// Defaults to `0.0` if not set.
159147
#[serde(skip_serializing_if = "Option::is_none")]
160-
#[schemars(example = "sample_rate_example", range(min = 0.0, max = 1.0))]
148+
#[schemars(example = 0.5, range(min = 0.0, max = 1.0))]
161149
pub traces_sample_rate: Option<f32>,
162150
}
163151

crates/context/src/fmt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tracing_subscriber::{
1818

1919
use crate::LogContext;
2020

21-
/// An event formatter usable by the [`tracing-subscriber`] crate, which
21+
/// An event formatter usable by the [`tracing_subscriber`] crate, which
2222
/// includes the log context and the OTEL trace ID.
2323
#[derive(Debug, Default)]
2424
pub struct EventFormatter;

crates/handlers/src/admin/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use mas_router::{
2929
UrlBuilder,
3030
};
3131
use mas_templates::{ApiDocContext, Templates};
32+
use schemars::transform::AddNullable;
3233
use tower_http::cors::{Any, CorsLayer};
3334

3435
mod call_context;
@@ -171,8 +172,16 @@ where
171172
aide::generate::infer_responses(false);
172173

173174
aide::generate::in_context(|ctx| {
174-
ctx.schema =
175-
schemars::r#gen::SchemaGenerator::new(schemars::r#gen::SchemaSettings::openapi3());
175+
ctx.schema = schemars::generate::SchemaGenerator::new(
176+
schemars::generate::SchemaSettings::openapi3().with(|settings| {
177+
// Remove the transform which adds nullable fields, as it's not
178+
// valid with OpenAPI 3.1. For some reason, aide/schemars output
179+
// an OpenAPI 3.1 schema with this nullable transform.
180+
settings
181+
.transforms
182+
.retain(|transform| !transform.is::<AddNullable>());
183+
}),
184+
);
176185
});
177186

178187
let mut api = OpenApi::default();

0 commit comments

Comments
 (0)