Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 47854c7

Browse files
authored
Use direct references for configuration variables (part 4). (#10893)
1 parent a109889 commit 47854c7

32 files changed

+77
-64
lines changed

changelog.d/10893.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Use direct references to config flags.

synapse/api/urls.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ def __init__(self, hs_config):
3939
Args:
4040
hs_config (synapse.config.homeserver.HomeServerConfig):
4141
"""
42-
if hs_config.form_secret is None:
42+
if hs_config.key.form_secret is None:
4343
raise ConfigError("form_secret not set in config")
4444
if hs_config.server.public_baseurl is None:
4545
raise ConfigError("public_baseurl not set in config")
4646

47-
self._hmac_secret = hs_config.form_secret.encode("utf-8")
47+
self._hmac_secret = hs_config.key.form_secret.encode("utf-8")
4848
self._public_baseurl = hs_config.server.public_baseurl
4949

5050
def build_user_consent_uri(self, user_id):

synapse/app/_base.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,14 @@ def setup_sentry(hs):
424424
hs (synapse.server.HomeServer)
425425
"""
426426

427-
if not hs.config.sentry_enabled:
427+
if not hs.config.metrics.sentry_enabled:
428428
return
429429

430430
import sentry_sdk
431431

432-
sentry_sdk.init(dsn=hs.config.sentry_dsn, release=get_version_string(synapse))
432+
sentry_sdk.init(
433+
dsn=hs.config.metrics.sentry_dsn, release=get_version_string(synapse)
434+
)
433435

434436
# We set some default tags that give some context to this instance
435437
with sentry_sdk.configure_scope() as scope:

synapse/app/admin_cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def start(config_options):
192192
):
193193
# Since we're meant to be run as a "command" let's not redirect stdio
194194
# unless we've actually set log config.
195-
config.no_redirect_stdio = True
195+
config.logging.no_redirect_stdio = True
196196

197197
# Explicitly disable background processes
198198
config.update_user_directory = False

synapse/app/generic_worker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ def start_listening(self):
395395
manhole_globals={"hs": self},
396396
)
397397
elif listener.type == "metrics":
398-
if not self.config.enable_metrics:
398+
if not self.config.metrics.enable_metrics:
399399
logger.warning(
400400
"Metrics listener configured, but "
401401
"enable_metrics is not True!"
@@ -488,7 +488,7 @@ def start(config_options):
488488
register_start(_base.start, hs)
489489

490490
# redirect stdio to the logs, if configured.
491-
if not hs.config.no_redirect_stdio:
491+
if not hs.config.logging.no_redirect_stdio:
492492
redirect_stdio_to_logs()
493493

494494
_base.start_worker_reactor("synapse-generic-worker", config)

synapse/app/homeserver.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def _configure_named_resource(self, name, compress=False):
269269
# https://twistedmatrix.com/trac/ticket/7678
270270
resources[WEB_CLIENT_PREFIX] = File(webclient_loc)
271271

272-
if name == "metrics" and self.config.enable_metrics:
272+
if name == "metrics" and self.config.metrics.enable_metrics:
273273
resources[METRICS_PREFIX] = MetricsResource(RegistryProxy)
274274

275275
if name == "replication":
@@ -278,7 +278,7 @@ def _configure_named_resource(self, name, compress=False):
278278
return resources
279279

280280
def start_listening(self):
281-
if self.config.redis_enabled:
281+
if self.config.redis.redis_enabled:
282282
# If redis is enabled we connect via the replication command handler
283283
# in the same way as the workers (since we're effectively a client
284284
# rather than a server).
@@ -305,7 +305,7 @@ def start_listening(self):
305305
for s in services:
306306
reactor.addSystemEventTrigger("before", "shutdown", s.stopListening)
307307
elif listener.type == "metrics":
308-
if not self.config.enable_metrics:
308+
if not self.config.metrics.enable_metrics:
309309
logger.warning(
310310
"Metrics listener configured, but "
311311
"enable_metrics is not True!"
@@ -366,7 +366,7 @@ def setup(config_options):
366366

367367
async def start():
368368
# Load the OIDC provider metadatas, if OIDC is enabled.
369-
if hs.config.oidc_enabled:
369+
if hs.config.oidc.oidc_enabled:
370370
oidc = hs.get_oidc_handler()
371371
# Loading the provider metadata also ensures the provider config is valid.
372372
await oidc.load_metadata()
@@ -455,7 +455,7 @@ def main():
455455
hs = setup(sys.argv[1:])
456456

457457
# redirect stdio to the logs, if configured.
458-
if not hs.config.no_redirect_stdio:
458+
if not hs.config.logging.no_redirect_stdio:
459459
redirect_stdio_to_logs()
460460

461461
run(hs)

synapse/app/phone_stats_home.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,12 @@ async def phone_stats_home(hs, stats, stats_process=_stats_process):
131131
log_level = synapse_logger.getEffectiveLevel()
132132
stats["log_level"] = logging.getLevelName(log_level)
133133

134-
logger.info("Reporting stats to %s: %s" % (hs.config.report_stats_endpoint, stats))
134+
logger.info(
135+
"Reporting stats to %s: %s" % (hs.config.metrics.report_stats_endpoint, stats)
136+
)
135137
try:
136138
await hs.get_proxied_http_client().put_json(
137-
hs.config.report_stats_endpoint, stats
139+
hs.config.metrics.report_stats_endpoint, stats
138140
)
139141
except Exception as e:
140142
logger.warning("Error reporting stats: %s", e)
@@ -188,7 +190,7 @@ async def generate_monthly_active_users():
188190
clock.looping_call(generate_monthly_active_users, 5 * 60 * 1000)
189191
# End of monthly active user settings
190192

191-
if hs.config.report_stats:
193+
if hs.config.metrics.report_stats:
192194
logger.info("Scheduling stats reporting for 3 hour intervals")
193195
clock.looping_call(phone_stats_home, 3 * 60 * 60 * 1000, hs, stats)
194196

synapse/config/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def setup_logging(
322322
323323
"""
324324
log_config_path = (
325-
config.worker_log_config if use_worker_options else config.log_config
325+
config.worker_log_config if use_worker_options else config.logging.log_config
326326
)
327327

328328
# Perform one-time logging configuration.

synapse/federation/transport/server/_base.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def __init__(self, hs: HomeServer):
4949
self.keyring = hs.get_keyring()
5050
self.server_name = hs.hostname
5151
self.store = hs.get_datastore()
52-
self.federation_domain_whitelist = hs.config.federation_domain_whitelist
52+
self.federation_domain_whitelist = (
53+
hs.config.federation.federation_domain_whitelist
54+
)
5355
self.notifier = hs.get_notifier()
5456

5557
self.replication_client = None

synapse/groups/groups_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,16 +847,16 @@ async def create_group(
847847
UserID.from_string(requester_user_id)
848848
)
849849
if not is_admin:
850-
if not self.hs.config.enable_group_creation:
850+
if not self.hs.config.groups.enable_group_creation:
851851
raise SynapseError(
852852
403, "Only a server admin can create groups on this server"
853853
)
854854
localpart = group_id_obj.localpart
855-
if not localpart.startswith(self.hs.config.group_creation_prefix):
855+
if not localpart.startswith(self.hs.config.groups.group_creation_prefix):
856856
raise SynapseError(
857857
400,
858858
"Can only create groups with prefix %r on this server"
859-
% (self.hs.config.group_creation_prefix,),
859+
% (self.hs.config.groups.group_creation_prefix,),
860860
)
861861

862862
profile = content.get("profile", {})

0 commit comments

Comments
 (0)