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"` }