Repository navigation
ref(auth): Use shared viewercontext library - #128628
Conversation
101736b to
e8670f5
Compare
9ad527e to
4bab5c3
Compare
2cc8472 to
9a37736
Compare
Sentry Snapshot Testing
|
4bab5c3 to
2809cd1
Compare
9a37736 to
b80f052
Compare
2809cd1 to
73d741c
Compare
b80f052 to
911d876
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 911d876. Configure here.
| return pyjwt.encode( | ||
| payload, secret, algorithm="HS256", headers={_JWT_KEY_ID_HEADER: _key_id(secret)} | ||
| ) | ||
| viewer_context = dataclasses.replace(viewer_context, organization_is_early_adopter=True) |
There was a problem hiding this comment.
Stale early-adopter flag on re-encode
Low Severity
encode_viewer_context now copies organization_is_early_adopter onto the ViewerContext before signing, and only sets that field when the org lookup is true. A decoded context that already carries True therefore keeps the claim on the next encode even if the org is no longer an early adopter. Previously the claim lived only on the JWT payload and was dropped on deserialize, so every encode rechecked the database.
Reviewed by Cursor Bugbot for commit 911d876. Configure here.
73d741c to
bf0be78
Compare
911d876 to
86549ba
Compare
| user_id = actor.actor_id if actor.type == ActorType.USER else actor.delegated_user_id | ||
| superuser = actor.superuser | ||
| superuser = ( | ||
| SuperuserAccess(expires_at=actor.superuser.expires_at) |
There was a problem hiding this comment.
apply DRY principles, this pattern is repeated in multiple places and likely best as a helper function of some sort
ac5581d to
de207a3
Compare
12f4308 to
fee7d0f
Compare
Models, contextvar and JWT encode/verify now come from the shared sentry-viewercontext package. Sentry keeps key lookup, early-adopter lookup, metrics and its set_viewer_context_* updaters.
Move the repeated conversion between the shared library's SuperuserAccess and Sentry's Pydantic SuperuserAccess into from_/to_viewer_context_superuser. Co-Authored-By: Jeremy Stanley <jeremy.stanley@sentry.io>
fee7d0f to
0a10c37
Compare


Moves Sentry's ViewerContext model, contextvar and JWT encode/verify onto the shared
sentry-viewercontextpackage (getsentry/viewercontext), so Sentry, Seer and other services share one implementation of the wire format.sentry.viewer_contextre-exports the library types, so call sites don't change. Sentry keeps signing-key lookup from settings, the early-adopter lookup, propagation metrics and itsset_viewer_context_*updaters. The library'sSuperuserAccessis a plain dataclass, so the Pydanticsentry.types.superuser.SuperuserAccessstays for RPC and agent tokens and is converted where it enters or leaves the ViewerContext (middleware,ViewerContextAuthentication, the agent token endpoint).Stacked on the cleanup PR (#128112). Locks the published
sentry-viewercontext0.1.0 from the internal index (getsentry/pypi#2660).