Initial commit: SenSu Alpha 0.2.0
- 13-service async plugin framework - Textual TUI with CLI fallback - Plugin hot-reload + permission system - Web management panel (aiohttp) - Bridge-based inter-module communication - 10 regression tests Fixes applied: - PBKDF2-SHA256 auth (was plain SHA256) - Auth bypass removed (was allow-all on fail) - Bare excepts replaced with logged errors - CatFramework/DreamSu -> SenSu naming unified - ServiceManager: health checks + startup_order - Env var credentials (SENSU_ADMIN_PASSWORD etc)
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import logging
|
||||
import asyncio
|
||||
from typing import Dict, Any
|
||||
from aiohttp import web
|
||||
|
||||
try:
|
||||
from fmfuncs.plugin_command_decorator import plugin_command, command
|
||||
except ImportError:
|
||||
def plugin_command(name=None, description=None, permissions=None):
|
||||
def decorator(func): return func
|
||||
return decorator
|
||||
command = plugin_command
|
||||
|
||||
try:
|
||||
from bridges.plugin_network_bridge import PluginNetworkBridge
|
||||
except ImportError:
|
||||
class PluginNetworkBridge:
|
||||
def __init__(self, *args): pass
|
||||
async def register_http_route(self, *a, **k): pass
|
||||
async def register_websocket(self, *a, **k): pass
|
||||
async def broadcast_websocket(self, *a, **k): pass
|
||||
def get_network_info(self): return {'plugin_name': '', 'registered_routes': [], 'websocket_handlers': [], 'base_url': '不可用'}
|
||||
async def setup_data_transfer(self, *a, **k): pass
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
class Plugin:
|
||||
"""${plugin_name} 插件"""
|
||||
|
||||
def __init__(self, plugin_name: str, config: Dict, bridge):
|
||||
self.plugin_name = plugin_name
|
||||
self.config = config
|
||||
self.bridge = bridge
|
||||
self.network_bridge = None
|
||||
self.is_running = False
|
||||
logger.debug(f"插件初始化: {plugin_name}")
|
||||
|
||||
async def initialize(self):
|
||||
logger.info(f"初始化插件: {self.plugin_name}")
|
||||
self.is_running = True
|
||||
logger.debug(f"插件初始化完成: {self.plugin_name}")
|
||||
|
||||
async def shutdown(self):
|
||||
logger.info(f"关闭插件: {self.plugin_name}")
|
||||
self.is_running = False
|
||||
self.bridge.cleanup_plugin_subscriptions(self.plugin_name)
|
||||
logger.debug(f"插件关闭完成: {self.plugin_name}")
|
||||
@@ -0,0 +1,9 @@
|
||||
name: "${plugin_name}"
|
||||
version: "1.0.0"
|
||||
description: "${description}"
|
||||
author: "${author}"
|
||||
|
||||
settings:
|
||||
enabled: true
|
||||
auto_start: true
|
||||
log_level: "INFO"
|
||||
@@ -0,0 +1,10 @@
|
||||
plugin_name: "${plugin_name}"
|
||||
permissions:
|
||||
- "plugin.${plugin_name}.read"
|
||||
- "plugin.${plugin_name}.write"
|
||||
- "plugin.${plugin_name}.execute"
|
||||
|
||||
permission_descriptions:
|
||||
plugin.${plugin_name}.read: "读取${plugin_name}插件数据"
|
||||
plugin.${plugin_name}.write: "写入${plugin_name}插件数据"
|
||||
plugin.${plugin_name}.execute: "执行${plugin_name}插件操作"
|
||||
Reference in New Issue
Block a user