mirror of
https://github.com/chaitin/MonkeyCode.git
synced 2026-12-05 21:00:15 +08:00
This reverts commit 600d93eecb.
This commit is contained in:
4 files changed
-61
No files matched your search
@@ -1,19 +0,0 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
//go:embed admin.yaml
|
||||
var adminYAML []byte
|
||||
|
||||
func ServeAdminSpec(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/yaml")
|
||||
w.Header().Set("Content-Disposition", `attachment; filename="admin.yaml"`)
|
||||
w.Header().Set("Cache-Control", "private, no-store")
|
||||
if _, err := w.Write(adminYAML); err != nil && r.Context().Err() == nil {
|
||||
slog.WarnContext(r.Context(), "写入后台 OpenAPI 文档失败", "error", err)
|
||||
}
|
||||
}
|
||||
@@ -7,24 +7,6 @@ servers:
|
||||
security:
|
||||
- AdminSession: []
|
||||
paths:
|
||||
/api/admin/v1/openapi/admin.yaml:
|
||||
get:
|
||||
summary: 下载当前服务版本的后台 OpenAPI 文档
|
||||
description: 全局管理员和分组主管可使用后台登录会话下载,响应体为 admin.yaml 原文。
|
||||
responses:
|
||||
'200':
|
||||
description: 随当前服务版本发布的 YAML 文件
|
||||
headers:
|
||||
Content-Disposition:
|
||||
schema: {type: string, const: 'attachment; filename="admin.yaml"'}
|
||||
Cache-Control:
|
||||
schema: {type: string, const: 'private, no-store'}
|
||||
content:
|
||||
application/yaml:
|
||||
schema: {type: string}
|
||||
'401': {$ref: '#/components/responses/ResourceError401'}
|
||||
'403': {$ref: '#/components/responses/ResourceError403'}
|
||||
'500': {$ref: '#/components/responses/ResourceError500'}
|
||||
/api/admin/v1/settings/client_access_policy:
|
||||
get:
|
||||
summary: 查询客户端登录与令牌续期策略(仅超级管理员)
|
||||
|
||||
@@ -16,7 +16,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/chaitin/MonkeyCode/monkeyai/backend/api"
|
||||
"github.com/chaitin/MonkeyCode/monkeyai/backend/extension"
|
||||
"github.com/chaitin/MonkeyCode/monkeyai/backend/internal/agentconfig"
|
||||
"github.com/chaitin/MonkeyCode/monkeyai/backend/internal/apikey"
|
||||
@@ -305,7 +304,6 @@ func newApplicationHandlerWithMembers(ctx context.Context, logger *slog.Logger,
|
||||
admin.Use(identities.RequireAdmin, rootGroup, auditAdmin)
|
||||
console := chi.NewRouter()
|
||||
shared := console.With(identities.RequireAdminOrGroupSupervisor, rootGroup, auditAdmin)
|
||||
shared.Get("/openapi/admin.yaml", api.ServeAdminSpec)
|
||||
scopedGet := identities.MemberReads(shared.Get)
|
||||
audits.RegisterMemberReads(scopedGet)
|
||||
identities.RegisterMemberReads(scopedGet)
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -93,27 +92,6 @@ func TestSupervisorSharedReads(t *testing.T) {
|
||||
get("HEAD", p, "lead", 403)
|
||||
}
|
||||
get("GET", "/users/"+outsider, "lead", 404)
|
||||
t.Run("后台 OpenAPI 下载", func(t *testing.T) {
|
||||
const path = "/openapi/admin.yaml"
|
||||
want, err := os.ReadFile("../../api/admin.yaml")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for who, status := range map[string]int{"admin": 200, "lead": 200, "ordinary": 403, "": 401, "invalid-session": 401} {
|
||||
req := httptest.NewRequest(http.MethodGet, "/api/admin/v1"+path, nil)
|
||||
if who != "" {
|
||||
req.AddCookie(&http.Cookie{Name: "monkeyai_session", Value: who})
|
||||
}
|
||||
res := httptest.NewRecorder()
|
||||
h.ServeHTTP(res, req)
|
||||
if res.Code != status {
|
||||
t.Fatalf("%q: 状态码 %d,期望 %d", who, res.Code, status)
|
||||
}
|
||||
if status == 200 && (!bytes.Equal(res.Body.Bytes(), want) || res.Header().Get("Content-Type") != "application/yaml" || res.Header().Get("Content-Disposition") != `attachment; filename="admin.yaml"` || res.Header().Get("Cache-Control") != "private, no-store") {
|
||||
t.Fatalf("%q: 下载的文件内容或响应头不符合约定", who)
|
||||
}
|
||||
}
|
||||
})
|
||||
for _, test := range [][2]string{{"GET", "/groups/"}, {"GET", "/me"}, {"PATCH", "/users/" + outsider}, {"DELETE", "/groups/test"}, {"PUT", "/groups/test/supervisors"}, {"POST", "/license/import"}, {"POST", "/license/downgrade"}} {
|
||||
get(test[0], test[1], "lead", 403)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user