You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-08-06 06:02:40 +03:00
Make the SiteConfig available in the GraphQL context
This commit is contained in:
@@ -194,8 +194,12 @@ impl Options {
|
||||
// Listen for SIGHUP
|
||||
register_sighup(&templates, &activity_tracker)?;
|
||||
|
||||
let graphql_schema =
|
||||
mas_handlers::graphql_schema(&pool, &policy_factory, homeserver_connection.clone());
|
||||
let graphql_schema = mas_handlers::graphql_schema(
|
||||
&pool,
|
||||
&policy_factory,
|
||||
homeserver_connection.clone(),
|
||||
site_config.clone(),
|
||||
);
|
||||
|
||||
let state = {
|
||||
let mut s = AppState {
|
||||
|
@@ -12,6 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
use mas_data_model::SiteConfig;
|
||||
use mas_matrix::HomeserverConnection;
|
||||
use mas_policy::Policy;
|
||||
use mas_storage::{BoxClock, BoxRepository, BoxRng, RepositoryError};
|
||||
@@ -25,6 +26,7 @@ pub trait State {
|
||||
fn homeserver_connection(&self) -> &dyn HomeserverConnection<Error = anyhow::Error>;
|
||||
fn clock(&self) -> BoxClock;
|
||||
fn rng(&self) -> BoxRng;
|
||||
fn site_config(&self) -> &SiteConfig;
|
||||
}
|
||||
|
||||
pub type BoxState = Box<dyn State + Send + Sync + 'static>;
|
||||
|
@@ -31,7 +31,7 @@ use hyper::header::CACHE_CONTROL;
|
||||
use mas_axum_utils::{
|
||||
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_matrix::HomeserverConnection;
|
||||
use mas_policy::{InstantiateError, Policy, PolicyFactory};
|
||||
@@ -54,6 +54,7 @@ struct GraphQLState {
|
||||
pool: PgPool,
|
||||
homeserver_connection: Arc<dyn HomeserverConnection<Error = anyhow::Error>>,
|
||||
policy_factory: Arc<PolicyFactory>,
|
||||
site_config: SiteConfig,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
@@ -70,6 +71,10 @@ impl mas_graphql::State for GraphQLState {
|
||||
self.policy_factory.instantiate().await
|
||||
}
|
||||
|
||||
fn site_config(&self) -> &SiteConfig {
|
||||
&self.site_config
|
||||
}
|
||||
|
||||
fn homeserver_connection(&self) -> &dyn HomeserverConnection<Error = anyhow::Error> {
|
||||
self.homeserver_connection.as_ref()
|
||||
}
|
||||
@@ -93,11 +98,13 @@ pub fn schema(
|
||||
pool: &PgPool,
|
||||
policy_factory: &Arc<PolicyFactory>,
|
||||
homeserver_connection: impl HomeserverConnection<Error = anyhow::Error> + 'static,
|
||||
site_config: SiteConfig,
|
||||
) -> Schema {
|
||||
let state = GraphQLState {
|
||||
pool: pool.clone(),
|
||||
policy_factory: Arc::clone(policy_factory),
|
||||
homeserver_connection: Arc::new(homeserver_connection),
|
||||
site_config,
|
||||
};
|
||||
let state: mas_graphql::BoxState = Box::new(state);
|
||||
|
||||
|
@@ -193,6 +193,7 @@ impl TestState {
|
||||
pool: pool.clone(),
|
||||
policy_factory: Arc::clone(&policy_factory),
|
||||
homeserver_connection: Arc::clone(&homeserver_connection),
|
||||
site_config: site_config.clone(),
|
||||
rng: Arc::clone(&rng),
|
||||
clock: Arc::clone(&clock),
|
||||
};
|
||||
@@ -307,6 +308,7 @@ impl TestState {
|
||||
struct TestGraphQLState {
|
||||
pool: PgPool,
|
||||
homeserver_connection: Arc<MockHomeserverConnection>,
|
||||
site_config: SiteConfig,
|
||||
policy_factory: Arc<PolicyFactory>,
|
||||
clock: Arc<MockClock>,
|
||||
rng: Arc<Mutex<ChaChaRng>>,
|
||||
@@ -336,6 +338,10 @@ impl mas_graphql::State for TestGraphQLState {
|
||||
Box::new(self.clock.clone())
|
||||
}
|
||||
|
||||
fn site_config(&self) -> &SiteConfig {
|
||||
&self.site_config
|
||||
}
|
||||
|
||||
fn rng(&self) -> BoxRng {
|
||||
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");
|
||||
|
Reference in New Issue
Block a user