bugfix
This commit is contained in:
parent
7bbdb1bd35
commit
0bee1ea891
0
dapi/__init__.py
Normal file
0
dapi/__init__.py
Normal file
81
dapi/dapi.py
Normal file
81
dapi/dapi.py
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
|
||||||
|
from time import time
|
||||||
|
from appPublic.aes import aes_encrypt_ecb, aes_decrypt_ecb
|
||||||
|
from appPublic.timeUtils import curDateString
|
||||||
|
from sqlor.dbpools import DBPools
|
||||||
|
from ahserver.serverenv import get_serverenv
|
||||||
|
from ahserver.auth_api import get_session_userinfo
|
||||||
|
|
||||||
|
def get_dbname():
|
||||||
|
f = get_serverenv('get_module_dbname')
|
||||||
|
if f:
|
||||||
|
return f('dapi')
|
||||||
|
return None
|
||||||
|
|
||||||
|
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 {}
|
||||||
|
|
||||||
7
dapi/init.py
Normal file
7
dapi/init.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
from daap.dapi import dearer_header, manis_header
|
||||||
|
from ahserver.serverenv import ServerEnv
|
||||||
|
|
||||||
|
def load_dapi():
|
||||||
|
env = ServerEnv
|
||||||
|
env.dearer_header = dearer_header
|
||||||
|
env.manis_header = manis_header
|
||||||
3
json/build.sh
Executable file
3
json/build.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
xls2ui -m ../models -o ../wwwroot kyapikey *.json
|
||||||
3
json/upapikey.json
Normal file
3
json/upapikey.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"tblname":"upapikey"
|
||||||
|
}
|
||||||
3
json/upapp.json
Normal file
3
json/upapp.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"tblname":"upapp"
|
||||||
|
}
|
||||||
BIN
models/upapikey.xlsx
Normal file
BIN
models/upapikey.xlsx
Normal file
Binary file not shown.
BIN
models/upapp.xlsx
Normal file
BIN
models/upapp.xlsx
Normal file
Binary file not shown.
4
pyproject.toml
Normal file
4
pyproject.toml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["setuptools>=61", "wheel"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
|
|
||||||
15
setup.cfg
Normal file
15
setup.cfg
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[metadata]
|
||||||
|
name=kyapikeyclient
|
||||||
|
version = 0.0.2
|
||||||
|
description = Your project description
|
||||||
|
author = "yu moqing"
|
||||||
|
author_email = "yumoqing@gmail.com"
|
||||||
|
readme = "README.md"
|
||||||
|
license = "MIT"
|
||||||
|
[options]
|
||||||
|
packages = find:
|
||||||
|
requires_python = ">=3.8"
|
||||||
|
install_requires =
|
||||||
|
apppublic
|
||||||
|
sqlor
|
||||||
|
ahserver
|
||||||
Loading…
x
Reference in New Issue
Block a user