feat(data-sources): 支持外部插件安装与版本管理

Signed-off-by: shy3130 <shy3130@qq.com>
This commit is contained in:
shy3130
2026-11-01 10:47:19 +08:00
parent ba27fc932b
commit 762e04ab88
24 changed files with 1649 additions and 72 deletions
+13
View File
@@ -0,0 +1,13 @@
"""Replace this URL and field mapping with your provider's documented contract."""
import httpx
BASE_URL = "https://example.invalid"
def fetch(key: str) -> list[dict]:
if BASE_URL.endswith(".invalid"):
raise ValueError("请先修改模板的接口地址")
with httpx.Client(timeout=15) as client:
response = client.get(f"{BASE_URL}/quotes", headers={"Authorization": f"Bearer {key}"})
response.raise_for_status()
return response.json()["data"]
+13
View File
@@ -0,0 +1,13 @@
name: example_http
version: 1.0.0
plugin_api_version: 1
display_name: HTTP 数据源模板
author: 插件开发者
runtime: none
entry: provider:Provider
requires_app: '>=0.3.24'
requires_python: '>=3.11'
platforms: [any]
datasets: [realtime]
api_key_env: EXAMPLE_HTTP_API_KEY
description: 开发模板,请先在 client.py 配置真实接口并完成字段转换和测试。
+32
View File
@@ -0,0 +1,32 @@
"""Example only: vendor data must already match the documented normalized schema."""
from types import SimpleNamespace
from app import secrets_store
from app.data_providers.base import ProviderRequestError
from .client import fetch
def probe_api_key(key):
try:
fetch(key)
return True, "接口可连接;其他能力权限需另行验证"
except Exception: # noqa: BLE001 — never return raw HTTP errors containing credentials
return False, "验证失败,请检查接口地址、Key、权限与网络"
class Provider:
name = "example_http"
def __init__(self):
self.config = SimpleNamespace(datasets={"realtime": {}})
self.key = secrets_store.get_env_backed_secret("example_http_api_key", "EXAMPLE_HTTP_API_KEY")
def get_realtime(self):
try:
return fetch(self.key)
except Exception as exc:
raise ProviderRequestError("行情请求失败,请检查供应商服务") from exc
def close(self):
pass