import hashlib
import html
import random
import secrets
import string
from datetime import datetime, timedelta
from service.conf import settings
POOL_NAME = (
f"frontend-api-{settings.PROFILE}-user-pool"
if settings.PROFILE in ["live", "test"]
else "frontend-api-devel-user-pool"
)
def make_iso_date_now():
return f'{datetime.utcnow().isoformat(timespec="microseconds")}Z'
def make_date_in_future(**kw):
return f"{(datetime.utcnow() + timedelta(**kw)).date()}"
def make_random_hash() -> str:
random_hash = hashlib.sha224("SCHEMA094u".encode())
random_hash.update(make_iso_date_now().encode())
random_hash.update(f"{random.random()}".encode())
return random_hash.hexdigest()
def generate_password(length: int = 12) -> str:
alphabet = string.ascii_letters + string.digits
while True:
password = "".join(secrets.choice(alphabet) for _ in range(length))
if (
any(c.islower() for c in password)
and any(c.isupper() for c in password)
and any(c.isdigit() for c in password)
):
return password
def generate_schema_id(marker="c") -> str:
return marker + make_random_hash()
def esc(ss):
return html.escape(str(ss)).encode("ascii", "xmlcharrefreplace").decode("UTF-8")