1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-08-06 06:02:40 +03:00

Allow disabling registrations (#2553)

This commit is contained in:
Quentin Gliech
2024-04-03 09:27:14 +02:00
committed by GitHub
parent e3944d1f34
commit 58fd6ab4c1
21 changed files with 308 additions and 164 deletions

View File

@@ -19,7 +19,7 @@ use clap::Parser;
use figment::Figment;
use itertools::Itertools;
use mas_config::{AppConfig, ClientsConfig, ConfigurationSection, UpstreamOAuth2Config};
use mas_handlers::{ActivityTracker, CookieManager, HttpClientFactory, MetadataCache, SiteConfig};
use mas_handlers::{ActivityTracker, CookieManager, HttpClientFactory, MetadataCache};
use mas_listener::{server::Server, shutdown::ShutdownStream};
use mas_matrix_synapse::SynapseConnection;
use mas_router::UrlBuilder;
@@ -37,7 +37,8 @@ use crate::{
app_state::AppState,
util::{
database_pool_from_config, mailer_from_config, password_manager_from_config,
policy_factory_from_config, register_sighup, templates_from_config,
policy_factory_from_config, register_sighup, site_config_from_config,
templates_from_config,
},
};
@@ -138,14 +139,17 @@ impl Options {
None,
);
// Load and compile the templates
let templates = templates_from_config(
&config.templates,
// Load the site configuration
let site_config = site_config_from_config(
&config.branding,
&url_builder,
&config.matrix.homeserver,
)
.await?;
&config.matrix,
&config.experimental,
&config.passwords,
);
// Load and compile the templates
let templates =
templates_from_config(&config.templates, &site_config, &url_builder).await?;
let http_client_factory = HttpClientFactory::new();
@@ -179,12 +183,6 @@ impl Options {
// The upstream OIDC metadata cache
let metadata_cache = MetadataCache::new();
let site_config = SiteConfig {
tos_uri: config.branding.tos_uri.clone(),
access_token_ttl: config.experimental.access_token_ttl,
compat_token_ttl: config.experimental.compat_token_ttl,
};
// Initialize the activity tracker
// Activity is flushed every minute
let activity_tracker = ActivityTracker::new(pool.clone(), Duration::from_secs(60));

View File

@@ -14,12 +14,15 @@
use clap::Parser;
use figment::Figment;
use mas_config::{BrandingConfig, ConfigurationSection, MatrixConfig, TemplatesConfig};
use mas_config::{
BrandingConfig, ConfigurationSection, ExperimentalConfig, MatrixConfig, PasswordsConfig,
TemplatesConfig,
};
use mas_storage::{Clock, SystemClock};
use rand::SeedableRng;
use tracing::info_span;
use crate::util::templates_from_config;
use crate::util::{site_config_from_config, templates_from_config};
#[derive(Parser, Debug)]
pub(super) struct Options {
@@ -43,19 +46,22 @@ impl Options {
let template_config = TemplatesConfig::extract(figment)?;
let branding_config = BrandingConfig::extract(figment)?;
let matrix_config = MatrixConfig::extract(figment)?;
let experimental_config = ExperimentalConfig::extract(figment)?;
let password_config = PasswordsConfig::extract(figment)?;
let clock = SystemClock::default();
// XXX: we should disallow SeedableRng::from_entropy
let mut rng = rand_chacha::ChaChaRng::from_entropy();
let url_builder =
mas_router::UrlBuilder::new("https://example.com/".parse()?, None, None);
let templates = templates_from_config(
&template_config,
let site_config = site_config_from_config(
&branding_config,
&url_builder,
&matrix_config.homeserver,
)
.await?;
&matrix_config,
&experimental_config,
&password_config,
);
let templates =
templates_from_config(&template_config, &site_config, &url_builder).await?;
templates.check_render(clock.now(), &mut rng)?;
Ok(())

View File

@@ -24,7 +24,9 @@ use rand::{
};
use tracing::{info, info_span};
use crate::util::{database_pool_from_config, mailer_from_config, templates_from_config};
use crate::util::{
database_pool_from_config, mailer_from_config, site_config_from_config, templates_from_config,
};
#[derive(Parser, Debug, Default)]
pub(super) struct Options {}
@@ -44,14 +46,17 @@ impl Options {
None,
);
// Load and compile the templates
let templates = templates_from_config(
&config.templates,
// Load the site configuration
let site_config = site_config_from_config(
&config.branding,
&url_builder,
&config.matrix.homeserver,
)
.await?;
&config.matrix,
&config.experimental,
&config.passwords,
);
// Load and compile the templates
let templates =
templates_from_config(&config.templates, &site_config, &url_builder).await?;
let mailer = mailer_from_config(&config.email, &templates)?;
mailer.test_connection().await?;