Ada
103479668d
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
Co-authored-by: Ada <ada@gnous.eu> Co-committed-by: Ada <ada@gnous.eu>
38 lines
727 B
Python
Executable file
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)
|