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

Commit a0f48ee

Browse files
authored
Use direct references for configuration variables (part 7). (#10959)
1 parent a071144 commit a0f48ee

File tree

23 files changed

+83
-68
lines changed

23 files changed

+83
-68
lines changed

changelog.d/10959.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/handlers/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def __init__(self, hs: "HomeServer"):
198198
if inst.is_enabled():
199199
self.checkers[inst.AUTH_TYPE] = inst # type: ignore
200200

201-
self.bcrypt_rounds = hs.config.bcrypt_rounds
201+
self.bcrypt_rounds = hs.config.registration.bcrypt_rounds
202202

203203
# we can't use hs.get_module_api() here, because to do so will create an
204204
# import loop.

synapse/handlers/identity.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -573,9 +573,15 @@ async def validate_threepid_session(
573573

574574
# Try to validate as email
575575
if self.hs.config.email.threepid_behaviour_email == ThreepidBehaviour.REMOTE:
576+
# Remote emails will only be used if a valid identity server is provided.
577+
assert (
578+
self.hs.config.registration.account_threepid_delegate_email is not None
579+
)
580+
576581
# Ask our delegated email identity server
577582
validation_session = await self.threepid_from_creds(
578-
self.hs.config.account_threepid_delegate_email, threepid_creds
583+
self.hs.config.registration.account_threepid_delegate_email,
584+
threepid_creds,
579585
)
580586
elif self.hs.config.email.threepid_behaviour_email == ThreepidBehaviour.LOCAL:
581587
# Get a validated session matching these details
@@ -587,10 +593,11 @@ async def validate_threepid_session(
587593
return validation_session
588594

589595
# Try to validate as msisdn
590-
if self.hs.config.account_threepid_delegate_msisdn:
596+
if self.hs.config.registration.account_threepid_delegate_msisdn:
591597
# Ask our delegated msisdn identity server
592598
validation_session = await self.threepid_from_creds(
593-
self.hs.config.account_threepid_delegate_msisdn, threepid_creds
599+
self.hs.config.registration.account_threepid_delegate_msisdn,
600+
threepid_creds,
594601
)
595602

596603
return validation_session

synapse/handlers/profile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ async def set_displayname(
178178
if not by_admin and target_user != requester.user:
179179
raise AuthError(400, "Cannot set another user's displayname")
180180

181-
if not by_admin and not self.hs.config.enable_set_displayname:
181+
if not by_admin and not self.hs.config.registration.enable_set_displayname:
182182
profile = await self.store.get_profileinfo(target_user.localpart)
183183
if profile.display_name:
184184
raise SynapseError(
@@ -268,7 +268,7 @@ async def set_avatar_url(
268268
if not by_admin and target_user != requester.user:
269269
raise AuthError(400, "Cannot set another user's avatar_url")
270270

271-
if not by_admin and not self.hs.config.enable_set_avatar_url:
271+
if not by_admin and not self.hs.config.registration.enable_set_avatar_url:
272272
profile = await self.store.get_profileinfo(target_user.localpart)
273273
if profile.avatar_url:
274274
raise SynapseError(

synapse/handlers/register.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ def __init__(self, hs: "HomeServer"):
116116
self._register_device_client = self.register_device_inner
117117
self.pusher_pool = hs.get_pusherpool()
118118

119-
self.session_lifetime = hs.config.session_lifetime
120-
self.access_token_lifetime = hs.config.access_token_lifetime
119+
self.session_lifetime = hs.config.registration.session_lifetime
120+
self.access_token_lifetime = hs.config.registration.access_token_lifetime
121121

122122
init_counters_for_auth_provider("")
123123

@@ -343,7 +343,10 @@ async def register_user(
343343
# If the user does not need to consent at registration, auto-join any
344344
# configured rooms.
345345
if not self.hs.config.consent.user_consent_at_registration:
346-
if not self.hs.config.auto_join_rooms_for_guests and make_guest:
346+
if (
347+
not self.hs.config.registration.auto_join_rooms_for_guests
348+
and make_guest
349+
):
347350
logger.info(
348351
"Skipping auto-join for %s because auto-join for guests is disabled",
349352
user_id,

synapse/handlers/room_member.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __init__(self, hs: "HomeServer"):
8989
self.spam_checker = hs.get_spam_checker()
9090
self.third_party_event_rules = hs.get_third_party_event_rules()
9191
self._server_notices_mxid = self.config.servernotices.server_notices_mxid
92-
self._enable_lookup = hs.config.enable_3pid_lookup
92+
self._enable_lookup = hs.config.registration.enable_3pid_lookup
9393
self.allow_per_room_profiles = self.config.server.allow_per_room_profiles
9494

9595
self._join_rate_limiter_local = Ratelimiter(

synapse/handlers/ui_auth/checkers.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,23 @@ async def _check_threepid(self, medium: str, authdict: dict) -> dict:
153153

154154
# msisdns are currently always ThreepidBehaviour.REMOTE
155155
if medium == "msisdn":
156-
if not self.hs.config.account_threepid_delegate_msisdn:
156+
if not self.hs.config.registration.account_threepid_delegate_msisdn:
157157
raise SynapseError(
158158
400, "Phone number verification is not enabled on this homeserver"
159159
)
160160
threepid = await identity_handler.threepid_from_creds(
161-
self.hs.config.account_threepid_delegate_msisdn, threepid_creds
161+
self.hs.config.registration.account_threepid_delegate_msisdn,
162+
threepid_creds,
162163
)
163164
elif medium == "email":
164165
if (
165166
self.hs.config.email.threepid_behaviour_email
166167
== ThreepidBehaviour.REMOTE
167168
):
168-
assert self.hs.config.account_threepid_delegate_email
169+
assert self.hs.config.registration.account_threepid_delegate_email
169170
threepid = await identity_handler.threepid_from_creds(
170-
self.hs.config.account_threepid_delegate_email, threepid_creds
171+
self.hs.config.registration.account_threepid_delegate_email,
172+
threepid_creds,
171173
)
172174
elif (
173175
self.hs.config.email.threepid_behaviour_email == ThreepidBehaviour.LOCAL
@@ -240,7 +242,7 @@ def __init__(self, hs: "HomeServer"):
240242
_BaseThreepidAuthChecker.__init__(self, hs)
241243

242244
def is_enabled(self) -> bool:
243-
return bool(self.hs.config.account_threepid_delegate_msisdn)
245+
return bool(self.hs.config.registration.account_threepid_delegate_msisdn)
244246

245247
async def check_auth(self, authdict: dict, clientip: str) -> Any:
246248
return await self._check_threepid("msisdn", authdict)
@@ -252,7 +254,7 @@ class RegistrationTokenAuthChecker(UserInteractiveAuthChecker):
252254
def __init__(self, hs: "HomeServer"):
253255
super().__init__(hs)
254256
self.hs = hs
255-
self._enabled = bool(hs.config.registration_requires_token)
257+
self._enabled = bool(hs.config.registration.registration_requires_token)
256258
self.store = hs.get_datastore()
257259

258260
def is_enabled(self) -> bool:

synapse/rest/admin/users.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
442442
async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
443443
self._clear_old_nonces()
444444

445-
if not self.hs.config.registration_shared_secret:
445+
if not self.hs.config.registration.registration_shared_secret:
446446
raise SynapseError(400, "Shared secret registration is not enabled")
447447

448448
body = parse_json_object_from_request(request)
@@ -498,7 +498,7 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
498498
got_mac = body["mac"]
499499

500500
want_mac_builder = hmac.new(
501-
key=self.hs.config.registration_shared_secret.encode(),
501+
key=self.hs.config.registration.registration_shared_secret.encode(),
502502
digestmod=hashlib.sha1,
503503
)
504504
want_mac_builder.update(nonce.encode("utf8"))

synapse/rest/client/account.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,11 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
130130
raise SynapseError(400, "Email not found", Codes.THREEPID_NOT_FOUND)
131131

132132
if self.config.email.threepid_behaviour_email == ThreepidBehaviour.REMOTE:
133-
assert self.hs.config.account_threepid_delegate_email
133+
assert self.hs.config.registration.account_threepid_delegate_email
134134

135135
# Have the configured identity server handle the request
136136
ret = await self.identity_handler.requestEmailToken(
137-
self.hs.config.account_threepid_delegate_email,
137+
self.hs.config.registration.account_threepid_delegate_email,
138138
email,
139139
client_secret,
140140
send_attempt,
@@ -414,11 +414,11 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
414414
raise SynapseError(400, "Email is already in use", Codes.THREEPID_IN_USE)
415415

416416
if self.config.email.threepid_behaviour_email == ThreepidBehaviour.REMOTE:
417-
assert self.hs.config.account_threepid_delegate_email
417+
assert self.hs.config.registration.account_threepid_delegate_email
418418

419419
# Have the configured identity server handle the request
420420
ret = await self.identity_handler.requestEmailToken(
421-
self.hs.config.account_threepid_delegate_email,
421+
self.hs.config.registration.account_threepid_delegate_email,
422422
email,
423423
client_secret,
424424
send_attempt,
@@ -496,7 +496,7 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
496496

497497
raise SynapseError(400, "MSISDN is already in use", Codes.THREEPID_IN_USE)
498498

499-
if not self.hs.config.account_threepid_delegate_msisdn:
499+
if not self.hs.config.registration.account_threepid_delegate_msisdn:
500500
logger.warning(
501501
"No upstream msisdn account_threepid_delegate configured on the server to "
502502
"handle this request"
@@ -507,7 +507,7 @@ async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
507507
)
508508

509509
ret = await self.identity_handler.requestMsisdnToken(
510-
self.hs.config.account_threepid_delegate_msisdn,
510+
self.hs.config.registration.account_threepid_delegate_msisdn,
511511
country,
512512
phone_number,
513513
client_secret,
@@ -604,7 +604,7 @@ def __init__(self, hs: "HomeServer"):
604604
self.identity_handler = hs.get_identity_handler()
605605

606606
async def on_POST(self, request: Request) -> Tuple[int, JsonDict]:
607-
if not self.config.account_threepid_delegate_msisdn:
607+
if not self.config.registration.account_threepid_delegate_msisdn:
608608
raise SynapseError(
609609
400,
610610
"This homeserver is not validating phone numbers. Use an identity server "
@@ -617,7 +617,7 @@ async def on_POST(self, request: Request) -> Tuple[int, JsonDict]:
617617

618618
# Proxy submit_token request to msisdn threepid delegate
619619
response = await self.identity_handler.proxy_msisdn_submit_token(
620-
self.config.account_threepid_delegate_msisdn,
620+
self.config.registration.account_threepid_delegate_msisdn,
621621
body["client_secret"],
622622
body["sid"],
623623
body["token"],
@@ -644,7 +644,7 @@ async def on_GET(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
644644
return 200, {"threepids": threepids}
645645

646646
async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
647-
if not self.hs.config.enable_3pid_changes:
647+
if not self.hs.config.registration.enable_3pid_changes:
648648
raise SynapseError(
649649
400, "3PID changes are disabled on this server", Codes.FORBIDDEN
650650
)
@@ -693,7 +693,7 @@ def __init__(self, hs: "HomeServer"):
693693

694694
@interactive_auth_handler
695695
async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
696-
if not self.hs.config.enable_3pid_changes:
696+
if not self.hs.config.registration.enable_3pid_changes:
697697
raise SynapseError(
698698
400, "3PID changes are disabled on this server", Codes.FORBIDDEN
699699
)
@@ -801,7 +801,7 @@ def __init__(self, hs: "HomeServer"):
801801
self.auth_handler = hs.get_auth_handler()
802802

803803
async def on_POST(self, request: SynapseRequest) -> Tuple[int, JsonDict]:
804-
if not self.hs.config.enable_3pid_changes:
804+
if not self.hs.config.registration.enable_3pid_changes:
805805
raise SynapseError(
806806
400, "3PID changes are disabled on this server", Codes.FORBIDDEN
807807
)

synapse/rest/client/auth.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ def __init__(self, hs: "HomeServer"):
4949
self.registration_handler = hs.get_registration_handler()
5050
self.recaptcha_template = hs.config.captcha.recaptcha_template
5151
self.terms_template = hs.config.terms_template
52-
self.registration_token_template = hs.config.registration_token_template
53-
self.success_template = hs.config.fallback_success_template
52+
self.registration_token_template = (
53+
hs.config.registration.registration_token_template
54+
)
55+
self.success_template = hs.config.registration.fallback_success_template
5456

5557
async def on_GET(self, request: SynapseRequest, stagetype: str) -> None:
5658
session = parse_string(request, "session")

0 commit comments

Comments
 (0)