pssecret-server/pssecret/utils.py
Ivan Golikov 8266c95cd9 Integration tests (#3)
Reviewed-on: root/pssecret#3
Co-authored-by: Ivan Golikov <root@ivnglkv.me>
Co-committed-by: Ivan Golikov <root@ivnglkv.me>
2025-01-01 18:18:38 +00:00

22 lines
515 B
Python

from uuid import uuid4
from redis.asyncio import Redis
from pssecret.models import Secret
async def get_new_key(redis: Redis) -> str:
"""Returns free Redis key"""
while True:
new_key = str(uuid4())
if not await redis.exists(new_key):
return new_key
async def save_secret(data: Secret, redis: Redis) -> str:
"""Save passed data, returns retrieval key"""
new_key = await get_new_key(redis)
await redis.setex(new_key, 60 * 60 * 24, data.data)
return new_key