fix: 独立审计日志并补齐令牌身份与失败记录
This commit is contained in:
@@ -41,18 +41,18 @@ func (h *Handler) handleEndpointImport(w http.ResponseWriter, r *http.Request) {
|
||||
raw, err := readImportCSV(r)
|
||||
if err != nil {
|
||||
if httpx.IsBodyTooLarge(err) {
|
||||
h.audit(actorString(p), "endpoint_import", "", "payload_too_large", ip)
|
||||
h.auditP(p, "endpoint_import", "", "payload_too_large", ip)
|
||||
httpx.WriteError(w, http.StatusRequestEntityTooLarge, "payload_too_large", "请求体过大")
|
||||
return
|
||||
}
|
||||
h.audit(actorString(p), "endpoint_import", "", "bad_request", ip)
|
||||
h.auditP(p, "endpoint_import", "", "bad_request", ip)
|
||||
httpx.WriteError(w, http.StatusBadRequest, "bad_request", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
prepared, errs, fatal := h.validateImportCSV(r.Context(), raw)
|
||||
if fatal != nil {
|
||||
h.audit(actorString(p), "endpoint_import", "", "error", ip)
|
||||
h.auditP(p, "endpoint_import", "", "error", ip)
|
||||
if errors.Is(fatal, context.Canceled) || errors.Is(fatal, context.DeadlineExceeded) {
|
||||
httpx.WriteError(w, http.StatusServiceUnavailable, "busy", "哈希繁忙,请稍后再试")
|
||||
return
|
||||
@@ -61,7 +61,7 @@ func (h *Handler) handleEndpointImport(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
if len(errs) > 0 {
|
||||
h.audit(actorString(p), "endpoint_import", "", "bad_request", ip)
|
||||
h.auditP(p, "endpoint_import", "", "bad_request", ip)
|
||||
writeCSVValidationError(w, errs)
|
||||
return
|
||||
}
|
||||
@@ -78,15 +78,19 @@ func (h *Handler) handleEndpointImport(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
if err := h.insertEndpointsBatch(r.Context(), rows); err != nil {
|
||||
if isUniqueConstraint(err) {
|
||||
h.audit(actorString(p), "endpoint_import", "", "id_taken", ip)
|
||||
h.auditP(p, "endpoint_import", "", "id_taken", ip)
|
||||
writeCSVConflictError(w, h.importUniqueLineErrors(r.Context(), prepared))
|
||||
return
|
||||
}
|
||||
h.audit(actorString(p), "endpoint_import", "", "error", ip)
|
||||
h.auditP(p, "endpoint_import", "", "error", ip)
|
||||
httpx.WriteError(w, http.StatusInternalServerError, "internal", "内部错误")
|
||||
return
|
||||
}
|
||||
h.audit(actorString(p), "endpoint_import", strconv.Itoa(len(items)), "ok", ip)
|
||||
ids := make([]string, 0, len(prepared))
|
||||
for _, pRow := range prepared {
|
||||
ids = append(ids, pRow.Insert.ID)
|
||||
}
|
||||
h.auditPD(p, "endpoint_import", strconv.Itoa(len(items)), "ok", ip, importAuditDetail(ids))
|
||||
httpx.WriteOK(w, map[string]any{"items": items})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user