mirror of
https://github.com/element-hq/matrix-authentication-service.git
synced 2026-09-17 03:44:55 +00:00
Inject the version in the app state
This commit is contained in:
@@ -9,7 +9,7 @@ use std::{convert::Infallible, net::IpAddr, sync::Arc};
|
||||
use axum::extract::{FromRef, FromRequestParts};
|
||||
use ipnetwork::IpNetwork;
|
||||
use mas_context::LogContext;
|
||||
use mas_data_model::{BoxClock, BoxRng, SiteConfig, SystemClock};
|
||||
use mas_data_model::{AppVersion, BoxClock, BoxRng, SiteConfig, SystemClock};
|
||||
use mas_handlers::{
|
||||
ActivityTracker, BoundActivityTracker, CookieManager, ErrorWrapper, GraphQLSchema, Limiter,
|
||||
MetadataCache, RequesterFingerprint, passwords::PasswordManager,
|
||||
@@ -27,7 +27,7 @@ use rand::SeedableRng;
|
||||
use sqlx::PgPool;
|
||||
use tracing::Instrument;
|
||||
|
||||
use crate::telemetry::METER;
|
||||
use crate::{VERSION, telemetry::METER};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
@@ -214,6 +214,12 @@ impl FromRef<AppState> for Arc<dyn HomeserverConnection> {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRef<AppState> for AppVersion {
|
||||
fn from_ref(_input: &AppState) -> Self {
|
||||
AppVersion(VERSION)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRequestParts<AppState> for BoxClock {
|
||||
type Rejection = Infallible;
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ pub(crate) mod upstream_oauth2;
|
||||
pub(crate) mod user_agent;
|
||||
pub(crate) mod users;
|
||||
mod utils;
|
||||
mod version;
|
||||
|
||||
/// Error when an invalid state transition is attempted.
|
||||
#[derive(Debug, Error)]
|
||||
@@ -57,4 +58,5 @@ pub use self::{
|
||||
UserRecoveryTicket, UserRegistration, UserRegistrationPassword, UserRegistrationToken,
|
||||
},
|
||||
utils::{BoxClock, BoxRng},
|
||||
version::AppVersion,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2025 New Vector Ltd.
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
// Please see LICENSE files in the repository root for full details.
|
||||
|
||||
/// A structure which holds information about the running version of the app
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct AppVersion(pub &'static str);
|
||||
@@ -20,7 +20,7 @@ use axum::{
|
||||
use hyper::header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE};
|
||||
use indexmap::IndexMap;
|
||||
use mas_axum_utils::InternalError;
|
||||
use mas_data_model::{BoxRng, SiteConfig};
|
||||
use mas_data_model::{AppVersion, BoxRng, SiteConfig};
|
||||
use mas_http::CorsLayerExt;
|
||||
use mas_matrix::HomeserverConnection;
|
||||
use mas_policy::PolicyFactory;
|
||||
@@ -164,6 +164,7 @@ where
|
||||
UrlBuilder: FromRef<S>,
|
||||
Arc<PolicyFactory>: FromRef<S>,
|
||||
SiteConfig: FromRef<S>,
|
||||
AppVersion: FromRef<S>,
|
||||
{
|
||||
// We *always* want to explicitly set the possible responses, beacuse the
|
||||
// infered ones are not necessarily correct
|
||||
|
||||
@@ -60,6 +60,7 @@ impl_from_ref!(mas_keystore::Keystore);
|
||||
impl_from_ref!(mas_handlers::passwords::PasswordManager);
|
||||
impl_from_ref!(Arc<mas_policy::PolicyFactory>);
|
||||
impl_from_ref!(mas_data_model::SiteConfig);
|
||||
impl_from_ref!(mas_data_model::AppVersion);
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let (mut api, _) = mas_handlers::admin_api_router::<DummyState>();
|
||||
|
||||
@@ -28,7 +28,7 @@ use mas_axum_utils::{
|
||||
cookies::{CookieJar, CookieManager},
|
||||
};
|
||||
use mas_config::RateLimitingConfig;
|
||||
use mas_data_model::{BoxClock, BoxRng, SiteConfig, clock::MockClock};
|
||||
use mas_data_model::{AppVersion, BoxClock, BoxRng, SiteConfig, clock::MockClock};
|
||||
use mas_email::{MailTransport, Mailer};
|
||||
use mas_i18n::Translator;
|
||||
use mas_keystore::{Encrypter, JsonWebKey, JsonWebKeySet, Keystore, PrivateKey};
|
||||
@@ -575,6 +575,12 @@ impl FromRef<TestState> for reqwest::Client {
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRef<TestState> for AppVersion {
|
||||
fn from_ref(_input: &TestState) -> Self {
|
||||
AppVersion("v0.0.0-test")
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRequestParts<TestState> for ActivityTracker {
|
||||
type Rejection = Infallible;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user