fix: validate platform keys at the gate and stop auto-register
All checks were successful
技能自动化发布 / release (push) Successful in 6s
All checks were successful
技能自动化发布 / release (push) Successful in 6s
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -8,7 +8,7 @@ from db.connection import get_conn, init_db
|
||||
from service._svc_common import _err_json, _ok_json, _resolve_or_fail, _say
|
||||
from util.constants import SKILL_SLUG
|
||||
from util.logging_config import get_skill_logger
|
||||
from util.platforms import DEFAULT_CAPABILITIES_JSON, is_valid_platform_key_format, seed_platforms
|
||||
from util.platforms import DEFAULT_CAPABILITIES_JSON, seed_platforms
|
||||
from util.runtime_paths import get_db_path
|
||||
|
||||
|
||||
@@ -76,6 +76,20 @@ def cmd_platform_get(input_key: str) -> None:
|
||||
))
|
||||
|
||||
|
||||
def _aliases_for_ensure(aliases: Optional[str], key: str, display_name: str) -> tuple[list[str], str]:
|
||||
from util.platforms import _parse_aliases_json
|
||||
|
||||
claimed: list[str] = []
|
||||
extra = _parse_aliases_json(aliases) if aliases else []
|
||||
for item in (display_name, key, *extra):
|
||||
text = (item or "").strip()
|
||||
if text and text not in claimed:
|
||||
claimed.append(text)
|
||||
if aliases:
|
||||
return claimed, aliases
|
||||
return claimed, json.dumps(claimed, ensure_ascii=False)
|
||||
|
||||
|
||||
def cmd_platform_ensure(
|
||||
key: str,
|
||||
display_name: str,
|
||||
@@ -89,25 +103,33 @@ def cmd_platform_ensure(
|
||||
幂等地注册或更新平台到 DB。
|
||||
输出单行 JSON:{"ok": true, "platform_key": "xxx", "action": "created|updated"}
|
||||
"""
|
||||
from util.platform_validate import validate_platform_registration
|
||||
|
||||
log = get_skill_logger()
|
||||
key = (key or "").strip()
|
||||
display_name = (display_name or key).strip()
|
||||
display_name = (display_name or "").strip()
|
||||
if not key:
|
||||
_say('ERROR:INVALID_ARGS platform ensure 需要 --key 参数')
|
||||
return 1
|
||||
if not is_valid_platform_key_format(key):
|
||||
_say(_err_json(
|
||||
"ERROR:INVALID_PLATFORM_KEY",
|
||||
f"平台 key 格式非法:「{key}」。建议使用小写字母、数字、下划线或连字符。",
|
||||
))
|
||||
return 1
|
||||
|
||||
aliases_json = aliases if aliases else json.dumps([key, display_name], ensure_ascii=False)
|
||||
capabilities_json = capabilities if capabilities else DEFAULT_CAPABILITIES_JSON
|
||||
|
||||
init_db()
|
||||
conn = get_conn()
|
||||
try:
|
||||
alias_list, aliases_json = _aliases_for_ensure(aliases, key, display_name)
|
||||
check = validate_platform_registration(
|
||||
key,
|
||||
display_name,
|
||||
aliases=alias_list,
|
||||
conn=conn,
|
||||
)
|
||||
if not check.ok:
|
||||
_say(_err_json(
|
||||
f"ERROR:{check.error_code}",
|
||||
check.message or "平台登记校验失败。",
|
||||
))
|
||||
return 1
|
||||
|
||||
capabilities_json = capabilities if capabilities else DEFAULT_CAPABILITIES_JSON
|
||||
existed = bool(
|
||||
conn.execute(
|
||||
"SELECT 1 FROM platforms WHERE platform_key = ?", (key,)
|
||||
|
||||
Reference in New Issue
Block a user