Source code for mindroot.coreplugins.admin.plugin_routes
fromfastapiimportAPIRouter,HTTPException,HeaderfrompydanticimportBaseModelimportjsonimportosfromtypingimportOptionalfromlibimportpluginsfrom.importplugin_managerfromlib.route_decoratorsimportrequires_role# Create router with admin role requirementrouter=APIRouter(dependencies=[requires_role('admin')])
[docs]@router.get("/get-plugins")asyncdefget_plugins():"""Get list of all plugins."""try:returnplugins.load_plugin_manifest()exceptExceptionase:raiseHTTPException(status_code=500,detail=str(e))
[docs]@router.post("/plugins/publish_from_github")asyncdefpublish_plugin_from_github(request:GithubPublishRequest,authorization:Optional[str]=Header(None)):"""Publish a plugin from GitHub repository to the registry. This endpoint allows publishing a plugin by simply providing the GitHub repository in the format 'username/repo'. It will fetch the plugin_info.json from the repository and publish it to the configured registry. The registry token can be provided via: 1. Authorization header: "Bearer <token>" 2. REGISTRY_TOKEN environment variable 3. registry_token in data/registry_settings.json """try:# Get registry token from multiple sourcesregistry_token=None# 1. Try Authorization headerifauthorizationandauthorization.startswith("Bearer "):registry_token=authorization.split(" ")[1]# 2. Try environment variableifnotregistry_token:registry_token=os.getenv('REGISTRY_TOKEN')# 3. Try settings fileifnotregistry_token:try:settings_file='data/registry_settings.json'ifos.path.exists(settings_file):withopen(settings_file,'r')asf:settings=json.load(f)registry_token=settings.get('registry_token')exceptExceptionase:print(f"Error reading registry settings: {e}")ifnotregistry_token:raiseHTTPException(status_code=401,detail="Registry authentication token not provided. Please provide via Authorization header, REGISTRY_TOKEN environment variable, or registry_settings.json file.")# Use the existing plugin_manager functionalityregistry_url=request.registry_urlor"https://registry.mindroot.io"result=awaitplugin_manager.publish_plugin_from_github(request.repo,registry_token,registry_url)return{"success":True,"message":f"Plugin '{result.get('title',request.repo)}' published successfully!","data":result}exceptExceptionase:importtracebacktraceback.print_exc()raiseHTTPException(status_code=500,detail=str(e))