引入基于 AK/SK -> App -> tenantId 的 OpenAPI 租户识别链路,补齐 remote 模式下的无登录态租户隔离#21
Merged
itxaiohanglover merged 1 commit intoitxaiohanglover:mainfrom Mar 7, 2026
Merged
引入基于 AK/SK -> App -> tenantId 的 OpenAPI 租户识别链路,补齐 remote 模式下的无登录态租户隔离#21itxaiohanglover merged 1 commit intoitxaiohanglover:mainfrom
itxaiohanglover merged 1 commit intoitxaiohanglover:mainfrom
Conversation
- 将 search/upload/delete 的租户解析统一收口到 SearchTenantUtils - 将 ES 从“模板全文拼接索引”重构为“基于 meta.json 的模板级元数据索引” - 为模板上传/删除增加 Redis 分布式锁,确保 ES 与文件存储更新具备幂等性 - 统一在请求完成阶段清理 ApiTenantContextHolder,避免 ThreadLocal 污染
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR 类型
变更说明
本次改动主要围绕 MCP Remote 模式下的模板搜索、上传、删除链路,补齐基于 OpenAPI AK/SK 的租户识别与 ES 租户隔离能力,并重构 ES 索引模型,提升检索准确性与可维护性。
1. 租户识别与上下文传递闭环
accessKey -> sys_app -> tenantId建立ApiTenantContextHolderSearchTenantUtils,统一 search / upload / delete 的租户解析逻辑search链路通过SearchRequest.tenantId显式透传租户,解决异步检索线程无法读取 ThreadLocal 的问题ApiTenantContextHolder,与现有UserContextHolder生命周期保持一致2. App 与文件模型补齐租户字段
AppDO改为继承TenantBaseDO,使 OpenAPI 应用具备租户归属能力AppReq增加隐藏字段tenantIdFileDO改为继承TenantBaseDO,确保上传后的sys_file记录具备租户归属3. ES 存储模型重构
meta.json的模板级元数据索引”content字段idtenantIdgroupIdartifactIdversiontitlenamedescriptionsummarytagskeywordsfileCountcreateTimetenantId:groupId:artifactId:version4. ES 搜索方式优化
name^4artifactId.text^3description^3summary^2tags.text^3tenantIdfilter,实现租户级隔离description/summary5. upload / delete 幂等性增强
RedisLockUtils分布式锁lock:template:upload:{groupId}:{artifactId}:{version}lock:template:delete:{groupId}:{artifactId}:{version}6. TemplateFileController 与服务链路整理
delete接口删除结果返回结构7. MCP 侧上传路径校验修正
upload --path恢复为严格校验,只接受groupId/artifactId/versioncodestyle-cache/...时,给出更明确的错误提示相关 Issue
测试
已执行验证
mvn -pl codestyle-plugin/codestyle-plugin-search,codestyle-server -am -DskipTests compilemvn -DskipTests compilecodestyle_templatesLocalDateTime序列化异常截图/日志
关键验证点
OpenAPI 验签开始: accessKey=..., dbTenantId=...OpenAPI 验签完成并写入 ApiTenantContextHolder: ...OpenAPI 搜索请求写入 tenantId: ...ES 检索请求已构建: index=codestyle_templates, tenantFilter=...ES 索引模板: index=..., docId=tenantId:groupId:artifactId:version检查清单
其他信息
索引迁移说明
本次 PR 调整了
codestyle_templates的 ES 文档结构与查询字段,合并前建议:注意事项
当前工作区仍存在部分与本次 PR 无关的前端/其他模块改动,提交 PR 时建议仅纳入本次 OpenAPI + Search + MCP 相关文件。