fix: float fields + RBAC init script
This commit is contained in:
parent
db15bb5ea5
commit
0921f4d7f3
@ -16,7 +16,7 @@
|
|||||||
{"name": "api_calls", "title": "API调用数", "type": "int", "default": 1},
|
{"name": "api_calls", "title": "API调用数", "type": "int", "default": 1},
|
||||||
{"name": "engine_type", "title": "引擎类型", "type": "str", "length": 32},
|
{"name": "engine_type", "title": "引擎类型", "type": "str", "length": 32},
|
||||||
{"name": "tokens_used", "title": "Token消耗", "type": "int", "default": 0},
|
{"name": "tokens_used", "title": "Token消耗", "type": "int", "default": 0},
|
||||||
{"name": "cost_estimate", "title": "预估费用", "type": "float", "dec": 4},
|
{"name": "cost_estimate", "title": "预估费用", "type": "float", "length": 20, "dec": 4},
|
||||||
{"name": "detail", "title": "详情JSON", "type": "text", "length": 2000},
|
{"name": "detail", "title": "详情JSON", "type": "text", "length": 2000},
|
||||||
{"name": "created_at", "title": "创建时间", "type": "datetime"}
|
{"name": "created_at", "title": "创建时间", "type": "datetime"}
|
||||||
],
|
],
|
||||||
|
|||||||
85
scripts/init_rbac.py
Normal file
85
scripts/init_rbac.py
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
# -*- coding:utf-8 -*-
|
||||||
|
"""RAG Server RBAC 权限初始化"""
|
||||||
|
import sys, os
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), 'pkgs', 'rag-pipeline'))
|
||||||
|
|
||||||
|
from ahserver.serverenv import ServerEnv
|
||||||
|
from sqlor.sqlor import DBPools
|
||||||
|
from appPublic.jsonConfig import getConfig
|
||||||
|
from appPublic.log import debug
|
||||||
|
import asyncio
|
||||||
|
|
||||||
|
config = getConfig('.')
|
||||||
|
DBPools(config.databases)
|
||||||
|
|
||||||
|
from rbac.userperm import UserPerm
|
||||||
|
|
||||||
|
PUBLIC_PATHS = [
|
||||||
|
'/api/status',
|
||||||
|
'/api/engines',
|
||||||
|
'/api/kb/list',
|
||||||
|
'/',
|
||||||
|
'/index.ui',
|
||||||
|
]
|
||||||
|
|
||||||
|
LOGINED_PATHS = [
|
||||||
|
'/api/search',
|
||||||
|
'/api/ingest',
|
||||||
|
'/knowledge_bases_list/',
|
||||||
|
'/documents_list/',
|
||||||
|
'/engine_configs_list/',
|
||||||
|
'/subscriptions_list/',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
async def init_perms():
|
||||||
|
sor = await DBPools().get_sor_context('rag')
|
||||||
|
up = UserPerm()
|
||||||
|
await up.init(sor)
|
||||||
|
|
||||||
|
# Create 'any' role for public access
|
||||||
|
recs = await sor.sqlExe("SELECT id FROM role WHERE id='any'", {})
|
||||||
|
if not recs:
|
||||||
|
await sor.sqlExe(
|
||||||
|
"INSERT INTO role (id, rolename, orgtypeid, roletype, del_flg) "
|
||||||
|
"VALUES ('any', 'any', '', 'any', '0')", {}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create 'logined' role
|
||||||
|
recs = await sor.sqlExe("SELECT id FROM role WHERE id='logined'", {})
|
||||||
|
if not recs:
|
||||||
|
await sor.sqlExe(
|
||||||
|
"INSERT INTO role (id, rolename, orgtypeid, roletype, del_flg) "
|
||||||
|
"VALUES ('logined', 'logined', '', 'logined', '0')", {}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Register public paths
|
||||||
|
for path in PUBLIC_PATHS:
|
||||||
|
perm_id = f"perm_{path.replace('/', '_')}"
|
||||||
|
await sor.sqlExe(
|
||||||
|
f"INSERT IGNORE INTO permission (id, path, name) VALUES ('{perm_id}', '{path}', 'RAG {path}')",
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
await sor.sqlExe(
|
||||||
|
f"INSERT IGNORE INTO rolepermission (role_id, permission_id) VALUES ('any', '{perm_id}')",
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Register logined paths
|
||||||
|
for path in LOGINED_PATHS:
|
||||||
|
perm_id = f"perm_{path.replace('/', '_')}"
|
||||||
|
await sor.sqlExe(
|
||||||
|
f"INSERT IGNORE INTO permission (id, path, name) VALUES ('{perm_id}', '{path}', 'RAG {path}')",
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
await sor.sqlExe(
|
||||||
|
f"INSERT IGNORE INTO rolepermission (role_id, permission_id) VALUES ('logined', '{perm_id}')",
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|
||||||
|
print(f"RBAC initialized: {len(PUBLIC_PATHS)} public + {len(LOGINED_PATHS)} logined paths")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
asyncio.run(init_perms())
|
||||||
Loading…
x
Reference in New Issue
Block a user