Move specific Synapse config out of RootConfig

This commit is contained in:
Eric Eastwood
2025-05-07 17:27:47 -05:00
parent ae877aa101
commit ffbdb9f2be
3 changed files with 37 additions and 31 deletions
-29
View File
@@ -101,28 +101,6 @@ def format_config_error(e: ConfigError) -> Iterator[str]:
parent_e = parent_e.__cause__
# We split these messages out to allow packages to override with package
# specific instructions.
MISSING_REPORT_STATS_CONFIG_INSTRUCTIONS = """\
Please opt in or out of reporting homeserver usage statistics, by setting
the `report_stats` key in your config file to either True or False.
"""
MISSING_REPORT_STATS_SPIEL = """\
We would really appreciate it if you could help our project out by reporting
homeserver usage statistics from your homeserver. Your homeserver's server name,
along with very basic aggregate data (e.g. number of users) will be reported. But
it helps us to track the growth of the Matrix community, and helps us to make Matrix
a success, as well as to convince other networks that they should peer with us.
Thank you.
"""
MISSING_SERVER_NAME = """\
Missing mandatory `server_name` config option.
"""
CONFIG_FILE_HEADER = """\
# Configuration file for Synapse.
#
@@ -929,13 +907,6 @@ def read_config_files(config_files: Iterable[str]) -> Dict[str, Any]:
specified_config.update(yaml_config)
if "server_name" not in specified_config:
raise ConfigError(MISSING_SERVER_NAME)
if "report_stats" not in specified_config:
raise ConfigError(
MISSING_REPORT_STATS_CONFIG_INSTRUCTIONS + "\n" + MISSING_REPORT_STATS_SPIEL
)
return specified_config
+26 -1
View File
@@ -29,6 +29,21 @@ from synapse.util.check_dependencies import check_requirements
from ._base import Config, ConfigError
MISSING_REPORT_STATS_CONFIG_INSTRUCTIONS = """\
Please opt in or out of reporting homeserver usage statistics, by setting
the `report_stats` key in your config file to either True or False.
"""
MISSING_REPORT_STATS_SPIEL = """\
We would really appreciate it if you could help our project out by reporting
homeserver usage statistics from your homeserver. Your homeserver's server name,
along with very basic aggregate data (e.g. number of users) will be reported. But
it helps us to track the growth of the Matrix community, and helps us to make Matrix
a success, as well as to convince other networks that they should peer with us.
Thank you.
"""
@attr.s
class MetricsFlags:
@@ -50,7 +65,17 @@ class MetricsConfig(Config):
def read_config(self, config: JsonDict, **kwargs: Any) -> None:
self.enable_metrics = config.get("enable_metrics", False)
self.report_stats = config.get("report_stats", None)
report_stats = config.get("report_stats", None)
if report_stats is None:
raise ConfigError(
MISSING_REPORT_STATS_CONFIG_INSTRUCTIONS
+ "\n"
+ MISSING_REPORT_STATS_SPIEL,
("report_stats",),
)
self.report_stats = report_stats
self.report_stats_endpoint = config.get(
"report_stats_endpoint", "https://matrix.org/report-usage-stats/push"
)
+11 -1
View File
@@ -49,6 +49,11 @@ Using direct TCP replication for workers is no longer supported.
Please see https://element-hq.github.io/synapse/latest/upgrade.html#direct-tcp-replication-is-no-longer-supported-migrate-to-redis
"""
MISSING_SERVER_NAME = """\
Missing mandatory `server_name` config option.
"""
# by default, we attempt to listen on both '::' *and* '0.0.0.0' because some OSes
# (Windows, macOS, other BSD/Linux where net.ipv6.bindv6only is set) will only listen
# on IPv6 when '::' is set.
@@ -295,9 +300,14 @@ class ServerConfig(Config):
section = "server"
def read_config(self, config: JsonDict, **kwargs: Any) -> None:
self.server_name = config["server_name"]
self.server_context = config.get("server_context", None)
server_name = config.get("server_name")
if server_name is None:
raise ConfigError(MISSING_SERVER_NAME, ("server_name",))
self.server_name = server_name
try:
parse_and_validate_server_name(self.server_name)
except ValueError as e: