优化结构
This commit is contained in:
@@ -6,7 +6,7 @@ grouped by role:
|
||||
- `handler/`: resource handlers and HTTP boundary validation
|
||||
- `middleware/`: request metadata, auth, access control, audit, recovery, CORS
|
||||
- `router/`: resource route registration and the system route registrar
|
||||
- `pkg/httpx/`: transport-level response and cookie helpers shared by handlers
|
||||
- `httpx/`: transport-level response and cookie helpers shared by handlers
|
||||
and middleware
|
||||
- `staticfiles/`: local upload storage route registration and file serving
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ func (h *API) ApplySync(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err := h.service.ApplyAPISyncRequest(c.Request.Context(), &req); err != nil {
|
||||
Fail(c, "忽略失败")
|
||||
Fail(c, "同步失败")
|
||||
return
|
||||
}
|
||||
OK(c)
|
||||
|
||||
@@ -138,7 +138,7 @@ func (h *Audit) DataAccess(c *gin.Context) {
|
||||
}
|
||||
items, total, err := h.service.DataAccessRequest(c.Request.Context(), &req)
|
||||
if err != nil {
|
||||
Fail(c, "获取失败:"+err.Error())
|
||||
Fail(c, "获取失败")
|
||||
return
|
||||
}
|
||||
Write(c, CodeSuccess, PageResult{List: items, Total: total, Page: req.Page, PageSize: req.PageSize}, "获取成功")
|
||||
@@ -150,7 +150,7 @@ func (h *Audit) DeleteDataAccess(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err := h.service.DeleteDataAccess(c.Request.Context(), req.IDs); err != nil {
|
||||
Fail(c, "删除失败:"+err.Error())
|
||||
Fail(c, "删除失败")
|
||||
return
|
||||
}
|
||||
Write(c, CodeSuccess, gin.H{}, "删除成功")
|
||||
@@ -238,7 +238,7 @@ func (h *Audit) DeleteError(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err := h.service.DeleteErrors(c.Request.Context(), []uint{id}); err != nil {
|
||||
Fail(c, "删除失败:"+err.Error())
|
||||
Fail(c, "删除失败")
|
||||
return
|
||||
}
|
||||
Write(c, CodeSuccess, gin.H{}, "删除成功")
|
||||
@@ -250,7 +250,7 @@ func (h *Audit) DeleteErrors(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err := h.service.DeleteErrors(c.Request.Context(), ids); err != nil {
|
||||
Fail(c, "批量删除失败:"+err.Error())
|
||||
Fail(c, "批量删除失败")
|
||||
return
|
||||
}
|
||||
Write(c, CodeSuccess, gin.H{}, "批量删除成功")
|
||||
@@ -262,7 +262,7 @@ func (h *Audit) UpdateError(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err := h.service.UpdateErrorRequest(c.Request.Context(), &req); err != nil {
|
||||
Fail(c, "更新失败:"+err.Error())
|
||||
Fail(c, "更新失败")
|
||||
return
|
||||
}
|
||||
Write(c, CodeSuccess, gin.H{}, "更新成功")
|
||||
@@ -275,7 +275,7 @@ func (h *Audit) Error(c *gin.Context) {
|
||||
}
|
||||
item, err := h.service.Error(c.Request.Context(), id)
|
||||
if err != nil {
|
||||
Fail(c, "查询失败:"+err.Error())
|
||||
Fail(c, "查询失败")
|
||||
return
|
||||
}
|
||||
OKWithData(c, item)
|
||||
@@ -297,7 +297,7 @@ func (h *Audit) Errors(c *gin.Context) {
|
||||
}
|
||||
items, total, err := h.service.ErrorsFilter(c.Request.Context(), p, size, c.Query("form"), c.Query("info"), createdAtRange)
|
||||
if err != nil {
|
||||
Fail(c, "获取失败:"+err.Error())
|
||||
Fail(c, "获取失败")
|
||||
return
|
||||
}
|
||||
Write(c, CodeSuccess, PageResult{List: items, Total: total, Page: p, PageSize: size}, "获取成功")
|
||||
@@ -309,7 +309,7 @@ func (h *Audit) CreateError(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
if err := h.recorder.CreateErrorMutationRequest(c.Request.Context(), &req); err != nil {
|
||||
Fail(c, "创建失败:"+err.Error())
|
||||
Fail(c, "创建失败")
|
||||
return
|
||||
}
|
||||
Write(c, CodeSuccess, gin.H{}, "创建成功")
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// This file is the handler package's single vocabulary for HTTP replies: the
|
||||
// envelope helpers come from pkg/httpx and Claims from the auth middleware, so
|
||||
// envelope helpers come from server/httpx and Claims from the auth middleware, so
|
||||
// handlers name one package instead of two.
|
||||
package handler
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ func AccessLog(runtime *config.Store, logger *slog.Logger, version string) gin.H
|
||||
started := time.Now()
|
||||
var requestBody []byte
|
||||
multipart := strings.Contains(c.GetHeader("Content-Type"), "multipart/form-data")
|
||||
mediaUpload := multipart && isMediaUploadRoute(c.FullPath())
|
||||
mediaUpload := multipart && routecatalog.BodyPolicyFor(c.Request.Method, c.Request.URL.Path) == routecatalog.BodyPolicyUpload
|
||||
var admin *config.Admin
|
||||
if runtime != nil {
|
||||
if snapshot := runtime.Snapshot(); snapshot != nil {
|
||||
@@ -170,11 +170,6 @@ func AccessLog(runtime *config.Store, logger *slog.Logger, version string) gin.H
|
||||
}
|
||||
}
|
||||
|
||||
func isMediaUploadRoute(route string) bool {
|
||||
return strings.HasSuffix(route, "/fileUploadAndDownload/upload") ||
|
||||
strings.HasSuffix(route, "/mediaUpload/chunk")
|
||||
}
|
||||
|
||||
func paymentCallbackProvider(path string) string {
|
||||
parts := strings.Split(strings.Trim(path, "/"), "/")
|
||||
for index := 0; index+2 < len(parts); index++ {
|
||||
|
||||
@@ -80,7 +80,7 @@ func OperationAudit(runtime *config.Store, recorder *systemservice.AuditRecorder
|
||||
responseBody := ""
|
||||
if value, ok := c.Get(ctxRespBufferKey); ok {
|
||||
if body, bok := value.(*bytes.Buffer); bok {
|
||||
responseBody = body.String()
|
||||
responseBody = redactJSON(body.Bytes(), c.Writer.Header().Get("Content-Type"), maxBytes)
|
||||
}
|
||||
}
|
||||
if isDownloadResponse(c) && len(responseBody) > maxBytes {
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func TestPaymentIntegrationSecretsAreRedacted(t *testing.T) {
|
||||
raw := []byte(`{"enabled":true,"config":{"app_id":"app","mch_key":"merchant-secret","api_v3_key":"v3-secret","client_cert":"certificate","client_key":"private-key","platform_cert":"platform-certificate","credential_code":"credential","webhook_id":"webhook"}}`)
|
||||
raw := []byte(`{"enabled":true,"config":{"app_id":"app","mch_key":"merchant-secret","api_v3_key":"v3-secret","client_cert":"certificate","client_key":"private-key","platform_cert":"platform-certificate","credential_code":"credential","webhook_id":"webhook","key":"institution-secret","public_cert":"public-certificate","signing_key":"jwt-secret","secret_key":"cloud-secret"}}`)
|
||||
redacted := redactJSON(raw, "application/json", 4096)
|
||||
var payload struct {
|
||||
Config map[string]string `json:"config"`
|
||||
@@ -17,7 +17,7 @@ func TestPaymentIntegrationSecretsAreRedacted(t *testing.T) {
|
||||
if err := json.Unmarshal([]byte(redacted), &payload); err != nil {
|
||||
t.Fatalf("decode redacted payload: %v", err)
|
||||
}
|
||||
for _, key := range []string{"mch_key", "api_v3_key", "client_cert", "client_key", "platform_cert", "credential_code", "webhook_id"} {
|
||||
for _, key := range []string{"mch_key", "api_v3_key", "client_cert", "client_key", "platform_cert", "credential_code", "webhook_id", "key", "public_cert", "signing_key", "secret_key"} {
|
||||
if payload.Config[key] != "***" {
|
||||
t.Fatalf("payment secret %q was not redacted: %s", key, redacted)
|
||||
}
|
||||
@@ -55,4 +55,7 @@ func TestPaymentIntegrationConfigUsesRouteLevelSummary(t *testing.T) {
|
||||
if routecatalog.BodyPolicyFor("PUT", "/api/integration/configs/mq/emqx") == routecatalog.BodyPolicyPaymentConfig {
|
||||
t.Fatal("non-payment integration was treated as payment configuration")
|
||||
}
|
||||
if routecatalog.BodyPolicyFor("POST", "/api/integration/configs/payment/saobei/test") != routecatalog.BodyPolicyPaymentConfig {
|
||||
t.Fatal("payment test route was not recognized as sensitive")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,9 @@ var sensitivePayloadKeys = map[string]struct{}{
|
||||
"password": {}, "newpassword": {}, "oldpassword": {}, "confirmpassword": {},
|
||||
"passwd": {}, "pwd": {}, "token": {}, "accesstoken": {}, "refreshtoken": {},
|
||||
"secret": {}, "clientsecret": {}, "apikey": {}, "privatekey": {}, "idcard": {},
|
||||
"key": {}, "signingkey": {}, "secretkey": {},
|
||||
"appkey": {}, "mchkey": {}, "apiv3key": {}, "clientcert": {}, "clientkey": {},
|
||||
"platformcert": {}, "platformserialno": {}, "credentialcode": {}, "certfile": {},
|
||||
"platformcert": {}, "platformserialno": {}, "publiccert": {}, "credentialcode": {}, "certfile": {},
|
||||
"keyfile": {}, "publickey": {}, "rootcert": {}, "appcert": {}, "webhookid": {},
|
||||
"authorization": {},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user