Browse Source

chore(hybrid-cloud): Update OrgAuthTokensEndpoint to be a control silo endpoint (#54760)

Alberto Leal 1 year ago
parent
commit
da34506658
1 changed files with 18 additions and 5 deletions
  1. 18 5
      src/sentry/api/endpoints/org_auth_tokens.py

+ 18 - 5
src/sentry/api/endpoints/org_auth_tokens.py

@@ -11,23 +11,31 @@ from rest_framework.response import Response
 
 from sentry import analytics, audit_log, roles
 from sentry.api.base import control_silo_endpoint
-from sentry.api.bases.organization import OrganizationEndpoint, OrgAuthTokenPermission
+from sentry.api.bases.organization import ControlSiloOrganizationEndpoint, OrgAuthTokenPermission
 from sentry.api.serializers import serialize
 from sentry.api.utils import generate_region_url
-from sentry.models.organization import Organization
 from sentry.models.organizationmembermapping import OrganizationMemberMapping
 from sentry.models.orgauthtoken import OrgAuthToken
 from sentry.models.user import User
 from sentry.security.utils import capture_security_activity
+from sentry.services.hybrid_cloud.organization.model import (
+    RpcOrganization,
+    RpcUserOrganizationContext,
+)
 from sentry.utils.security.orgauthtoken_token import generate_token, hash_token
 
 
 @control_silo_endpoint
-class OrgAuthTokensEndpoint(OrganizationEndpoint):
+class OrgAuthTokensEndpoint(ControlSiloOrganizationEndpoint):
     permission_classes = (OrgAuthTokenPermission,)
 
     @method_decorator(never_cache)
-    def get(self, request: Request, organization: Organization) -> Response:
+    def get(
+        self,
+        request: Request,
+        organization_context: RpcUserOrganizationContext,
+        organization: RpcOrganization,
+    ) -> Response:
         # We want to sort by date_last_used, but sort NULLs last
         the_past = datetime.min
 
@@ -41,7 +49,12 @@ class OrgAuthTokensEndpoint(OrganizationEndpoint):
 
         return Response(serialize(token_list, request.user, token=None))
 
-    def post(self, request: Request, organization: Organization) -> Response:
+    def post(
+        self,
+        request: Request,
+        organization_context: RpcUserOrganizationContext,
+        organization: RpcOrganization,
+    ) -> Response:
         token_str = generate_token(organization.slug, generate_region_url())
         token_hashed = hash_token(token_str)