-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(sentry app authorizations): Return token if already made for sentry #91507
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cd46808
fail quietly for token replication
Christinarlong e1730ee
remove old logs
Christinarlong 34fd420
add tests and fix some consistency issues
Christinarlong d0f4238
align missing apiapplication errors
Christinarlong 5d63e30
move error catching to outbox
Christinarlong 94c260c
Merge branch 'master' into crl/best-try-refresh-token
Christinarlong efa18d5
add test for exception catching
Christinarlong ae7b061
fix tests and typing
Christinarlong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
from django.utils.functional import cached_property | ||
|
||
from sentry import analytics | ||
from sentry.hybridcloud.models.outbox import OutboxDatabaseError | ||
from sentry.models.apiapplication import ApiApplication | ||
from sentry.models.apitoken import ApiToken | ||
from sentry.sentry_apps.models.sentry_app import SentryApp | ||
|
@@ -30,22 +31,35 @@ class Refresher: | |
user: User | ||
|
||
def run(self) -> ApiToken: | ||
with transaction.atomic(router.db_for_write(ApiToken)): | ||
try: | ||
try: | ||
token = None | ||
with transaction.atomic(router.db_for_write(ApiToken)): | ||
self._validate() | ||
self.token.delete() | ||
|
||
self._record_analytics() | ||
return self._create_new_token() | ||
except (SentryAppIntegratorError, SentryAppSentryError): | ||
logger.info( | ||
"refresher.context", | ||
extra={ | ||
"application_id": self.application.id, | ||
"refresh_token": self.refresh_token[-4:], | ||
}, | ||
token = self._create_new_token() | ||
return token | ||
except OutboxDatabaseError as e: | ||
context = { | ||
"installation_uuid": self.install.uuid, | ||
"client_id": self.application.client_id[:SENSITIVE_CHARACTER_LIMIT], | ||
"sentry_app_id": self.install.sentry_app.id, | ||
} | ||
|
||
if token is not None: | ||
Christinarlong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
logger.warning( | ||
"refresher.outbox-failure", | ||
extra=context, | ||
exc_info=e, | ||
) | ||
raise | ||
return token | ||
|
||
raise SentryAppSentryError( | ||
message="Failed to refresh given token", | ||
status_code=500, | ||
webhook_context=context, | ||
) from e | ||
|
||
def _record_analytics(self) -> None: | ||
analytics.record( | ||
|
@@ -106,7 +120,7 @@ def application(self) -> ApiApplication: | |
try: | ||
return ApiApplication.objects.get(client_id=self.client_id) | ||
except ApiApplication.DoesNotExist: | ||
raise SentryAppIntegratorError( | ||
raise SentryAppSentryError( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Making this consistent with |
||
message="Could not find matching Application for given client_id", | ||
status_code=401, | ||
webhook_context={ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Taking these logs out as they were to debug a prior customer issue a while back