#!/usr/bin/env python3 """Wrapper script for RBAC permission registration. Called by modules' load_path.py scripts. Usage: py3/bin/python set_role_perm.py """ import sys import os import asyncio # Add current directory to path sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from rbac.set_role_perms import set_role_perm as _set_role_perm from appPublic.jsonConfig import getConfig from sqlor.dbpools import DBPools async def main(role, path): """Register a single permission path for a role.""" # Determine module name from path # e.g., /pipeline_core/index.ui -> pipeline_core parts = path.strip('/').split('/') module = parts[0] if parts else 'app' # Get database name from config config = getConfig('.', {'workdir': '.'}) db = DBPools(config.databases) # Call the actual permission setter await _set_role_perm('pipeline', module, '*', role, path) def run(coro): """Run async function in event loop.""" loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) try: loop.run_until_complete(coro) finally: loop.close() if __name__ == '__main__': if len(sys.argv) != 3: print(f"Usage: {sys.argv[0]} ") print(f"Example: {sys.argv[0]} logined /pipeline_core/index.ui") sys.exit(1) role = sys.argv[1] path = sys.argv[2] run(main(role, path))