-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll 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 |
|
||
serializer = TrustedRelaySerializer(data=request.data) | ||
if not serializer.is_valid(): | ||
return Response({"detail": "Invalid request body"}, status=status.HTTP_400_BAD_REQUEST) |
There was a problem hiding this comment.
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.
try: | ||
existing_option = OrganizationOption.objects.get( | ||
organization=organization, key=option_key | ||
) | ||
existing_relays = existing_option.value | ||
except OrganizationOption.DoesNotExist: | ||
existing_option = None | ||
existing_relays = [] |
There was a problem hiding this comment.
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.
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 | ||
) |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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?
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