-
-
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
Changes from 3 commits
cd46808
e1730ee
34fd420
d0f4238
5d63e30
94c260c
efa18d5
ae7b061
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import logging | ||
from dataclasses import dataclass | ||
|
||
from django.db import router, transaction | ||
from django.db import OperationalError, router, transaction | ||
from django.utils.functional import cached_property | ||
|
||
from sentry import analytics | ||
|
@@ -30,22 +30,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 OperationalError as e: | ||
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. Instead of catching an 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. I tried to do this via adding I was having trouble understanding what the Lmk thoughts / |
||
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.database-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( | ||
|
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