65 lines
2.8 KiB
Go
65 lines
2.8 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// SQLAuditRecord SQL审计记录 // Logan.Li
|
|
type SQLAuditRecord struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
SQLContent string `gorm:"type:text;not null" json:"sql_content"`
|
|
SQLType string `gorm:"size:50" json:"sql_type"` // DDL/DML/DQL/DCL
|
|
DatabaseName string `gorm:"size:255" json:"database_name"`
|
|
TableName string `gorm:"size:255" json:"table_name"`
|
|
RiskLevel string `gorm:"size:20;default:safe" json:"risk_level"` // high/medium/low/safe
|
|
RiskRules string `gorm:"type:text" json:"risk_rules"` // JSON 数组
|
|
Status string `gorm:"size:20;default:pending" json:"status"` // pending/approved/rejected/executed
|
|
Executor string `gorm:"size:255" json:"executor"`
|
|
Approver string `gorm:"size:255" json:"approver"`
|
|
ExecuteTime *time.Time `json:"execute_time"`
|
|
AffectedRows int64 `gorm:"default:0" json:"affected_rows"`
|
|
ExecutionTime int64 `gorm:"default:0" json:"execution_time"` // 毫秒
|
|
SourceIP string `gorm:"size:100" json:"source_ip"`
|
|
Application string `gorm:"size:255" json:"application"`
|
|
TicketID string `gorm:"size:100" json:"ticket_id"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
}
|
|
|
|
func (SQLAuditRecord) TableName() string { return "sql_audit_records" }
|
|
|
|
// SQLAuditRule SQL审计规则 // Logan.Li
|
|
type SQLAuditRule struct {
|
|
ID uint `gorm:"primarykey" json:"id"`
|
|
Name string `gorm:"size:255;not null" json:"name"`
|
|
Description string `gorm:"type:text" json:"description"`
|
|
Pattern string `gorm:"type:text" json:"pattern"` // 正则/关键词匹配
|
|
Enabled bool `gorm:"default:true" json:"enabled"`
|
|
Severity string `gorm:"size:20;default:medium" json:"severity"` // high/medium/low
|
|
Category string `gorm:"size:100" json:"category"` // DDL/DML/DROP/TRUNCATE/etc
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
|
|
}
|
|
|
|
func (SQLAuditRule) TableName() string { return "sql_audit_rules" }
|
|
|
|
// AnalyzeSQLRequest SQL分析请求 // Logan.Li
|
|
type AnalyzeSQLRequest struct {
|
|
SQL string `json:"sql"`
|
|
DatabaseName string `json:"database_name"`
|
|
Application string `json:"application"`
|
|
}
|
|
|
|
// AnalyzeSQLResponse SQL分析响应 // Logan.Li
|
|
type AnalyzeSQLResponse struct {
|
|
ID int64 `json:"id"`
|
|
RiskLevel string `json:"risk_level"`
|
|
RiskRules []string `json:"risk_rules"`
|
|
SQLType string `json:"sql_type"`
|
|
TableName string `json:"table_name"`
|
|
}
|