diff --git a/README.md b/README.md index e69de29..da87df8 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,2 @@ +# kyapikeyclient + diff --git a/dapi/__init__.py b/dapi/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/dapi/dapi.py b/dapi/dapi.py new file mode 100644 index 0000000..c217438 --- /dev/null +++ b/dapi/dapi.py @@ -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 {} + diff --git a/dapi/init.py b/dapi/init.py new file mode 100644 index 0000000..98f71f3 --- /dev/null +++ b/dapi/init.py @@ -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 diff --git a/json/build.sh b/json/build.sh new file mode 100755 index 0000000..6fd2291 --- /dev/null +++ b/json/build.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +xls2ui -m ../models -o ../wwwroot kyapikey *.json diff --git a/json/upapikey.json b/json/upapikey.json new file mode 100644 index 0000000..5c5d784 --- /dev/null +++ b/json/upapikey.json @@ -0,0 +1,3 @@ +{ + "tblname":"upapikey" +} diff --git a/json/upapp.json b/json/upapp.json new file mode 100644 index 0000000..833115b --- /dev/null +++ b/json/upapp.json @@ -0,0 +1,3 @@ +{ + "tblname":"upapp" +} diff --git a/models/upapikey.xlsx b/models/upapikey.xlsx new file mode 100644 index 0000000..225cc93 Binary files /dev/null and b/models/upapikey.xlsx differ diff --git a/models/upapp.xlsx b/models/upapp.xlsx new file mode 100644 index 0000000..45c74a6 Binary files /dev/null and b/models/upapp.xlsx differ diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..59514a1 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,4 @@ +[build-system] +requires = ["setuptools>=61", "wheel"] +build-backend = "setuptools.build_meta" + diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..2135e94 --- /dev/null +++ b/setup.cfg @@ -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