F1 告警静默规则 [done]: - 后端 alert_silence.go: CRUD + Toggle (onetime/daily/weekly 三模式) - 告警引擎 isSilenced 集成 (alert_engine.go) - 前端 SilenceRuleTab + SilenceDialog - 路由 /alerts/silences 已注册 F2 审计日志导出 [done]: - 重写 ExportAuditLogs: 真正的 CSV 导出 (encoding/csv + UTF-8 BOM) - 支持 module/action/username/startTime/endTime 筛选 - 导出限制 10000 条防溢出,自动记录审计日志 - JSON 格式向后兼容 (format=json) - 前端 exportLogs 传递查询参数 同时包含累积的前期工作: - 目录重构 internal/ -> controller/model/router (v0.55-v0.57) - 后端分层架构 dto/repository/service/utils - 审计模块全功能 (终端审计/操作审计/登录日志) - asciicast v2 录制格式 - SFTP 文件浏览器 - StatStrip 紧凑统计条 - 在线会话自动刷新 - LiveMonitor WebSocket 诊断修复 验证: go build ✅ | npm run build ✅ | Docker 部署 ✅ | 10 回归端点 ✅ | CSV 导出 ✅ | 静默 CRUD ✅
194 lines
8.8 KiB
Go
194 lines
8.8 KiB
Go
package model
|
||
|
||
import "time"
|
||
|
||
// ============================================
|
||
// PipelineRepo Git 仓库认证配置
|
||
// ============================================
|
||
|
||
// RepoAuthType 仓库认证方式
|
||
type RepoAuthType string
|
||
|
||
const (
|
||
RepoAuthToken RepoAuthType = "token" // Personal Access Token
|
||
RepoAuthSSH RepoAuthType = "ssh" // SSH Key
|
||
RepoAuthPassword RepoAuthType = "password" // 用户名+密码
|
||
)
|
||
|
||
// PipelineRepo Git 仓库认证配置表
|
||
type PipelineRepo struct {
|
||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||
Name string `gorm:"type:varchar(128);not null;comment:配置名称" json:"name"`
|
||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||
URL string `gorm:"type:varchar(512);not null;comment:仓库 URL" json:"url"`
|
||
AuthType RepoAuthType `gorm:"type:varchar(16);default:'token';comment:认证方式: token/ssh/password" json:"auth_type"`
|
||
CredentialID *uint `gorm:"index;comment:凭据ID(关联 iam_credentials)" json:"credential_id,omitempty"`
|
||
Enabled bool `gorm:"default:true;comment:是否启用" json:"enabled"`
|
||
CreatedBy string `gorm:"type:varchar(64);comment:创建人" json:"created_by,omitempty"`
|
||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||
}
|
||
|
||
// TableName 表名
|
||
func (PipelineRepo) TableName() string {
|
||
return "deploy_pipeline_repos"
|
||
}
|
||
|
||
// ============================================
|
||
// PipelineRegistry 镜像仓库认证配置
|
||
// ============================================
|
||
|
||
// RegistryAuthType 镜像仓库认证方式
|
||
type RegistryAuthType string
|
||
|
||
const (
|
||
RegistryAuthToken RegistryAuthType = "token" // Access Token
|
||
RegistryAuthPassword RegistryAuthType = "password" // 用户名+密码
|
||
)
|
||
|
||
// PipelineRegistry 镜像仓库认证配置表
|
||
type PipelineRegistry struct {
|
||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||
Name string `gorm:"type:varchar(128);not null;comment:配置名称" json:"name"`
|
||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||
RegistryURL string `gorm:"type:varchar(512);not null;comment:镜像仓库地址" json:"registry_url"`
|
||
Namespace string `gorm:"type:varchar(128);comment:默认命名空间" json:"namespace,omitempty"`
|
||
AuthType RegistryAuthType `gorm:"type:varchar(16);default:'password';comment:认证方式: token/password" json:"auth_type"`
|
||
CredentialID *uint `gorm:"index;comment:凭据ID(关联 iam_credentials)" json:"credential_id,omitempty"`
|
||
Enabled bool `gorm:"default:true;comment:是否启用" json:"enabled"`
|
||
CreatedBy string `gorm:"type:varchar(64);comment:创建人" json:"created_by,omitempty"`
|
||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||
}
|
||
|
||
// TableName 表名
|
||
func (PipelineRegistry) TableName() string {
|
||
return "deploy_pipeline_registries"
|
||
}
|
||
|
||
// ============================================
|
||
// PipelineStage 流水线阶段定义(JSON)
|
||
// ============================================
|
||
|
||
// PipelineStage 一个阶段包含多个任务
|
||
type PipelineStage struct {
|
||
ID string `json:"id"`
|
||
Name string `json:"name"`
|
||
Type string `json:"type"` // source/build/deploy/test/custom
|
||
Tasks []PipelineTask `json:"tasks"`
|
||
}
|
||
|
||
// PipelineTask 阶段内的任务
|
||
type PipelineTask struct {
|
||
ID string `json:"id"`
|
||
Name string `json:"name"`
|
||
Type string `json:"type"` // build/deploy/test/custom
|
||
Icon string `json:"icon,omitempty"`
|
||
Config map[string]string `json:"config,omitempty"`
|
||
Script string `json:"script,omitempty"`
|
||
ScriptType string `json:"script_type,omitempty"` // shell/python
|
||
}
|
||
|
||
// ============================================
|
||
// DeployEnvironment 发布环境分组
|
||
// ============================================
|
||
|
||
type EnvironmentType string
|
||
|
||
const (
|
||
EnvProduction EnvironmentType = "production"
|
||
EnvStaging EnvironmentType = "staging"
|
||
EnvTesting EnvironmentType = "testing"
|
||
EnvDev EnvironmentType = "development"
|
||
)
|
||
|
||
// DeployEnvironment 环境分组表(生产/测试/预发布/开发)
|
||
type DeployEnvironment struct {
|
||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||
Name string `gorm:"type:varchar(64);not null;uniqueIndex;comment:环境名称" json:"name"`
|
||
DisplayName string `gorm:"type:varchar(128);not null;comment:显示名称" json:"display_name"`
|
||
Type EnvironmentType `gorm:"type:varchar(16);not null;index;comment:环境类型: production/staging/testing/development" json:"type"`
|
||
Color string `gorm:"type:varchar(16);default:'#3B82F6';comment:标识颜色" json:"color"`
|
||
SortOrder int `gorm:"default:0;comment:排序" json:"sort_order"`
|
||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||
Enabled bool `gorm:"default:true;comment:是否启用" json:"enabled"`
|
||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||
}
|
||
|
||
func (DeployEnvironment) TableName() string {
|
||
return "deploy_environments"
|
||
}
|
||
|
||
// ============================================
|
||
// DeployPipelineMember 流水线成员
|
||
// ============================================
|
||
|
||
type MemberRole string
|
||
|
||
const (
|
||
MemberOwner MemberRole = "owner" // 拥有者
|
||
MemberEditor MemberRole = "editor" // 编辑者
|
||
MemberViewer MemberRole = "viewer" // 查看者
|
||
)
|
||
|
||
// DeployPipelineMember 流水线成员表
|
||
// 支持两种授权方式:直接用户授权(username 非空)和用户组授权(group_id 非空)
|
||
type DeployPipelineMember struct {
|
||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||
PipelineID uint `gorm:"index:idx_pipeline_user,unique,priority:1;index:idx_pipeline_group,unique,priority:1;not null;comment:流水线ID" json:"pipeline_id"`
|
||
Username *string `gorm:"type:varchar(64);index:idx_pipeline_user,unique,priority:2;comment:用户名(直接授权)" json:"username,omitempty"`
|
||
GroupID *uint `gorm:"index:idx_pipeline_group,unique,priority:2;comment:用户组ID(组授权)" json:"group_id,omitempty"`
|
||
Role MemberRole `gorm:"type:varchar(16);default:'editor';comment:角色: owner/editor/viewer" json:"role"`
|
||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||
|
||
// 关联
|
||
Pipeline *Pipeline `json:"pipeline,omitempty" gorm:"foreignKey:PipelineID"`
|
||
Group *DeployUserGroup `json:"group,omitempty" gorm:"foreignKey:GroupID"`
|
||
}
|
||
|
||
func (DeployPipelineMember) TableName() string {
|
||
return "deploy_pipeline_members"
|
||
}
|
||
|
||
// ============================================
|
||
// DeployUserGroup 发布系统用户组
|
||
// ============================================
|
||
|
||
// DeployUserGroup 用户组(用于流水线权限分组授权)
|
||
type DeployUserGroup struct {
|
||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||
Name string `gorm:"type:varchar(64);uniqueIndex;not null;comment:组名称" json:"name"`
|
||
Description string `gorm:"type:varchar(256);comment:描述" json:"description,omitempty"`
|
||
CreatedBy string `gorm:"type:varchar(64);comment:创建人" json:"created_by,omitempty"`
|
||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||
UpdatedAt time.Time `gorm:"not null;comment:更新时间" json:"updated_at"`
|
||
|
||
// 关联
|
||
Members []DeployUserGroupMember `json:"members,omitempty" gorm:"foreignKey:GroupID"`
|
||
}
|
||
|
||
func (DeployUserGroup) TableName() string {
|
||
return "deploy_user_groups"
|
||
}
|
||
|
||
// ============================================
|
||
// DeployUserGroupMember 用户组成员
|
||
// ============================================
|
||
|
||
// DeployUserGroupMember 用户组成员关联表
|
||
type DeployUserGroupMember struct {
|
||
ID uint `gorm:"primaryKey;autoIncrement;comment:主键ID" json:"id"`
|
||
GroupID uint `gorm:"uniqueIndex:idx_group_user;not null;comment:组ID" json:"group_id"`
|
||
Username string `gorm:"type:varchar(64);uniqueIndex:idx_group_user;not null;comment:用户名" json:"username"`
|
||
CreatedAt time.Time `gorm:"not null;comment:创建时间" json:"created_at"`
|
||
|
||
// 关联
|
||
Group *DeployUserGroup `json:"group,omitempty" gorm:"foreignKey:GroupID"`
|
||
}
|
||
|
||
func (DeployUserGroupMember) TableName() string {
|
||
return "deploy_user_group_members"
|
||
}
|