Merge branch 'main' of git.opencomputing.cn:yumoqing/rbac
This commit is contained in:
commit
c0ea3baef1
@ -14,6 +14,17 @@ dbname = get_module_dbname('dapi')
|
|||||||
db = DBPools()
|
db = DBPools()
|
||||||
|
|
||||||
async with db.sqlorContext(dbname) as sor:
|
async with db.sqlorContext(dbname) as sor:
|
||||||
|
dapps = await sor.R('downapp', {'id': dappid})
|
||||||
|
if not dapps:
|
||||||
|
return {
|
||||||
|
"status": "error",
|
||||||
|
"data":{
|
||||||
|
"message": f"{dappid=} not found"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dapp = dapps[0]
|
||||||
|
secretkey = password_decode(dapp.secretkey)
|
||||||
|
|
||||||
if action == 'single':
|
if action == 'single':
|
||||||
user_data = params_kw.get('user', {})
|
user_data = params_kw.get('user', {})
|
||||||
user_id = user_data.get('id', '')
|
user_id = user_data.get('id', '')
|
||||||
@ -61,6 +72,7 @@ async with db.sqlorContext(dbname) as sor:
|
|||||||
existing = await sor.R('downapikey', {'dappid': dappid, 'userid': user_id})
|
existing = await sor.R('downapikey', {'dappid': dappid, 'userid': user_id})
|
||||||
|
|
||||||
if existing:
|
if existing:
|
||||||
|
secretkey = password_decode(dapp.secretkey)
|
||||||
apikey = password_decode(existing[0].apikey)
|
apikey = password_decode(existing[0].apikey)
|
||||||
msg = '用户已同步,获取现有apikey'
|
msg = '用户已同步,获取现有apikey'
|
||||||
else:
|
else:
|
||||||
@ -79,6 +91,8 @@ async with db.sqlorContext(dbname) as sor:
|
|||||||
'data': [{
|
'data': [{
|
||||||
'user_id': user_id,
|
'user_id': user_id,
|
||||||
'apikey': apikey,
|
'apikey': apikey,
|
||||||
|
'appid': dappid,
|
||||||
|
'secretkey': secretkey,
|
||||||
'status': msg
|
'status': msg
|
||||||
}]
|
}]
|
||||||
}, ensure_ascii=False)
|
}, ensure_ascii=False)
|
||||||
@ -130,6 +144,8 @@ async with db.sqlorContext(dbname) as sor:
|
|||||||
ns_key = {
|
ns_key = {
|
||||||
'id': uuid(), 'dappid': dappid, 'userid': user_id,
|
'id': uuid(), 'dappid': dappid, 'userid': user_id,
|
||||||
'apikey': password_encode(apikey_value),
|
'apikey': password_encode(apikey_value),
|
||||||
|
'secretkey': secretkey,
|
||||||
|
'appid': dappid,
|
||||||
'enabled_date': datetime.now().strftime('%Y-%m-%d'), 'expired_date': '9999-12-31'
|
'enabled_date': datetime.now().strftime('%Y-%m-%d'), 'expired_date': '9999-12-31'
|
||||||
}
|
}
|
||||||
await sor.C('downapikey', ns_key)
|
await sor.C('downapikey', ns_key)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user