bugfix
This commit is contained in:
parent
9553afeb77
commit
e05e94da96
@ -27,11 +27,11 @@
|
|||||||
|
|
||||||
"title":"API",
|
"title":"API",
|
||||||
"description":"API定义",
|
"description":"API定义",
|
||||||
"sortby":"name",
|
"sortby":["apisetid", "name"],
|
||||||
"browserfields":{
|
"browserfields":{
|
||||||
"exclouded":["id"],
|
"exclouded":["id", "apisetid"],
|
||||||
"alters":{}
|
"alters":{}
|
||||||
},
|
},
|
||||||
"editexclouded":["id", "usid"]
|
"editexclouded":["id", "apisetid"]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,17 +4,13 @@
|
|||||||
"title":"上位系统",
|
"title":"上位系统",
|
||||||
"description":"上位系统",
|
"description":"上位系统",
|
||||||
"sortby":"name",
|
"sortby":"name",
|
||||||
|
"logined_userorgid":"ownerid",
|
||||||
"browserfields":{
|
"browserfields":{
|
||||||
"exclouded":["id"],
|
"exclouded":[],
|
||||||
"alters":{}
|
"alters":{}
|
||||||
},
|
},
|
||||||
"editexclouded":["id"],
|
"editexclouded":[],
|
||||||
"subtables":[
|
"subtables":[
|
||||||
{
|
|
||||||
"field":"upappid",
|
|
||||||
"subtable": "uapi",
|
|
||||||
"title": "API"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"field":"upappid",
|
"field":"upappid",
|
||||||
"subtable": "upappkey",
|
"subtable": "upappkey",
|
||||||
|
|||||||
@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"tblname":"upapp",
|
|
||||||
"alias":"upapp1",
|
|
||||||
"params":{
|
|
||||||
"title":"上位系统",
|
|
||||||
"sortby":"name",
|
|
||||||
"noedit":true,
|
|
||||||
"browserfields":{
|
|
||||||
"exclouded":["id"],
|
|
||||||
"alters":{}
|
|
||||||
},
|
|
||||||
"subtables":[
|
|
||||||
{
|
|
||||||
"field":"upappid",
|
|
||||||
"subtable":"upappkey",
|
|
||||||
"title":"应用密码"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -2,9 +2,9 @@
|
|||||||
"tblname":"upappkey",
|
"tblname":"upappkey",
|
||||||
"params":{
|
"params":{
|
||||||
"title":"上位系统密码",
|
"title":"上位系统密码",
|
||||||
"logined_userorgid":"ownerid",
|
"logined_useid":"ownerid",
|
||||||
"description":"上位系统密码",
|
"description":"上位系统密码",
|
||||||
"confidential_fields":["apikey", "apipasswd" ],
|
"confidential_fields":["apikey", "secretkey", "apipasswd" ],
|
||||||
"browserfields":{
|
"browserfields":{
|
||||||
"exclouded":["id", "ownerid"],
|
"exclouded":["id", "ownerid"],
|
||||||
"alters":{}
|
"alters":{}
|
||||||
|
|||||||
BIN
models/uapi.xlsx
BIN
models/uapi.xlsx
Binary file not shown.
Binary file not shown.
@ -15,37 +15,14 @@ def get_dbname():
|
|||||||
dbname = f('uapi')
|
dbname = f('uapi')
|
||||||
return dbname
|
return dbname
|
||||||
|
|
||||||
def build_deererdata(appid, apikey, secretkey):
|
def deerer(myappid, 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()
|
t = time()
|
||||||
txt = f'{t}:{apikey}'
|
txt = f'{t}:{apikey}'
|
||||||
cyber = aes_encrypt_ecb(secretkey, txt)
|
cyber = aes_encrypt_ecb(secretkey, txt)
|
||||||
return f'Manis {appid}-:-{cyber}'
|
return f'Deerer {appid}-:-{cyber}'
|
||||||
|
|
||||||
def build_dearerdata(apikey):
|
def bearer(apikey):
|
||||||
return f'Dearer {apikey}'
|
return f'Bearer {apikey}'
|
||||||
|
|
||||||
async def get_apikeys(sor, appid, userid):
|
|
||||||
ns = {
|
|
||||||
'appid':appid,
|
|
||||||
'userid':userid,
|
|
||||||
'today':curDateString()
|
|
||||||
}
|
|
||||||
sql = """select a.myid, b.apikey, b.secretkey from upapp a, upappkey b
|
|
||||||
where a.id = b.upappid
|
|
||||||
and a.id = ${appid}$
|
|
||||||
and b.owner = ${userid}$
|
|
||||||
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, userid):
|
async def sync_users(request, upappid, userid):
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
@ -53,31 +30,6 @@ async def sync_users(request, upappid, userid):
|
|||||||
async with db.sqlorContext(dbname) as sor:
|
async with db.sqlorContext(dbname) as sor:
|
||||||
upapp = await get_upapp(sor, upappid)
|
upapp = await get_upapp(sor, upappid)
|
||||||
|
|
||||||
|
|
||||||
async def bearer_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 dearer
|
|
||||||
return None
|
|
||||||
|
|
||||||
async def deerer_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_deererdata(r.myid, r.apikey, r.secretkey)
|
|
||||||
return manis
|
|
||||||
return None
|
|
||||||
|
|
||||||
class UAPI:
|
class UAPI:
|
||||||
def __init__(self, request, env=DictObject()):
|
def __init__(self, request, env=DictObject()):
|
||||||
self.te = MyTemplateEngine([], env=env)
|
self.te = MyTemplateEngine([], env=env)
|
||||||
@ -94,38 +46,47 @@ class UAPI:
|
|||||||
te = MyTemplateEngine([], env=self.env)
|
te = MyTemplateEngine([], env=self.env)
|
||||||
return te.renders(tmplstr, ns)
|
return te.renders(tmplstr, ns)
|
||||||
|
|
||||||
async def get_uapis(self, upappid, uapiid, callerid, params={}):
|
async def get_uapis(self, upappid, apiname, callerid, params={}):
|
||||||
self.env.update(params)
|
self.env.update(params)
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
dbname = get_dbname()
|
dbname = get_dbname()
|
||||||
uapi = None
|
uapi = None
|
||||||
auth_uapi = None
|
auth_uapi = None
|
||||||
async with db.sqlorContext(dbname) as sor:
|
async with db.sqlorContext(dbname) as sor:
|
||||||
recs = await sor.R('uapi', {'id':uapiid})
|
upapps = await sor.R('upapp', {'id': upappid})
|
||||||
|
if len(upapps) == 0:
|
||||||
|
e = Exceptions(f'{upappid=}, {apiname=}, {callerid=} upapp not found')
|
||||||
|
exception(f'{e=}\n{format_exc()}')
|
||||||
|
raise e
|
||||||
|
upapp = upapps[0]
|
||||||
|
apisets = await sor.R('uapiset', {'id': upapp.apisetid})
|
||||||
|
if len(apisets) == 0:
|
||||||
|
e = Exceptions(f'{upappid=}, {apiname=}, {callerid=} apiset not found')
|
||||||
|
exception(f'{e=}\n{format_exc()}')
|
||||||
|
raise e
|
||||||
|
return None, None
|
||||||
|
apiset = apisets[0]
|
||||||
|
recs = await sor.R('uapi', {'name':apiname, 'apisetid': upapp.apisetid})
|
||||||
if len(recs)==0:
|
if len(recs)==0:
|
||||||
return None, None
|
return None, None
|
||||||
uapi = recs[0]
|
uapi = recs[0]
|
||||||
kinfo = await self.get_userapikey(sor, upappid, callerid)
|
kinfo = await self.get_userapikey(sor, upappid, callerid)
|
||||||
self.env.update(kinfo)
|
self.env.update(kinfo)
|
||||||
apisets = await sor.R('uapiset', {'id': uapi.usid})
|
|
||||||
if len(apisets) == 0:
|
|
||||||
return None, None
|
|
||||||
apiset = apisets[0]
|
|
||||||
auth_uapi = None
|
auth_uapi = None
|
||||||
if apiset.auth_apiid:
|
if apiset.auth_apiname:
|
||||||
uapis = await sor.R('uapi', {'id': apiset.auth_apiid})
|
uapis = await sor.R('uapi', {'name': apiset.auth_apiname, 'apisetid': upapp.apisetid})
|
||||||
if len(uapis) == 0:
|
if len(uapis) == 0:
|
||||||
e = Exceptions(f'{upappid=}, {uapiid=}, {callerid=} {apiset.auth_apiid=} auth_apiid not found')
|
e = Exceptions(f'{upappid=}, {uapiid=}, {callerid=} {apiset.auth_apinamed=} auth_api not found')
|
||||||
exception(f'{e=}\n{format_exc()}')
|
exception(f'{e=}\n{format_exc()}')
|
||||||
raise e
|
raise e
|
||||||
auth_uapi = uapi[0]
|
auth_uapi = uapi[0]
|
||||||
return auth_uapi, uapi
|
return auth_uapi, uapi
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
async def __call__(self, upappid, upapiid, callerid, params={}):
|
async def __call__(self, upappid, apiname, callerid, params={}):
|
||||||
"""
|
"""
|
||||||
"""
|
"""
|
||||||
auth_uapi, uapi = await self.get_uapis(upapiid,
|
auth_uapi, uapi = await self.get_uapis(upapiid, apiname,
|
||||||
callerid, params=params)
|
callerid, params=params)
|
||||||
if uapi is None:
|
if uapi is None:
|
||||||
return
|
return
|
||||||
@ -135,7 +96,7 @@ class UAPI:
|
|||||||
yield line
|
yield line
|
||||||
|
|
||||||
async def request(self, upappid, upapiid, callerid, params={}):
|
async def request(self, upappid, upapiid, callerid, params={}):
|
||||||
auth_uapi, uapi = await self.get_uapis(upapiid,
|
auth_uapi, uapi = await self.get_uapis(upapiid, apiname,
|
||||||
callerid, params=params)
|
callerid, params=params)
|
||||||
if auth_uapi:
|
if auth_uapi:
|
||||||
await self.do_auth(auth_uapi)
|
await self.do_auth(auth_uapi)
|
||||||
|
|||||||
20
uapi/init.py
20
uapi/init.py
@ -1,9 +1,23 @@
|
|||||||
from ahserver.serverenv import ServerEnv
|
from ahserver.serverenv import ServerEnv
|
||||||
from .appapi import UAPI, dearer_header, manis_header
|
from .appapi import UAPI, deerer, bearer
|
||||||
|
|
||||||
def load_uapi():
|
def load_uapi():
|
||||||
g = ServerEnv()
|
g = ServerEnv()
|
||||||
g.UAPI = UAPI
|
g.UAPI = UAPI
|
||||||
g.manis_header = manis_header
|
g.deerer = deerer
|
||||||
g.dearer_header = dearer_header
|
g.bearer = bearer
|
||||||
|
|
||||||
|
# USAGE in dspy
|
||||||
|
|
||||||
|
## uapi = UAPI(request, DictObject(**globals()))
|
||||||
|
## d = uapi.request(upappid, apiname. user, params_kw)
|
||||||
|
## use d in your following code
|
||||||
|
|
||||||
|
# bearer usage
|
||||||
|
## in your header template
|
||||||
|
## {{bearer(apikey)}}
|
||||||
|
|
||||||
|
# deerer usge
|
||||||
|
## in your header template
|
||||||
|
## {{deerer(myappid, apikey, secretkey)}}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user