Skip to content

Move specific Synapse config out of RootConfig #18410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/18410.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move specific Synapse config out of `RootConfig`.
29 changes: 0 additions & 29 deletions synapse/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,28 +101,6 @@
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.
#
Expand Down Expand Up @@ -774,7 +752,7 @@
if config_args.report_stats is None:
parser.error(
"Please specify either --report-stats=yes or --report-stats=no\n\n"
+ MISSING_REPORT_STATS_SPIEL

Check failure on line 755 in synapse/config/_base.py

View workflow job for this annotation

GitHub Actions / lint

Ruff (F821)

synapse/config/_base.py:755:23: F821 Undefined name `MISSING_REPORT_STATS_SPIEL`
)

(config_path,) = config_files
Expand Down Expand Up @@ -929,13 +907,6 @@

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


Expand Down
27 changes: 26 additions & 1 deletion synapse/config/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@

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:
Expand All @@ -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"
)
Expand Down
12 changes: 11 additions & 1 deletion synapse/config/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
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.
Expand Down Expand Up @@ -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:
Expand Down
Loading