Files
aiops/backend/internal/models/credential.go
T
attacker 5949ec5d0c feat: Agent采集uptime, 后端持久化kernel/uptime/diskIO, 前端磁盘BPS+IOPS展示
- Agent: system.go 添加 readUptime(), SystemStat 携带 Uptime
- Backend: Server 模型新增 Kernel 字段, ReceiveReport 持久化 kernel+uptime
- Backend: /agent/latest 返回 kernel/uptime/port_info/disk_io_info/disk_total
- Frontend: 磁盘监控改为 BPS+IOPS (4张卡片), 系统信息修复内核/运行时长/监听端口/磁盘容量
- 图表单位从 MB/s 改为 KB/s, 添加 formatBPS 工具函数
2026-06-19 01:10:00 +00:00

48 lines
1.8 KiB
Go

package models
import (
"time"
)
// Credential 凭据管理模型(SSH密钥/API Token/密码等统一管理)
type Credential struct {
ID uint `gorm:"primarykey" json:"id"`
Name string `gorm:"size:128;not null" json:"name"` // 凭据名称
Type string `gorm:"size:32;not null" json:"type"` // ssh_key, api_token, password, access_key
Content string `gorm:"type:text;not null" json:"-"` // AES加密后的内容,API不返回
Description string `gorm:"size:500" json:"description"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
func (Credential) TableName() string {
return "iam_credentials"
}
// CredentialCreateRequest 创建凭据请求
type CredentialCreateRequest struct {
Name string `json:"name" binding:"required"`
Type string `json:"type" binding:"required,oneof=ssh_key api_token password access_key"`
Content string `json:"content" binding:"required"` // 明文,后端加密存储
Description string `json:"description"`
}
// CredentialUpdateRequest 更新凭据请求
type CredentialUpdateRequest struct {
Name string `json:"name" binding:"required"`
Type string `json:"type" binding:"required,oneof=ssh_key api_token password access_key"`
Content string `json:"content"` // 空则不更新内容
Description string `json:"description"`
}
// CredentialListResponse 列表返回(内容脱敏)
type CredentialListResponse struct {
ID uint `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Preview string `json:"preview"` // 内容预览(前8+后4字符)
Description string `json:"description"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}