Skip to content

Commit

Permalink
ref(relay): Only update internal state when it changed (#76594)
Browse files Browse the repository at this point in the history
Removes the `is_internal` update from the `relay_from_id` function, to
move the check to the endpoint (where it already was anyways). All
additional uses of `relay_from_id` don't seem to care about the internal
state, except authentication.
So that seems fine, also this behaviour does seem more consistent.
  • Loading branch information
Dav1dde committed Aug 28, 2024
1 parent 8e5ec88 commit 7e0fe49
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/sentry/api/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def relay_from_id(request: Request, relay_id: str) -> tuple[Relay | None, bool]:
else:
try:
relay = Relay.objects.get(relay_id=relay_id)
relay.is_internal = is_internal_relay(request, relay.public_key)
return relay, False # a Relay from the database
except Relay.DoesNotExist:
return None, False # no Relay found
Expand Down Expand Up @@ -223,6 +222,9 @@ def authenticate_credentials(
if relay is None:
raise AuthenticationFailed("Unknown relay")

if not static:
relay.is_internal = is_internal_relay(request, relay.public_key)

try:
data = relay.public_key_object.unpack(request.body, relay_sig, max_age=60 * 5)
request.relay = relay
Expand Down
2 changes: 1 addition & 1 deletion src/sentry/api/endpoints/relay/register_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def post(self, request: Request) -> Response:
relay = Relay.objects.create(
relay_id=relay_id, public_key=public_key, is_internal=is_internal
)
else:
elif relay.is_internal != is_internal:
# update the internal flag in case it is changed
relay.is_internal = is_internal
relay.save()
Expand Down

0 comments on commit 7e0fe49

Please sign in to comment.