保存完整任务报告及完成审计原子化基线,最新回归待确认
This commit is contained in:
1 parent
8a8b1a5e0e
commit
4e8d50919a
21 files changed
+505
-52
No files matched your search
@@ -0,0 +1,30 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// 完成审计从已锁定的任务取资源、操作者及项目,不信任外部传入的归属字段。
|
||||
func (r *SQLTaskRepository) recordCompletionAudit(ctx context.Context, tx *sql.Tx, completion TaskCompletion) error {
|
||||
status := completion.Status
|
||||
if status == "failed" {
|
||||
status = "error"
|
||||
}
|
||||
result, err := tx.ExecContext(ctx, r.query(`INSERT INTO audit_logs
|
||||
(action, resource_type, resource_id, status, message, created_at, scope_type, project_id, task_id, operator_id)
|
||||
SELECT ?, CASE WHEN scope_type = 'system' THEN 'management_certificate' ELSE 'domain' END,
|
||||
domain_id, ?, ?, ?, scope_type, project_id, id, operator_id
|
||||
FROM tasks WHERE id = ?`), completion.AuditAction, status, completion.Message,
|
||||
completion.FinishedAt.UTC(), completion.TaskID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("保存任务完成审计失败:%w", err)
|
||||
}
|
||||
if count, err := result.RowsAffected(); err != nil {
|
||||
return fmt.Errorf("读取任务完成审计写入结果失败:%w", err)
|
||||
} else if count != 1 {
|
||||
return sql.ErrNoRows
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user