Skip to content

Commit 377ef1d

Browse files
committed
Inject the version in the app state
1 parent e08ab75 commit 377ef1d

File tree

6 files changed

+28
-4
lines changed

6 files changed

+28
-4
lines changed

crates/cli/src/app_state.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::{convert::Infallible, net::IpAddr, sync::Arc};
99
use axum::extract::{FromRef, FromRequestParts};
1010
use ipnetwork::IpNetwork;
1111
use mas_context::LogContext;
12-
use mas_data_model::{BoxClock, BoxRng, SiteConfig, SystemClock};
12+
use mas_data_model::{AppVersion, BoxClock, BoxRng, SiteConfig, SystemClock};
1313
use mas_handlers::{
1414
ActivityTracker, BoundActivityTracker, CookieManager, ErrorWrapper, GraphQLSchema, Limiter,
1515
MetadataCache, RequesterFingerprint, passwords::PasswordManager,
@@ -27,7 +27,7 @@ use rand::SeedableRng;
2727
use sqlx::PgPool;
2828
use tracing::Instrument;
2929

30-
use crate::telemetry::METER;
30+
use crate::{VERSION, telemetry::METER};
3131

3232
#[derive(Clone)]
3333
pub struct AppState {
@@ -214,6 +214,12 @@ impl FromRef<AppState> for Arc<dyn HomeserverConnection> {
214214
}
215215
}
216216

217+
impl FromRef<AppState> for AppVersion {
218+
fn from_ref(_input: &AppState) -> Self {
219+
AppVersion(VERSION)
220+
}
221+
}
222+
217223
impl FromRequestParts<AppState> for BoxClock {
218224
type Rejection = Infallible;
219225

crates/data-model/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub(crate) mod upstream_oauth2;
1818
pub(crate) mod user_agent;
1919
pub(crate) mod users;
2020
mod utils;
21+
mod version;
2122

2223
/// Error when an invalid state transition is attempted.
2324
#[derive(Debug, Error)]
@@ -57,4 +58,5 @@ pub use self::{
5758
UserRecoveryTicket, UserRegistration, UserRegistrationPassword, UserRegistrationToken,
5859
},
5960
utils::{BoxClock, BoxRng},
61+
version::AppVersion,
6062
};

crates/data-model/src/version.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Copyright 2025 New Vector Ltd.
2+
//
3+
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
4+
// Please see LICENSE files in the repository root for full details.
5+
6+
/// A structure which holds information about the running version of the app
7+
#[derive(Debug, Clone, Copy)]
8+
pub struct AppVersion(pub &'static str);

crates/handlers/src/admin/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use axum::{
2020
use hyper::header::{ACCEPT, AUTHORIZATION, CONTENT_TYPE};
2121
use indexmap::IndexMap;
2222
use mas_axum_utils::InternalError;
23-
use mas_data_model::{BoxRng, SiteConfig};
23+
use mas_data_model::{AppVersion, BoxRng, SiteConfig};
2424
use mas_http::CorsLayerExt;
2525
use mas_matrix::HomeserverConnection;
2626
use mas_policy::PolicyFactory;
@@ -164,6 +164,7 @@ where
164164
UrlBuilder: FromRef<S>,
165165
Arc<PolicyFactory>: FromRef<S>,
166166
SiteConfig: FromRef<S>,
167+
AppVersion: FromRef<S>,
167168
{
168169
// We *always* want to explicitly set the possible responses, beacuse the
169170
// infered ones are not necessarily correct

crates/handlers/src/bin/api-schema.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ impl_from_ref!(mas_keystore::Keystore);
6060
impl_from_ref!(mas_handlers::passwords::PasswordManager);
6161
impl_from_ref!(Arc<mas_policy::PolicyFactory>);
6262
impl_from_ref!(mas_data_model::SiteConfig);
63+
impl_from_ref!(mas_data_model::AppVersion);
6364

6465
fn main() -> Result<(), Box<dyn std::error::Error>> {
6566
let (mut api, _) = mas_handlers::admin_api_router::<DummyState>();

crates/handlers/src/test_utils.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use mas_axum_utils::{
2828
cookies::{CookieJar, CookieManager},
2929
};
3030
use mas_config::RateLimitingConfig;
31-
use mas_data_model::{BoxClock, BoxRng, SiteConfig, clock::MockClock};
31+
use mas_data_model::{AppVersion, BoxClock, BoxRng, SiteConfig, clock::MockClock};
3232
use mas_email::{MailTransport, Mailer};
3333
use mas_i18n::Translator;
3434
use mas_keystore::{Encrypter, JsonWebKey, JsonWebKeySet, Keystore, PrivateKey};
@@ -575,6 +575,12 @@ impl FromRef<TestState> for reqwest::Client {
575575
}
576576
}
577577

578+
impl FromRef<TestState> for AppVersion {
579+
fn from_ref(_input: &TestState) -> Self {
580+
AppVersion("v0.0.0-test")
581+
}
582+
}
583+
578584
impl FromRequestParts<TestState> for ActivityTracker {
579585
type Rejection = Infallible;
580586

0 commit comments

Comments
 (0)