From b9c02abfda4bd3de3ccd71ed6d74bf25189cca03 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 23 Jul 2025 15:21:31 +0800 Subject: [PATCH] bugfix --- uapi/appapi.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++ uapi/init.py | 4 ++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/uapi/appapi.py b/uapi/appapi.py index c8025ed..c8edccc 100644 --- a/uapi/appapi.py +++ b/uapi/appapi.py @@ -15,6 +15,73 @@ def get_dbname(): dbname = f('uapi') return dbname +def build_manisdata(appid, apikey, secretkey): + """ + this appid is isusses by upapp we connect to, + secretkey is with the appid, is s fixed key from upapp + apikey is user's apikey assigned by upapp when the users is synchronous to upapp + """ + t = time() + txt = f'{t}:{apikey}' + cyber = aes_encrypt_ecb(secretkey, txt) + return f'Manis {appid}-:-{cyber}' + +def build_dearerdata(apikey): + return f'Dearer {apikey}' + +async def get_apikeys(sor, appid, orgid, userid): + ns = { + 'appid':appid, + 'orgid':orgid, + 'userid':userid, + 'today':curDateString() + } + sql = """select a.myid, b.apikey, b.secretkey from upapp a, upapikey b +where a.upappid = ${appid}$ + and b.userid = ${userid}$ + and b.orgid = ${orgid}$ + and b.expired_date > ${today}$ + and b.enabled_date <= ${today}$""" + recs = await sor.sqlExe(sql, ns) + if len(recs) > 0: + r = recs[0] + return r + return r + +async def sync_users(request, upappid, orgid): + db = DBPools() + dbname = get_dbname() + async with db.sqlorContext(dbname) as sor: + upapp = await get_upapp(sor, upappid) + +async def dearer_header(request, appid): + db = DBPools() + dbname = get_dbname() + async with db.sqlorContext(dbname) as sor: + u = await get_session_userinfo(request) + r = await get_apikeys(sor, appid, u.userorgid, u.userid) + if r is None: + return None + dearer = build_dearerdata(r.apikey) + return { + "Authorization": dearer + } + return {} + +async def manis_header(request, appid): + db = DBPools() + dbname = get_dbname() + async with db.sqlorContext(dbname) as sor: + u = await get_session_userinfo(request) + r = await get_apikeys(sor, appid, u.userorgid, u.userid) + if r is None: + return None + manis = build_manisdata(r.myid, r.apikey, r.secretkey) + return { + "Authorization": manis + } + return {} + class UAPI: def __init__(self, env={}): self.te = MyTemplateEngine([], env=env) diff --git a/uapi/init.py b/uapi/init.py index cb41627..d81835f 100644 --- a/uapi/init.py +++ b/uapi/init.py @@ -1,7 +1,9 @@ from ahserver.serverenv import ServerEnv -from .appapi import UAPI +from .appapi import UAPI, dearer_header, manis_header def load_uapi(): g = ServerEnv() g.UAPI = UAPI + g.manis_header = manis_header + g.dearer_header = dearer_header