Skip to content

Conversation

weibaohui
Copy link
Owner

增加 Swagger 文档支持

weibaohui added 3 commits June 4, 2025 21:57
修复集群权限校验逻辑,确保管理员权限也能正确校验命名空间权限
更新用户和管理员界面的授权相关文案,使其更清晰准确
在集群管理页面添加命名空间选择功能
将简单的密钥显示改为包含完整使用示例的HTML内容,展示如何获取节点列表的示例代码和请求头设置
- 新增swagger生成脚本及文档文件
- 在中间件中排除swagger路径的认证检查
- 为集群接口添加swagger注解
- 更新API密钥使用示例链接指向swagger文档
- 集成gin-swagger库并配置路由
- 添加相关依赖到go.mod
Copy link
Contributor

coderabbitai bot commented Jun 4, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Summary by CodeRabbit

  • 新功能
    • 集成并上线了 Swagger UI,提供 API 文档页面(/swagger),支持 Bearer Token 认证。
    • 新增 API 接口:获取集群文件选项列表(/admin/cluster/file/option_list)。
  • 权限优化
    • 集群管理员在执行 exec 操作时需校验命名空间权限,权限判定更细致。
    • 只读与管理员角色均可访问集群读操作。
  • 界面优化
    • 集群授权页面支持命名空间限制与选择,显示方式更直观。
    • 用户授权、API 密钥等页面提示与操作说明优化,API 密钥弹窗新增使用示例及文档入口。
    • 我的集群、用户授权等页面文案调整,更清晰表达授权与权限说明。
  • 开发体验
    • 前端开发环境支持 /swagger 路径代理,便于本地调试 API 文档。
    • Swagger 相关依赖与生成脚本新增,便于后续文档维护。

Walkthrough

本次变更主要引入了 Swagger API 文档集成,包括后端 Gin 服务的 Swagger UI 接入、Swagger 文档生成脚本与配置文件,并在集群管理相关 API 增加了 Swagger 注解和接口。权限校验逻辑针对集群管理员和命名空间做了细化。前端方面,集群授权、用户授权、API Key 使用说明等页面的提示文案和交互细节进行了调整,Vite 代理配置新增了对 Swagger 路径的支持。

Changes

文件/路径分组 变更摘要
go.mod 新增 Swagger 相关依赖(swaggo 系列),并升级部分依赖版本,添加间接依赖。
main.go 集成 Swagger UI,注册 /swagger/*any 路由,添加 API 文档注释。
pkg/cb/cb.go 优化权限校验逻辑,细化集群管理员对 exec 操作的命名空间限制,统一只读/管理员读权限判断。
pkg/controller/admin/cluster/cluster.go 新增 FileOptionList 接口及 Swagger 注解,实现集群文件名去重选项列表查询。
pkg/middleware/auth.go
pkg/middleware/cluster.go
/swagger/ 路径请求免登录与免集群校验处理。
swagger/docs.go 新增自动生成的 Swagger 文档实现,定义 API 元数据、接口描述与安全策略。
swagger/make.sh 新增 Swagger 文档生成脚本,配置生成参数及目录。
swagger/swagger.json
swagger/swagger.yaml
新增 Swagger 2.0 规范的 API 文档文件,描述 /admin/cluster/file/option_list 接口及安全定义。
ui/public/pages/admin/cluster/cluster_all.json 集群授权 UI 增加命名空间限制控件与提示,调整 drawer 标题及说明。
ui/public/pages/admin/user/user.json 用户授权抽屉按钮与提示文案优化,突出“已获授权”及操作指引。
ui/public/pages/user/profile/api_keys.json API Key 查看弹窗改为用法示例,包含 Bearer Token 头部说明及文档链接。
ui/public/pages/user/profile/my_clusters.json 我的集群页面提示文案优化,明确“Exec”权限,突出已获授权集群及操作说明。
ui/vite.config.ts Vite dev server 代理新增 /swagger 路径支持,处理路径恢复逻辑。

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Browser
    participant GinServer
    participant SwaggerUI
    participant SwaggerDocs

    User->>Browser: 访问 /swagger/index.html
    Browser->>GinServer: GET /swagger/index.html
    GinServer->>SwaggerUI: 返回 Swagger UI 静态页面
    Browser->>GinServer: GET /swagger/doc.json
    GinServer->>SwaggerDocs: 读取并渲染 swagger/docs.go
    SwaggerDocs-->>GinServer: 返回 API 文档 JSON
    GinServer-->>Browser: 返回 swagger 文档内容
    Browser->>User: 展示交互式 API 文档
Loading
sequenceDiagram
    participant 前端页面
    participant GinServer
    participant ClusterController
    participant ClusterService
    participant DB

    前端页面->>GinServer: GET /admin/cluster/file/option_list (带 Bearer Token)
    GinServer->>ClusterController: 路由分发
    ClusterController->>ClusterService: 查询所有集群
    ClusterService->>DB: 查询集群数据
    DB-->>ClusterService: 返回集群列表
    ClusterService-->>ClusterController: 返回集群数据
    ClusterController->>GinServer: 去重文件名并返回选项列表
    GinServer-->>前端页面: 返回 JSON 选项列表
Loading

Possibly related PRs

  • weibaohui/k8m#159: 该 PR 移除了集群管理页面的命名空间选择,与本次 PR 在同一 UI 功能点上(命名空间限制控件)有直接的代码关联和相反的实现方向。

Poem

🐇
Swagger 文档闪亮登场,
集群权限细致又周详。
前端后端齐更新,
授权说明更贴心。
API Key 用法清晰明,
兔子跳跃赞一声:
“开发体验更上一层!”


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f043a5c and d6496a6.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (15)
  • go.mod (7 hunks)
  • main.go (3 hunks)
  • pkg/cb/cb.go (3 hunks)
  • pkg/controller/admin/cluster/cluster.go (1 hunks)
  • pkg/middleware/auth.go (1 hunks)
  • pkg/middleware/cluster.go (1 hunks)
  • swagger/docs.go (1 hunks)
  • swagger/make.sh (1 hunks)
  • swagger/swagger.json (1 hunks)
  • swagger/swagger.yaml (1 hunks)
  • ui/public/pages/admin/cluster/cluster_all.json (3 hunks)
  • ui/public/pages/admin/user/user.json (2 hunks)
  • ui/public/pages/user/profile/api_keys.json (1 hunks)
  • ui/public/pages/user/profile/my_clusters.json (2 hunks)
  • ui/vite.config.ts (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@weibaohui weibaohui merged commit d627ad0 into main Jun 4, 2025
1 check was pending
@weibaohui weibaohui deleted the swagger branch June 5, 2025 14:57
@coderabbitai coderabbitai bot mentioned this pull request Jun 15, 2025
@coderabbitai coderabbitai bot mentioned this pull request Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant