Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(relay): Add endpoint for registering trusted relay #82808

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

iambriccardo
Copy link
Member

@iambriccardo iambriccardo commented Jan 2, 2025

This PR exposes a new endpoint for registering an external Relay to Sentry.

This endpoint can be authenticated exclusively with the organization auth token, since it's meant to be used in a cli environment.

Closes: https://github.com/getsentry/team-ingest/issues/275

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jan 2, 2025
Copy link

codecov bot commented Jan 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #82808      +/-   ##
==========================================
+ Coverage   87.56%   87.57%   +0.01%     
==========================================
  Files        9469     9471       +2     
  Lines      536963   537109     +146     
  Branches    21119    21119              
==========================================
+ Hits       470182   470384     +202     
+ Misses      66422    66366      -56     
  Partials      359      359              

@iambriccardo iambriccardo marked this pull request as ready for review January 7, 2025 15:09
@iambriccardo iambriccardo requested a review from a team as a code owner January 7, 2025 15:09

serializer = TrustedRelaySerializer(data=request.data)
if not serializer.is_valid():
return Response({"detail": "Invalid request body"}, status=status.HTTP_400_BAD_REQUEST)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any validation errors we could give to the user? Right now it would be hard to figure what field you made a mistake on.

Comment on lines +43 to +50
try:
existing_option = OrganizationOption.objects.get(
organization=organization, key=option_key
)
existing_relays = existing_option.value
except OrganizationOption.DoesNotExist:
existing_option = None
existing_relays = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also use OrganizationOption.objects.get_value(organization=organization, key=option_key, default=[]) to read the value without needing a try/except. You wouldn't be able to know if the option was new/existing though.

Comment on lines +77 to +83
if existing_option is not None:
existing_option.value = existing_relays
existing_option.save()
else:
OrganizationOption.objects.set_value(
organization=organization, key=option_key, value=existing_relays
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OrganizationOption.objects.set_value() should take care of the insert/update paths for you.



@region_silo_endpoint
class InternalRegisterTrustedRelayEndpoint(OrganizationEndpoint):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default permissions from OrganizationEndpoint will allow manager role users to make changes, is that ok for this endpoint?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants