This repository has been archived on 2023-10-10. You can view files and clone it, but cannot push or open issues or pull requests.
paste/paste/utils.py
Ada 103479668d
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
add(backend): cache-control header
Co-authored-by: Ada <ada@gnous.eu>
Co-committed-by: Ada <ada@gnous.eu>
2023-10-01 20:01:21 +00:00

38 lines
727 B
Python
Executable file

# ruff: noqa: S311
"""Shared utils function."""
import random
import secrets
import string
from paste import config
from paste.db import connect_redis
def generate_id() -> str:
"""
Generate url id format.
:return: Url id.
"""
return "".join(
random.choices(string.ascii_letters + string.digits,
k=config.URL_LENGTH)
)
def generate_secret() -> str:
"""
Generate hex secret for delete paste.
:return: The secret.
"""
return secrets.token_hex()
def get_expiration_time(key: str) -> int:
"""
Get key expiration time
:param key: Key to check
:return: Expiration time in second.
"""
db = connect_redis()
return db.ttl(key)