Просмотр исходного кода

Fix token expiry miscalculation (#24639)

tags/1.8.1
Yongtao Huang 2 месяцев назад
Родитель
Сommit
bb718acadf
Аккаунт пользователя с таким Email не найден

+ 1
- 1
api/extensions/ext_storage.py Просмотреть файл

from extensions.storage.volcengine_tos_storage import VolcengineTosStorage from extensions.storage.volcengine_tos_storage import VolcengineTosStorage


return VolcengineTosStorage return VolcengineTosStorage
case StorageType.SUPBASE:
case StorageType.SUPABASE:
from extensions.storage.supabase_storage import SupabaseStorage from extensions.storage.supabase_storage import SupabaseStorage


return SupabaseStorage return SupabaseStorage

+ 1
- 1
api/extensions/storage/storage_type.py Просмотреть файл

S3 = "s3" S3 = "s3"
TENCENT_COS = "tencent-cos" TENCENT_COS = "tencent-cos"
VOLCENGINE_TOS = "volcengine-tos" VOLCENGINE_TOS = "volcengine-tos"
SUPBASE = "supabase"
SUPABASE = "supabase"

+ 0
- 4
api/factories/variable_factory.py Просмотреть файл

return cast(Variable, result) return cast(Variable, result)




def infer_segment_type_from_value(value: Any, /) -> SegmentType:
return build_segment(value).value_type


def build_segment(value: Any, /) -> Segment: def build_segment(value: Any, /) -> Segment:
# NOTE: If you have runtime type information available, consider using the `build_segment_with_type` # NOTE: If you have runtime type information available, consider using the `build_segment_with_type`
# below # below

+ 5
- 5
api/libs/helper.py Просмотреть файл

if expiry_minutes is None: if expiry_minutes is None:
raise ValueError(f"Expiry minutes for {token_type} token is not set") raise ValueError(f"Expiry minutes for {token_type} token is not set")
token_key = cls._get_token_key(token, token_type) token_key = cls._get_token_key(token, token_type)
expiry_time = int(expiry_minutes * 60)
redis_client.setex(token_key, expiry_time, json.dumps(token_data))
expiry_seconds = int(expiry_minutes * 60)
redis_client.setex(token_key, expiry_seconds, json.dumps(token_data))


if account_id: if account_id:
cls._set_current_token_for_account(account_id, token, token_type, expiry_minutes) cls._set_current_token_for_account(account_id, token, token_type, expiry_minutes)


@classmethod @classmethod
def _set_current_token_for_account( def _set_current_token_for_account(
cls, account_id: str, token: str, token_type: str, expiry_hours: Union[int, float]
cls, account_id: str, token: str, token_type: str, expiry_minutes: Union[int, float]
): ):
key = cls._get_account_token_key(account_id, token_type) key = cls._get_account_token_key(account_id, token_type)
expiry_time = int(expiry_hours * 60 * 60)
redis_client.setex(key, expiry_time, token)
expiry_seconds = int(expiry_minutes * 60)
redis_client.setex(key, expiry_seconds, token)


@classmethod @classmethod
def _get_account_token_key(cls, account_id: str, token_type: str) -> str: def _get_account_token_key(cls, account_id: str, token_type: str) -> str:

Загрузка…
Отмена
Сохранить