Files
opsxdb/server/internal/aitools/secrets.go
T
logan 0b68c8344d feat(mcp): P0 只读 MCP tool runtime + opsxdb-mcp stdio
- aitools 共用 runtime:list/describe/schema/query/redis(纯只读,无写确认)
- 白名单 ~/.opsxdb/mcp.json;审计 mcp-audit.jsonl;复用 danger.go
- 桌面 connections 双写 ~/.opsxdb/connections.json(ox1. 解码)
- Cursor 配置示例与任务书验收勾选更新;写操作与 Agent UI 留 P1
2026-10-15 11:14:08 +08:00

31 lines
694 B
Go

package aitools
import (
"encoding/base64"
"net/url"
"strings"
)
const secretPrefix = "ox1."
// DecodeSecret 与前端 src/secrets.ts decodeSecret 对齐:ox1. + base64(utf8)。 // Logan.Li
func DecodeSecret(stored string) string {
if stored == "" {
return ""
}
if !strings.HasPrefix(stored, secretPrefix) {
return stored
}
raw, err := base64.StdEncoding.DecodeString(stored[len(secretPrefix):])
if err != nil {
return stored
}
// 前端 encodeURIComponent 再 btoa;解码侧 escape/atob/decodeURIComponent。
// Go 侧:先按 latin1 字节还原,再尝试 URL unescape。
s := string(raw)
if u, err := url.QueryUnescape(s); err == nil {
return u
}
return s
}