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

Commit bb7fdd8

Browse files
authored
Use direct references for configuration variables (part 5). (#10897)
1 parent 85551b7 commit bb7fdd8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+128
-113
lines changed

changelog.d/10897.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/app/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ def start_worker_reactor(appname, config, run_command=reactor.run):
8888
appname,
8989
soft_file_limit=config.soft_file_limit,
9090
gc_thresholds=config.gc_thresholds,
91-
pid_file=config.worker_pid_file,
92-
daemonize=config.worker_daemonize,
91+
pid_file=config.worker.worker_pid_file,
92+
daemonize=config.worker.worker_daemonize,
9393
print_pidfile=config.print_pidfile,
9494
logger=logger,
9595
run_command=run_command,

synapse/app/admin_cmd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ def start(config_options):
186186
config.worker.worker_app = "synapse.app.admin_cmd"
187187

188188
if (
189-
not config.worker_daemonize
190-
and not config.worker_log_file
191-
and not config.worker_log_config
189+
not config.worker.worker_daemonize
190+
and not config.worker.worker_log_file
191+
and not config.worker.worker_log_config
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.

synapse/app/generic_worker.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def __init__(self, hs):
140140
self.auth = hs.get_auth()
141141
self.store = hs.get_datastore()
142142
self.http_client = hs.get_simple_http_client()
143-
self.main_uri = hs.config.worker_main_http_uri
143+
self.main_uri = hs.config.worker.worker_main_http_uri
144144

145145
async def on_POST(self, request: Request, device_id: Optional[str]):
146146
requester = await self.auth.get_user_by_req(request, allow_guest=True)
@@ -321,7 +321,7 @@ def _listen_http(self, listener_config: ListenerConfig):
321321
elif name == "federation":
322322
resources.update({FEDERATION_PREFIX: TransportLayerServer(self)})
323323
elif name == "media":
324-
if self.config.can_load_media_repo:
324+
if self.config.media.can_load_media_repo:
325325
media_repo = self.get_media_repository_resource()
326326

327327
# We need to serve the admin servlets for media on the
@@ -384,7 +384,7 @@ def _listen_http(self, listener_config: ListenerConfig):
384384
logger.info("Synapse worker now listening on port %d", port)
385385

386386
def start_listening(self):
387-
for listener in self.config.worker_listeners:
387+
for listener in self.config.worker.worker_listeners:
388388
if listener.type == "http":
389389
self._listen_http(listener)
390390
elif listener.type == "manhole":

synapse/app/homeserver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ def _configure_named_resource(self, name, compress=False):
234234
)
235235

236236
if name in ["media", "federation", "client"]:
237-
if self.config.enable_media_repo:
237+
if self.config.media.enable_media_repo:
238238
media_repo = self.get_media_repository_resource()
239239
resources.update(
240240
{MEDIA_PREFIX: media_repo, LEGACY_MEDIA_PREFIX: media_repo}

synapse/config/logger.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ def setup_logging(
322322
323323
"""
324324
log_config_path = (
325-
config.worker_log_config if use_worker_options else config.logging.log_config
325+
config.worker.worker_log_config
326+
if use_worker_options
327+
else config.logging.log_config
326328
)
327329

328330
# Perform one-time logging configuration.

synapse/crypto/context_factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ def configure_context(context, config):
7474
context.set_options(
7575
SSL.OP_NO_SSLv2 | SSL.OP_NO_SSLv3 | SSL.OP_NO_TLSv1 | SSL.OP_NO_TLSv1_1
7676
)
77-
context.use_certificate_chain_file(config.tls_certificate_file)
78-
context.use_privatekey(config.tls_private_key)
77+
context.use_certificate_chain_file(config.tls.tls_certificate_file)
78+
context.use_privatekey(config.tls.tls_private_key)
7979

8080
# https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/
8181
context.set_cipher_list(

synapse/events/spamcheck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def load_legacy_spam_checkers(hs: "synapse.server.HomeServer"):
7878
"""
7979
spam_checkers: List[Any] = []
8080
api = hs.get_module_api()
81-
for module, config in hs.config.spam_checkers:
81+
for module, config in hs.config.spamchecker.spam_checkers:
8282
# Older spam checkers don't accept the `api` argument, so we
8383
# try and detect support.
8484
spam_args = inspect.getfullargspec(module)

synapse/events/third_party_rules.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def load_legacy_third_party_event_rules(hs: "HomeServer"):
4242
"""Wrapper that loads a third party event rules module configured using the old
4343
configuration, and registers the hooks they implement.
4444
"""
45-
if hs.config.third_party_event_rules is None:
45+
if hs.config.thirdpartyrules.third_party_event_rules is None:
4646
return
4747

48-
module, config = hs.config.third_party_event_rules
48+
module, config = hs.config.thirdpartyrules.third_party_event_rules
4949

5050
api = hs.get_module_api()
5151
third_party_rules = module(config=config, module_api=api)

synapse/handlers/auth.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,23 +277,25 @@ def __init__(self, hs: "HomeServer"):
277277
# after the SSO completes and before redirecting them back to their client.
278278
# It notifies the user they are about to give access to their matrix account
279279
# to the client.
280-
self._sso_redirect_confirm_template = hs.config.sso_redirect_confirm_template
280+
self._sso_redirect_confirm_template = (
281+
hs.config.sso.sso_redirect_confirm_template
282+
)
281283

282284
# The following template is shown during user interactive authentication
283285
# in the fallback auth scenario. It notifies the user that they are
284286
# authenticating for an operation to occur on their account.
285-
self._sso_auth_confirm_template = hs.config.sso_auth_confirm_template
287+
self._sso_auth_confirm_template = hs.config.sso.sso_auth_confirm_template
286288

287289
# The following template is shown during the SSO authentication process if
288290
# the account is deactivated.
289291
self._sso_account_deactivated_template = (
290-
hs.config.sso_account_deactivated_template
292+
hs.config.sso.sso_account_deactivated_template
291293
)
292294

293295
self._server_name = hs.config.server.server_name
294296

295297
# cast to tuple for use with str.startswith
296-
self._whitelisted_sso_clients = tuple(hs.config.sso_client_whitelist)
298+
self._whitelisted_sso_clients = tuple(hs.config.sso.sso_client_whitelist)
297299

298300
# A mapping of user ID to extra attributes to include in the login
299301
# response.

synapse/handlers/directory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def __init__(self, hs: "HomeServer"):
4848
self.event_creation_handler = hs.get_event_creation_handler()
4949
self.store = hs.get_datastore()
5050
self.config = hs.config
51-
self.enable_room_list_search = hs.config.enable_room_list_search
51+
self.enable_room_list_search = hs.config.roomdirectory.enable_room_list_search
5252
self.require_membership = hs.config.require_membership_for_aliases
5353
self.third_party_event_rules = hs.get_third_party_event_rules()
5454

@@ -143,7 +143,7 @@ async def create_association(
143143
):
144144
raise AuthError(403, "This user is not permitted to create this alias")
145145

146-
if not self.config.is_alias_creation_allowed(
146+
if not self.config.roomdirectory.is_alias_creation_allowed(
147147
user_id, room_id, room_alias_str
148148
):
149149
# Lets just return a generic message, as there may be all sorts of
@@ -459,7 +459,7 @@ async def edit_published_room_list(
459459
if canonical_alias:
460460
room_aliases.append(canonical_alias)
461461

462-
if not self.config.is_publishing_room_allowed(
462+
if not self.config.roomdirectory.is_publishing_room_allowed(
463463
user_id, room_id, room_aliases
464464
):
465465
# Lets just return a generic message, as there may be all sorts of

synapse/handlers/federation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __init__(self, hs: "HomeServer"):
9191
self.spam_checker = hs.get_spam_checker()
9292
self.event_creation_handler = hs.get_event_creation_handler()
9393
self._event_auth_handler = hs.get_event_auth_handler()
94-
self._server_notices_mxid = hs.config.server_notices_mxid
94+
self._server_notices_mxid = hs.config.servernotices.server_notices_mxid
9595
self.config = hs.config
9696
self.http_client = hs.get_proxied_blacklisted_http_client()
9797
self._replication = hs.get_replication_data_handler()

synapse/handlers/message.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -692,10 +692,10 @@ async def _is_exempt_from_privacy_policy(
692692
return False
693693

694694
async def _is_server_notices_room(self, room_id: str) -> bool:
695-
if self.config.server_notices_mxid is None:
695+
if self.config.servernotices.server_notices_mxid is None:
696696
return False
697697
user_ids = await self.store.get_users_in_room(room_id)
698-
return self.config.server_notices_mxid in user_ids
698+
return self.config.servernotices.server_notices_mxid in user_ids
699699

700700
async def assert_accepted_privacy_policy(self, requester: Requester) -> None:
701701
"""Check if a user has accepted the privacy policy
@@ -731,8 +731,8 @@ async def assert_accepted_privacy_policy(self, requester: Requester) -> None:
731731

732732
# exempt the system notices user
733733
if (
734-
self.config.server_notices_mxid is not None
735-
and user_id == self.config.server_notices_mxid
734+
self.config.servernotices.server_notices_mxid is not None
735+
and user_id == self.config.servernotices.server_notices_mxid
736736
):
737737
return
738738

synapse/handlers/register.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ def __init__(self, hs: "HomeServer"):
9898
self.macaroon_gen = hs.get_macaroon_generator()
9999
self._account_validity_handler = hs.get_account_validity_handler()
100100
self._user_consent_version = self.hs.config.consent.user_consent_version
101-
self._server_notices_mxid = hs.config.server_notices_mxid
101+
self._server_notices_mxid = hs.config.servernotices.server_notices_mxid
102102
self._server_name = hs.hostname
103103

104104
self.spam_checker = hs.get_spam_checker()

synapse/handlers/room.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def __init__(self, hs: "HomeServer"):
126126
for preset_name, preset_config in self._presets_dict.items():
127127
encrypted = (
128128
preset_name
129-
in self.config.encryption_enabled_by_default_for_room_presets
129+
in self.config.room.encryption_enabled_by_default_for_room_presets
130130
)
131131
preset_config["encrypted"] = encrypted
132132

@@ -141,7 +141,7 @@ def __init__(self, hs: "HomeServer"):
141141
self._upgrade_response_cache: ResponseCache[Tuple[str, str]] = ResponseCache(
142142
hs.get_clock(), "room_upgrade", timeout_ms=FIVE_MINUTES_IN_MS
143143
)
144-
self._server_notices_mxid = hs.config.server_notices_mxid
144+
self._server_notices_mxid = hs.config.servernotices.server_notices_mxid
145145

146146
self.third_party_event_rules = hs.get_third_party_event_rules()
147147

@@ -757,7 +757,9 @@ async def create_room(
757757
)
758758

759759
if is_public:
760-
if not self.config.is_publishing_room_allowed(user_id, room_id, room_alias):
760+
if not self.config.roomdirectory.is_publishing_room_allowed(
761+
user_id, room_id, room_alias
762+
):
761763
# Lets just return a generic message, as there may be all sorts of
762764
# reasons why we said no. TODO: Allow configurable error messages
763765
# per alias creation rule?

synapse/handlers/room_list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
class RoomListHandler(BaseHandler):
5353
def __init__(self, hs: "HomeServer"):
5454
super().__init__(hs)
55-
self.enable_room_list_search = hs.config.enable_room_list_search
55+
self.enable_room_list_search = hs.config.roomdirectory.enable_room_list_search
5656
self.response_cache: ResponseCache[
5757
Tuple[Optional[int], Optional[str], Optional[ThirdPartyInstanceID]]
5858
] = ResponseCache(hs.get_clock(), "room_list")

synapse/handlers/room_member.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def __init__(self, hs: "HomeServer"):
8888
self.clock = hs.get_clock()
8989
self.spam_checker = hs.get_spam_checker()
9090
self.third_party_event_rules = hs.get_third_party_event_rules()
91-
self._server_notices_mxid = self.config.server_notices_mxid
91+
self._server_notices_mxid = self.config.servernotices.server_notices_mxid
9292
self._enable_lookup = hs.config.enable_3pid_lookup
9393
self.allow_per_room_profiles = self.config.allow_per_room_profiles
9494

synapse/handlers/saml.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,18 @@ class Saml2SessionData:
5454
class SamlHandler(BaseHandler):
5555
def __init__(self, hs: "HomeServer"):
5656
super().__init__(hs)
57-
self._saml_client = Saml2Client(hs.config.saml2_sp_config)
58-
self._saml_idp_entityid = hs.config.saml2_idp_entityid
57+
self._saml_client = Saml2Client(hs.config.saml2.saml2_sp_config)
58+
self._saml_idp_entityid = hs.config.saml2.saml2_idp_entityid
5959

60-
self._saml2_session_lifetime = hs.config.saml2_session_lifetime
60+
self._saml2_session_lifetime = hs.config.saml2.saml2_session_lifetime
6161
self._grandfathered_mxid_source_attribute = (
62-
hs.config.saml2_grandfathered_mxid_source_attribute
62+
hs.config.saml2.saml2_grandfathered_mxid_source_attribute
6363
)
6464
self._saml2_attribute_requirements = hs.config.saml2.attribute_requirements
65-
self._error_template = hs.config.sso_error_template
6665

6766
# plugin to do custom mapping from saml response to mxid
68-
self._user_mapping_provider = hs.config.saml2_user_mapping_provider_class(
69-
hs.config.saml2_user_mapping_provider_config,
67+
self._user_mapping_provider = hs.config.saml2.saml2_user_mapping_provider_class(
68+
hs.config.saml2.saml2_user_mapping_provider_config,
7069
ModuleApi(hs, hs.get_auth_handler()),
7170
)
7271

@@ -411,7 +410,7 @@ def __init__(self, parsed_config: SamlConfig, module_api: ModuleApi):
411410
self._mxid_mapper = parsed_config.mxid_mapper
412411

413412
self._grandfathered_mxid_source_attribute = (
414-
module_api._hs.config.saml2_grandfathered_mxid_source_attribute
413+
module_api._hs.config.saml2.saml2_grandfathered_mxid_source_attribute
415414
)
416415

417416
def get_remote_user_id(

synapse/handlers/sso.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,17 @@ def __init__(self, hs: "HomeServer"):
184184
self._server_name = hs.hostname
185185
self._registration_handler = hs.get_registration_handler()
186186
self._auth_handler = hs.get_auth_handler()
187-
self._error_template = hs.config.sso_error_template
188-
self._bad_user_template = hs.config.sso_auth_bad_user_template
187+
self._error_template = hs.config.sso.sso_error_template
188+
self._bad_user_template = hs.config.sso.sso_auth_bad_user_template
189189
self._profile_handler = hs.get_profile_handler()
190190

191191
# The following template is shown after a successful user interactive
192192
# authentication session. It tells the user they can close the window.
193-
self._sso_auth_success_template = hs.config.sso_auth_success_template
193+
self._sso_auth_success_template = hs.config.sso.sso_auth_success_template
194194

195-
self._sso_update_profile_information = hs.config.sso_update_profile_information
195+
self._sso_update_profile_information = (
196+
hs.config.sso.sso_update_profile_information
197+
)
196198

197199
# a lock on the mappings
198200
self._mapping_lock = Linearizer(name="sso_user_mapping", clock=hs.get_clock())

synapse/handlers/stats.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __init__(self, hs: "HomeServer"):
4646
self.notifier = hs.get_notifier()
4747
self.is_mine_id = hs.is_mine_id
4848

49-
self.stats_enabled = hs.config.stats_enabled
49+
self.stats_enabled = hs.config.stats.stats_enabled
5050

5151
# The current position in the current_state_delta stream
5252
self.pos: Optional[int] = None

synapse/handlers/user_directory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(self, hs: "HomeServer"):
6161
self.notifier = hs.get_notifier()
6262
self.is_mine_id = hs.is_mine_id
6363
self.update_user_directory = hs.config.update_user_directory
64-
self.search_all_users = hs.config.user_directory_search_all_users
64+
self.search_all_users = hs.config.userdirectory.user_directory_search_all_users
6565
self.spam_checker = hs.get_spam_checker()
6666
# The current position in the current_state_delta stream
6767
self.pos: Optional[int] = None

synapse/logging/opentracing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ def noop_context_manager(*args, **kwargs):
363363
def init_tracer(hs: "HomeServer"):
364364
"""Set the whitelists and initialise the JaegerClient tracer"""
365365
global opentracing
366-
if not hs.config.opentracer_enabled:
366+
if not hs.config.tracing.opentracer_enabled:
367367
# We don't have a tracer
368368
opentracing = None
369369
return
@@ -377,12 +377,12 @@ def init_tracer(hs: "HomeServer"):
377377
# Pull out the jaeger config if it was given. Otherwise set it to something sensible.
378378
# See https://github.com/jaegertracing/jaeger-client-python/blob/master/jaeger_client/config.py
379379

380-
set_homeserver_whitelist(hs.config.opentracer_whitelist)
380+
set_homeserver_whitelist(hs.config.tracing.opentracer_whitelist)
381381

382382
from jaeger_client.metrics.prometheus import PrometheusMetricsFactory
383383

384384
config = JaegerConfig(
385-
config=hs.config.jaeger_config,
385+
config=hs.config.tracing.jaeger_config,
386386
service_name=f"{hs.config.server.server_name} {hs.get_instance_name()}",
387387
scope_manager=LogContextScopeManager(hs.config),
388388
metrics_factory=PrometheusMetricsFactory(),

synapse/replication/http/_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ def make_client(cls, hs):
168168
client = hs.get_simple_http_client()
169169
local_instance_name = hs.get_instance_name()
170170

171-
master_host = hs.config.worker_replication_host
172-
master_port = hs.config.worker_replication_http_port
171+
master_host = hs.config.worker.worker_replication_host
172+
master_port = hs.config.worker.worker_replication_http_port
173173

174174
instance_map = hs.config.worker.instance_map
175175

synapse/replication/tcp/handler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,8 +322,8 @@ def start_replication(self, hs):
322322
else:
323323
client_name = hs.get_instance_name()
324324
self._factory = DirectTcpReplicationClientFactory(hs, client_name, self)
325-
host = hs.config.worker_replication_host
326-
port = hs.config.worker_replication_port
325+
host = hs.config.worker.worker_replication_host
326+
port = hs.config.worker.worker_replication_port
327327
hs.get_reactor().connectTCP(host.encode(), port, self._factory)
328328

329329
def get_streams(self) -> Dict[str, Stream]:

synapse/rest/admin/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ def register_servlets_for_client_rest_resource(
267267

268268
# Load the media repo ones if we're using them. Otherwise load the servlets which
269269
# don't need a media repo (typically readonly admin APIs).
270-
if hs.config.can_load_media_repo:
270+
if hs.config.media.can_load_media_repo:
271271
register_servlets_for_media_repo(hs, http_server)
272272
else:
273273
ListMediaInRoom(hs).register(http_server)

synapse/rest/client/login.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def __init__(self, hs: "HomeServer"):
7676
self.jwt_audiences = hs.config.jwt.jwt_audiences
7777

7878
# SSO configuration.
79-
self.saml2_enabled = hs.config.saml2_enabled
79+
self.saml2_enabled = hs.config.saml2.saml2_enabled
8080
self.cas_enabled = hs.config.cas.cas_enabled
8181
self.oidc_enabled = hs.config.oidc.oidc_enabled
8282
self._msc2918_enabled = hs.config.access_token_lifetime is not None

synapse/rest/client/user_directory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
5858
requester = await self.auth.get_user_by_req(request, allow_guest=False)
5959
user_id = requester.user.to_string()
6060

61-
if not self.hs.config.user_directory_search_enabled:
61+
if not self.hs.config.userdirectory.user_directory_search_enabled:
6262
return 200, {"limited": False, "results": []}
6363

6464
body = parse_json_object_from_request(request)

0 commit comments

Comments
 (0)