55from typing import Any
66
77import orjson
8+ from django .conf import settings
89from django .urls import reverse
9- from rb .clients import LocalClient
10+ from sentry_redis_tools .clients import RedisCluster , StrictRedis
1011
1112from sentry import options
1213from sentry .models .authprovider import AuthProvider
1718from sentry .utils .http import absolute_uri
1819from sentry .utils .security import get_secure_token
1920
20- _REDIS_KEY = "verificationKeyStorage"
2121_TTL = timedelta (minutes = 10 )
2222SSO_VERIFICATION_KEY = "confirm_account_verification_key"
2323
@@ -48,8 +48,8 @@ def send_one_time_account_confirm_link(
4848 return link
4949
5050
51- def get_redis_cluster () -> LocalClient :
52- return redis .clusters .get ("default" ). get_local_client_for_key ( _REDIS_KEY )
51+ def _get_redis_client () -> RedisCluster [ str ] | StrictRedis [ str ] :
52+ return redis .redis_clusters .get (settings . SENTRY_AUTH_IDPMIGRATION_REDIS_CLUSTER )
5353
5454
5555# Helper function for serializing named tuples with orjson.
@@ -96,7 +96,7 @@ def send_confirm_email(self) -> None:
9696 metrics .incr ("idpmigration.confirm_link_sent" , sample_rate = 1.0 )
9797
9898 def store_in_redis (self ) -> None :
99- cluster = get_redis_cluster ()
99+ client = _get_redis_client ()
100100
101101 member = organization_service .check_membership_by_id (
102102 organization_id = self .organization .id , user_id = self .user .id
@@ -110,17 +110,17 @@ def store_in_redis(self) -> None:
110110 "identity_id" : self .identity_id ,
111111 "provider" : self .provider .provider ,
112112 }
113- cluster .setex (
113+ client .setex (
114114 self .verification_key ,
115115 int (_TTL .total_seconds ()),
116116 orjson .dumps (verification_value , default = _serialize_named_tuple ).decode (),
117117 )
118118
119119
120120def get_verification_value_from_key (key : str ) -> dict [str , Any ] | None :
121- cluster = get_redis_cluster ()
121+ client = _get_redis_client ()
122122 verification_key = f"auth:one-time-key:{ key } "
123- verification_str = cluster .get (verification_key )
123+ verification_str = client .get (verification_key )
124124 if verification_str is None :
125125 metrics .incr ("idpmigration.confirmation_failure" , sample_rate = 1.0 )
126126 return None
0 commit comments