67 lines
1.9 KiB
Rust
67 lines
1.9 KiB
Rust
// Copyright 2024 New Vector Ltd.
|
|
// Copyright 2023, 2024 The Matrix.org Foundation C.I.C.
|
|
//
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
// Please see LICENSE in the repository root for full details.
|
|
|
|
use chrono::Duration;
|
|
use schemars::JsonSchema;
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_with::serde_as;
|
|
|
|
use crate::ConfigurationSection;
|
|
|
|
fn default_token_ttl() -> Duration {
|
|
Duration::microseconds(5 * 60 * 1000 * 1000)
|
|
}
|
|
|
|
fn is_default_token_ttl(value: &Duration) -> bool {
|
|
*value == default_token_ttl()
|
|
}
|
|
|
|
/// Configuration sections for experimental options
|
|
///
|
|
/// Do not change these options unless you know what you are doing.
|
|
#[serde_as]
|
|
#[allow(clippy::struct_excessive_bools)]
|
|
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
|
|
pub struct ExperimentalConfig {
|
|
/// Time-to-live of access tokens in seconds. Defaults to 5 minutes.
|
|
#[schemars(with = "u64", range(min = 60, max = 86400))]
|
|
#[serde(
|
|
default = "default_token_ttl",
|
|
skip_serializing_if = "is_default_token_ttl"
|
|
)]
|
|
#[serde_as(as = "serde_with::DurationSeconds<i64>")]
|
|
pub access_token_ttl: Duration,
|
|
|
|
/// Time-to-live of compatibility access tokens in seconds. Defaults to 5
|
|
/// minutes.
|
|
#[schemars(with = "u64", range(min = 60, max = 86400))]
|
|
#[serde(
|
|
default = "default_token_ttl",
|
|
skip_serializing_if = "is_default_token_ttl"
|
|
)]
|
|
#[serde_as(as = "serde_with::DurationSeconds<i64>")]
|
|
pub compat_token_ttl: Duration,
|
|
}
|
|
|
|
impl Default for ExperimentalConfig {
|
|
fn default() -> Self {
|
|
Self {
|
|
access_token_ttl: default_token_ttl(),
|
|
compat_token_ttl: default_token_ttl(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl ExperimentalConfig {
|
|
pub(crate) fn is_default(&self) -> bool {
|
|
is_default_token_ttl(&self.access_token_ttl) && is_default_token_ttl(&self.compat_token_ttl)
|
|
}
|
|
}
|
|
|
|
impl ConfigurationSection for ExperimentalConfig {
|
|
const PATH: Option<&'static str> = Some("experimental");
|
|
}
|