1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-08-07 17:03:01 +03:00

Make the SiteConfig available in the GraphQL context

This commit is contained in:
Quentin Gliech
2024-03-29 13:24:32 +01:00
parent aa2e2229bc
commit e080932906
4 changed files with 22 additions and 3 deletions

View File

@@ -194,8 +194,12 @@ impl Options {
// Listen for SIGHUP // Listen for SIGHUP
register_sighup(&templates, &activity_tracker)?; register_sighup(&templates, &activity_tracker)?;
let graphql_schema = let graphql_schema = mas_handlers::graphql_schema(
mas_handlers::graphql_schema(&pool, &policy_factory, homeserver_connection.clone()); &pool,
&policy_factory,
homeserver_connection.clone(),
site_config.clone(),
);
let state = { let state = {
let mut s = AppState { let mut s = AppState {

View File

@@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
use mas_data_model::SiteConfig;
use mas_matrix::HomeserverConnection; use mas_matrix::HomeserverConnection;
use mas_policy::Policy; use mas_policy::Policy;
use mas_storage::{BoxClock, BoxRepository, BoxRng, RepositoryError}; use mas_storage::{BoxClock, BoxRepository, BoxRng, RepositoryError};
@@ -25,6 +26,7 @@ pub trait State {
fn homeserver_connection(&self) -> &dyn HomeserverConnection<Error = anyhow::Error>; fn homeserver_connection(&self) -> &dyn HomeserverConnection<Error = anyhow::Error>;
fn clock(&self) -> BoxClock; fn clock(&self) -> BoxClock;
fn rng(&self) -> BoxRng; fn rng(&self) -> BoxRng;
fn site_config(&self) -> &SiteConfig;
} }
pub type BoxState = Box<dyn State + Send + Sync + 'static>; pub type BoxState = Box<dyn State + Send + Sync + 'static>;

View File

@@ -31,7 +31,7 @@ use hyper::header::CACHE_CONTROL;
use mas_axum_utils::{ use mas_axum_utils::{
cookies::CookieJar, sentry::SentryEventID, FancyError, SessionInfo, SessionInfoExt, cookies::CookieJar, sentry::SentryEventID, FancyError, SessionInfo, SessionInfoExt,
}; };
use mas_data_model::User; use mas_data_model::{SiteConfig, User};
use mas_graphql::{Requester, Schema}; use mas_graphql::{Requester, Schema};
use mas_matrix::HomeserverConnection; use mas_matrix::HomeserverConnection;
use mas_policy::{InstantiateError, Policy, PolicyFactory}; use mas_policy::{InstantiateError, Policy, PolicyFactory};
@@ -54,6 +54,7 @@ struct GraphQLState {
pool: PgPool, pool: PgPool,
homeserver_connection: Arc<dyn HomeserverConnection<Error = anyhow::Error>>, homeserver_connection: Arc<dyn HomeserverConnection<Error = anyhow::Error>>,
policy_factory: Arc<PolicyFactory>, policy_factory: Arc<PolicyFactory>,
site_config: SiteConfig,
} }
#[async_trait] #[async_trait]
@@ -70,6 +71,10 @@ impl mas_graphql::State for GraphQLState {
self.policy_factory.instantiate().await self.policy_factory.instantiate().await
} }
fn site_config(&self) -> &SiteConfig {
&self.site_config
}
fn homeserver_connection(&self) -> &dyn HomeserverConnection<Error = anyhow::Error> { fn homeserver_connection(&self) -> &dyn HomeserverConnection<Error = anyhow::Error> {
self.homeserver_connection.as_ref() self.homeserver_connection.as_ref()
} }
@@ -93,11 +98,13 @@ pub fn schema(
pool: &PgPool, pool: &PgPool,
policy_factory: &Arc<PolicyFactory>, policy_factory: &Arc<PolicyFactory>,
homeserver_connection: impl HomeserverConnection<Error = anyhow::Error> + 'static, homeserver_connection: impl HomeserverConnection<Error = anyhow::Error> + 'static,
site_config: SiteConfig,
) -> Schema { ) -> Schema {
let state = GraphQLState { let state = GraphQLState {
pool: pool.clone(), pool: pool.clone(),
policy_factory: Arc::clone(policy_factory), policy_factory: Arc::clone(policy_factory),
homeserver_connection: Arc::new(homeserver_connection), homeserver_connection: Arc::new(homeserver_connection),
site_config,
}; };
let state: mas_graphql::BoxState = Box::new(state); let state: mas_graphql::BoxState = Box::new(state);

View File

@@ -193,6 +193,7 @@ impl TestState {
pool: pool.clone(), pool: pool.clone(),
policy_factory: Arc::clone(&policy_factory), policy_factory: Arc::clone(&policy_factory),
homeserver_connection: Arc::clone(&homeserver_connection), homeserver_connection: Arc::clone(&homeserver_connection),
site_config: site_config.clone(),
rng: Arc::clone(&rng), rng: Arc::clone(&rng),
clock: Arc::clone(&clock), clock: Arc::clone(&clock),
}; };
@@ -307,6 +308,7 @@ impl TestState {
struct TestGraphQLState { struct TestGraphQLState {
pool: PgPool, pool: PgPool,
homeserver_connection: Arc<MockHomeserverConnection>, homeserver_connection: Arc<MockHomeserverConnection>,
site_config: SiteConfig,
policy_factory: Arc<PolicyFactory>, policy_factory: Arc<PolicyFactory>,
clock: Arc<MockClock>, clock: Arc<MockClock>,
rng: Arc<Mutex<ChaChaRng>>, rng: Arc<Mutex<ChaChaRng>>,
@@ -336,6 +338,10 @@ impl mas_graphql::State for TestGraphQLState {
Box::new(self.clock.clone()) Box::new(self.clock.clone())
} }
fn site_config(&self) -> &SiteConfig {
&self.site_config
}
fn rng(&self) -> BoxRng { fn rng(&self) -> BoxRng {
let mut parent_rng = self.rng.lock().expect("Failed to lock RNG"); let mut parent_rng = self.rng.lock().expect("Failed to lock RNG");
let rng = ChaChaRng::from_rng(&mut *parent_rng).expect("Failed to seed RNG"); let rng = ChaChaRng::from_rng(&mut *parent_rng).expect("Failed to seed RNG");