Port Requester class to Rust. (#19828)

This is in prep for converting the event serialization to Rust.

This is a fairly mechanical port, except that we store the appservice ID
rather than the appservice object. This avoids us having to store a
`Py<..>` (or port the appservice object over).
This commit is contained in:
Erik Johnston authored and GitHub committed 2026-06-09 10:26:04 +01:00
1 parent 8c9b1ff877
commit ac21bf08f3
30 files changed
+517 -133

No files matched your search

+4 -2
View File
@@ -371,7 +371,9 @@ class BaseAuth:
"""
ip_addr = request.get_client_ip_if_available()
if ip_addr and (not requester.app_service or self._track_appservice_user_ips):
if ip_addr and (
not requester.app_service_id or self._track_appservice_user_ips
):
user_agent = get_request_user_agent(request)
access_token = self.get_access_token_from_request(request)
@@ -381,7 +383,7 @@ class BaseAuth:
# table during the transition
recorded_device_id = (
"dummy-device"
if requester.device_id is None and requester.app_service is not None
if requester.device_id is None and requester.app_service_id is not None
else requester.device_id
)
await self.store.insert_client_ip(
+2 -2
View File
@@ -106,8 +106,8 @@ class InternalAuth(BaseAuth):
parent_span.set_tag("user_id", requester.user.to_string())
if requester.device_id is not None:
parent_span.set_tag("device_id", requester.device_id)
if requester.app_service is not None:
parent_span.set_tag("appservice_id", requester.app_service.id)
if requester.app_service_id is not None:
parent_span.set_tag("appservice_id", requester.app_service_id)
return requester
async def get_user_by_req_experimental_feature(
+2 -2
View File
@@ -311,8 +311,8 @@ class MasDelegatedAuth(BaseAuth):
parent_span.set_tag("user_id", requester.user.to_string())
if requester.device_id is not None:
parent_span.set_tag("device_id", requester.device_id)
if requester.app_service is not None:
parent_span.set_tag("appservice_id", requester.app_service.id)
if requester.app_service_id is not None:
parent_span.set_tag("appservice_id", requester.app_service_id)
return requester
async def get_user_by_access_token(
+2 -2
View File
@@ -420,8 +420,8 @@ class MSC3861DelegatedAuth(BaseAuth):
parent_span.set_tag("user_id", requester.user.to_string())
if requester.device_id is not None:
parent_span.set_tag("device_id", requester.device_id)
if requester.app_service is not None:
parent_span.set_tag("appservice_id", requester.app_service.id)
if requester.app_service_id is not None:
parent_span.set_tag("appservice_id", requester.app_service_id)
return requester
async def _wrapped_get_user_by_req(
+1 -1
View File
@@ -88,7 +88,7 @@ class AuthBlocking:
# We never block the server from doing actions on behalf of
# users.
return
if requester.app_service and not self._track_appservice_user_ips:
if requester.app_service_id and not self._track_appservice_user_ips:
# If we're authenticated as an appservice then we only block
# auth if `track_appservice_user_ips` is set, as that option
# implicitly means that application services are part of MAU
+6 -1
View File
@@ -163,7 +163,12 @@ class Ratelimiter:
if requester:
# Disable rate limiting of users belonging to any AS that is configured
# not to be rate limited in its registration file (rate_limited: true|false).
if requester.app_service and not requester.app_service.is_rate_limited():
app_service = (
self.store.get_app_service_by_id(requester.app_service_id)
if requester.app_service_id
else None
)
if app_service and not app_service.is_rate_limited():
return True, -1.0
# Check if ratelimiting has been disabled for the user.