Source code for luna_tasks.crutches_on_wheels.cow.utils.rid

"""
Module realizes  getting and checking request id
"""

import uuid
from contextvars import ContextVar

from log import getLogTimestamp

from .regexps import REQUEST_ID_REGEXP

# var contains actual requst id
requestIdCtx = ContextVar("requestId", default=None)  # pylint: disable-msg=C0103


[docs] def generateRequestId(timeIsLocal: bool) -> str: """ Generate correct request id. Args: timeIsLocal: timestamp generate in localtime or not Returns: standard request id string. """ requestId = f"{getLogTimestamp(timeIsLocal)},{uuid.uuid4()}" return requestId
[docs] def checkRequestId(requestId: str) -> bool: """ Validate request id str Args: requestId: str for checking Returns: True if requestId match with REQUEST_ID_REGEXP otherwise False """ match = REQUEST_ID_REGEXP.match(requestId) return match is not None