Beispiel #1
0
 def process_request(request):
     ruid = str(generate_uuid5())
     request.ruid = ruid
     request.req_start_time = time.time()
     request_id = f'{ruid}:{request.user.pk}'
     with configure_scope() as scope:
         scope.set_extra('request_id', request_id)
         scope.set_extra('usrid', request.user.pk)
         scope.set_extra('ruid', ruid)
     local.request_id = request_id  # for logger
Beispiel #2
0
def publication_qrimg(instance, filename):
    """ 场景码 主题发行记录 二维码 """
    from server.applibs.release.models import Publication
    assert isinstance(instance, Publication), type(instance).__name__
    upload_dir = OSSDir.PublicationQRImg.value
    name, ext = os.path.splitext(filename)
    msg = f'{instance.hid}-{instance.hotp_at}-{name}'
    uuid_key = idshift.generate_uuid5()
    hash_key = idshift.hmac_hash(uuid_key, msg)[-16:]
    key = f'{upload_dir}/{instance.symbol}-{hash_key}{ext}'
    return key
Beispiel #3
0
def usercode_qrimg(instance, filename):
    """ 用户码 二维码 """
    from server.applibs.account.models import UserCode
    assert isinstance(instance, UserCode), type(instance).__name__
    uuid_key = idshift.generate_uuid5()
    upload_dir = OSSDir.UserCodeQRImg.value
    name, ext = os.path.splitext(filename)
    msg = f'{instance.hid}-{instance.hotp_at}-{name}'
    hash_key = idshift.hmac_hash(uuid_key, msg)[-20:]
    key = f'{upload_dir}/{instance.code}-{hash_key}{ext}'
    return key
Beispiel #4
0
 def __init__(self, request, client=None):
     if not client:
         from .access import acs_client
         client = acs_client
     assert isinstance(client, AcsClient)
     assert isinstance(request, AcsRequest)
     request.set_accept_format('JSON')
     request.set_connect_timeout(2)
     request.set_read_timeout(6)
     self._ts = round(1000 * time.time())
     self._ruid = generate_uuid5().hex
     self._request = request
     self._client = client
Beispiel #5
0
def get_oss_key(scene, filename, instid):
    """ 根据场景获取OSS路径 """
    now = get_now()
    prefix = now.format('HHmm')
    today = now.format('YYYYMMDD')
    upload_dir = f'{scene}/{today}'
    name, ext = os.path.splitext(filename)
    uuid_key = idshift.generate_uuid5().hex[:8]
    name_key = idshift.generate_name_uuid(name).hex[-6:]
    instid = str(instid or f'none_{now.second}').lower()
    assert isinstance(scene, str) and scene in OSSDir, f'{scene}'
    new_name = f'{prefix}-{name_key}-{uuid_key}-{instid}{ext}'
    key = f'{upload_dir}/{new_name}'
    oss_key = OSSkey(key=key, name=new_name, updir=upload_dir)
    return oss_key
Beispiel #6
0
 def __init__(self, **params):
     self._ts = round(1000 * time.time())
     self._ruid = generate_uuid5().hex
     self._params = params
Beispiel #7
0
 def create_authuser(self, name=''):
     """ 创建普通用户 """
     username = str(idshift.generate_uuid5())
     inst = self.create(name=name, username=username)
     return inst