bugfix
This commit is contained in:
parent
c32854cd96
commit
931968ef48
@ -30,6 +30,17 @@ where b.orgid = ${orgid}$
|
|||||||
i = randint(0, cnt - 1)
|
i = randint(0, cnt - 1)
|
||||||
return recs[i].ownerid
|
return recs[i].ownerid
|
||||||
|
|
||||||
|
async def get_deerer(upappid, callerid):
|
||||||
|
db = DBPools()
|
||||||
|
dbname = get_dbname()
|
||||||
|
async with db.sqlorContext(dbname) as sor:
|
||||||
|
ki = await get_userapikey(sor, upappid, callerid)
|
||||||
|
d = deerer(ki.myappid, ki.apikey, ki.secretkey)
|
||||||
|
if not d:
|
||||||
|
return None
|
||||||
|
return d[7:]
|
||||||
|
return None
|
||||||
|
|
||||||
async def get_uapi(upappid, apiname):
|
async def get_uapi(upappid, apiname):
|
||||||
dbname = get_dbname()
|
dbname = get_dbname()
|
||||||
db = DBPools()
|
db = DBPools()
|
||||||
@ -37,6 +48,40 @@ async def get_uapi(upappid, apiname):
|
|||||||
return await sor_get_uapi(sor, upappid, apiname)
|
return await sor_get_uapi(sor, upappid, apiname)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
async def get_userapikey(sor, upappid, callerid):
|
||||||
|
"""
|
||||||
|
argumemts:
|
||||||
|
upappid: upappid which will make call to
|
||||||
|
orgid: owner organization or user which as the caller of the call
|
||||||
|
return:
|
||||||
|
None: this orgid has not gotton apikey from upapp
|
||||||
|
dict if apikey and upapp infos
|
||||||
|
"""
|
||||||
|
sql = """select
|
||||||
|
a.myappid,
|
||||||
|
a.ownerid as appownerid,
|
||||||
|
a.baseurl,
|
||||||
|
b.apikey,
|
||||||
|
a.secretkey
|
||||||
|
from upapp a, upappkey b
|
||||||
|
where a.id = b.upappid
|
||||||
|
and a.id = ${appid}$
|
||||||
|
and b.ownerid = ${ownerid}$"""
|
||||||
|
recs = await sor.sqlExe(sql, {'appid':upappid, 'ownerid': callerid})
|
||||||
|
if len(recs) < 1:
|
||||||
|
e = Exception(f'{upappid=}, {callerid=} has not apikey')
|
||||||
|
exception(f'{e}, {format_exc()}')
|
||||||
|
raise e
|
||||||
|
r = recs[0]
|
||||||
|
debug(f'{r=}')
|
||||||
|
return DictObject(**{
|
||||||
|
'apikey':password_decode(r.apikey),
|
||||||
|
'secretkey':password_decode(r.secretkey),
|
||||||
|
'baseurl':r.baseurl,
|
||||||
|
'appownerid': r.appownerid,
|
||||||
|
'myappid': r.myappid
|
||||||
|
})
|
||||||
|
|
||||||
async def sor_get_uapi(sor, upappid, apiname):
|
async def sor_get_uapi(sor, upappid, apiname):
|
||||||
sql = """select a.*,
|
sql = """select a.*,
|
||||||
c.auth_apiname
|
c.auth_apiname
|
||||||
@ -101,7 +146,7 @@ class UAPI:
|
|||||||
if uapi.auth_apiname:
|
if uapi.auth_apiname:
|
||||||
auth_uapi = await sor_get_uapi(sor, upappid, iuapi.auth_apiname)
|
auth_uapi = await sor_get_uapi(sor, upappid, iuapi.auth_apiname)
|
||||||
|
|
||||||
kinfo = await self.get_userapikey(sor, upappid, callerid)
|
kinfo = await get_userapikey(sor, upappid, callerid)
|
||||||
self.env.update(kinfo)
|
self.env.update(kinfo)
|
||||||
return auth_uapi, uapi
|
return auth_uapi, uapi
|
||||||
|
|
||||||
@ -181,39 +226,5 @@ class UAPI:
|
|||||||
async for chunk in gen:
|
async for chunk in gen:
|
||||||
yield chunk
|
yield chunk
|
||||||
|
|
||||||
async def get_userapikey(self, sor, upappid, callerid):
|
|
||||||
"""
|
|
||||||
argumemts:
|
|
||||||
upappid: upappid which will make call to
|
|
||||||
orgid: owner organization or user which as the caller of the call
|
|
||||||
return:
|
|
||||||
None: this orgid has not gotton apikey from upapp
|
|
||||||
dict if apikey and upapp infos
|
|
||||||
"""
|
|
||||||
sql = """select
|
|
||||||
a.myappid,
|
|
||||||
a.ownerid as appownerid,
|
|
||||||
a.baseurl,
|
|
||||||
b.apikey,
|
|
||||||
a.secretkey
|
|
||||||
from upapp a, upappkey b
|
|
||||||
where a.id = b.upappid
|
|
||||||
and a.id = ${appid}$
|
|
||||||
and b.ownerid = ${ownerid}$"""
|
|
||||||
recs = await sor.sqlExe(sql, {'appid':upappid, 'ownerid': callerid})
|
|
||||||
if len(recs) < 1:
|
|
||||||
e = Exception(f'{upappid=}, {callerid=} has not apikey')
|
|
||||||
exception(f'{e}, {format_exc()}')
|
|
||||||
raise e
|
|
||||||
r = recs[0]
|
|
||||||
debug(f'{r=}')
|
|
||||||
return DictObject(**{
|
|
||||||
'apikey':password_decode(r.apikey),
|
|
||||||
'secretkey':password_decode(r.secretkey),
|
|
||||||
'baseurl':r.baseurl,
|
|
||||||
'appownerid': r.appownerid,
|
|
||||||
'myappid': r.myappid
|
|
||||||
})
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
print('test')
|
print('test')
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
from ahserver.serverenv import ServerEnv
|
from ahserver.serverenv import ServerEnv
|
||||||
from .appapi import UAPI, deerer, bearer, get_callerid, sor_get_callerid
|
from .appapi import UAPI, deerer, bearer, get_callerid, sor_get_callerid, get_deerer
|
||||||
|
|
||||||
def load_uapi():
|
def load_uapi():
|
||||||
g = ServerEnv()
|
g = ServerEnv()
|
||||||
g.UAPI = UAPI
|
g.UAPI = UAPI
|
||||||
|
g.get_deerer = get_deerer
|
||||||
g.deerer = deerer
|
g.deerer = deerer
|
||||||
g.bearer = bearer
|
g.bearer = bearer
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user