Repository navigation
fix(api): Properly fetch org from token - #65403
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #65403 +/- ##
==========================================
- Coverage 84.31% 84.31% -0.01%
==========================================
Files 5306 5306
Lines 237091 237093 +2
Branches 41002 41003 +1
==========================================
- Hits 199915 199913 -2
- Misses 36958 36962 +4
Partials 218 218
|
|
This issue has gone three weeks without activity. In another week, I will close it. But! If you comment or otherwise update it, I will reset the clock, and if you remove the label "A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀 |
|
🚨 Warning: This pull request contains Frontend and Backend changes! It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently. Have questions? Please ask in the |
| token_id = request_auth.id | ||
| elif isinstance(request_auth, AuthenticatedToken) and request_auth.entity_id is not None: | ||
| token_id = request_auth.entity_id | ||
| elif isinstance(request_auth, ApiTokenReplica) and request_auth.apitoken_id is not None: | ||
| token_id = request_auth.apitoken_id |
There was a problem hiding this comment.
Seems kinda funny/dangerous that we have to do this. Are we concerned about the token falling into the wrong condition?
There was a problem hiding this comment.
Also, I think it might make sense for this entire if condition to be a method on the request_auth class? Seems like it would be useful and consistent logic we'd want across the code base
There was a problem hiding this comment.
These checks are done because from what I understand for hybrid cloud, the AuthenticatedToken class is like an interface for all our tokens that we pass around in the control region.
is_api_token_auth ensures the token is either an ApiToken or AuthenticatedToken that was created from an ApiToken so it's guaranteed that one of the conditions will pass.
I think the rate limiter can run in all regions, so that's why we can't simply do request_auth.organization when trying to fetch the org, and instead have to:
- Fetch the token
- Use a hybrid cloud service to find the installation belonging to the token
- Return the org on the installation
There was a problem hiding this comment.
These checks are done because from what I understand for hybrid cloud, the AuthenticatedToken class is like an interface for all our tokens that we pass around in the control region.
Correct, AuthenticatedToken is used in all silo modes though. The isinstance() checks are likely to appease type checking.
volokluev
left a comment
There was a problem hiding this comment.
This looks good to me but I cannot comment on the hybrid cloud stuff, it's out of my wheelhouse
| token_id = request_auth.id | ||
| elif isinstance(request_auth, AuthenticatedToken) and request_auth.entity_id is not None: | ||
| token_id = request_auth.entity_id | ||
| elif isinstance(request_auth, ApiTokenReplica) and request_auth.apitoken_id is not None: | ||
| token_id = request_auth.apitoken_id |
There was a problem hiding this comment.
These checks are done because from what I understand for hybrid cloud, the AuthenticatedToken class is like an interface for all our tokens that we pass around in the control region.
Correct, AuthenticatedToken is used in all silo modes though. The isinstance() checks are likely to appease type checking.
| filter={ | ||
| "status": SentryAppInstallationStatus.INSTALLED, | ||
| "api_token_id": token_id, | ||
| "api_installation_token_id": token_id, |
There was a problem hiding this comment.
We can't start using new RPC methods and parameters in the same pull request that the method or parameter is defined in. The reason for this is deploys don't go out to all regions and control at the same time. Regions deploy first, and then control. With the current changes you would be sending an unsupported filter condition to control for the duration of the deploy (20 min or so).
Instead we need to deploy the new parameter support first, and then deploy changes that use the new filter option.
There was a problem hiding this comment.
Just merged #67159, waiting for it to deploy
There was a problem hiding this comment.
deploy went out, just have to deploy this one now
Requires #67159
Uses the new param in sentry app to fetch the relevant
SentryAppInstallationfrom a token id by also checkingSentryAppInstallationToken, which will link to the relevantSentryAppInstallation.Moved test for
get_rate_limit_keyfromtest_ratelimit_middleware.pytotest_get_ratelimit_key.py.Also added individual tests for
ApiTokenReplicaandOrgAuthTokenmodelsCloses https://github.com/getsentry/team-core-product-foundations/issues/159