Add new frontend pages for the multi-tenant OCDP platform: - Charts page (/charts): Browse Harbor OCI registries to list Helm chart repositories and versions, with deploy modal to launch charts on selected clusters - Monitoring page (/monitoring): Display cluster metrics (CPU/Memory/GPU usage) and per-node details with resource utilization bars - Chart References page (/chart-references): CRUD for chart metadata references - Values Templates page (/templates): CRUD for Helm values templates with version history and rollback support - Sidebar: Add Charts navigation, update Storage and Templates links - api.ts: Add all API client functions (clusterApi, registryApi, instanceApi, monitoringApi, storageApi, chartReferenceApi, valuesTemplateApi, workspaceApi, userApi) with full TypeScript types Note: deploy flow and values template rollback not yet end-to-end tested.
90 lines
2.3 KiB
Go
90 lines
2.3 KiB
Go
package entity
|
|
|
|
import (
|
|
"encoding/json"
|
|
"time"
|
|
)
|
|
|
|
// AuditAction 审计操作类型
|
|
type AuditAction string
|
|
|
|
const (
|
|
AuditActionCreate AuditAction = "create"
|
|
AuditActionUpdate AuditAction = "update"
|
|
AuditActionDelete AuditAction = "delete"
|
|
AuditActionDeploy AuditAction = "deploy"
|
|
AuditActionScale AuditAction = "scale"
|
|
AuditActionLogin AuditAction = "login"
|
|
AuditActionLogout AuditAction = "logout"
|
|
AuditActionChangePassword AuditAction = "change_password"
|
|
)
|
|
|
|
// AuditResourceType 审计资源类型
|
|
type AuditResourceType string
|
|
|
|
const (
|
|
AuditResourceUser AuditResourceType = "user"
|
|
AuditResourceWorkspace AuditResourceType = "workspace"
|
|
AuditResourceQuota AuditResourceType = "quota"
|
|
AuditResourceCluster AuditResourceType = "cluster"
|
|
AuditResourceRegistry AuditResourceType = "registry"
|
|
AuditResourceInstance AuditResourceType = "instance"
|
|
AuditResourceStorage AuditResourceType = "storage"
|
|
AuditResourceTemplate AuditResourceType = "template"
|
|
)
|
|
|
|
// AuditLog 审计日志实体
|
|
type AuditLog struct {
|
|
ID string
|
|
WorkspaceID string
|
|
UserID string
|
|
Action AuditAction
|
|
ResourceType AuditResourceType
|
|
ResourceID string
|
|
ResourceName string
|
|
Details map[string]interface{}
|
|
IPAddress string
|
|
UserAgent string
|
|
CreatedAt time.Time
|
|
}
|
|
|
|
// NewAuditLog 创建新审计日志
|
|
func NewAuditLog(workspaceID, userID string, action AuditAction, resourceType AuditResourceType) *AuditLog {
|
|
now := time.Now()
|
|
return &AuditLog{
|
|
WorkspaceID: workspaceID,
|
|
UserID: userID,
|
|
Action: action,
|
|
ResourceType: resourceType,
|
|
CreatedAt: now,
|
|
}
|
|
}
|
|
|
|
// SetResource 设置关联资源
|
|
func (a *AuditLog) SetResource(resourceID, resourceName string) {
|
|
a.ResourceID = resourceID
|
|
a.ResourceName = resourceName
|
|
}
|
|
|
|
// SetDetails 设置详细信息
|
|
func (a *AuditLog) SetDetails(details map[string]interface{}) {
|
|
a.Details = details
|
|
}
|
|
|
|
// SetClientInfo 设置客户端信息
|
|
func (a *AuditLog) SetClientInfo(ipAddress, userAgent string) {
|
|
a.IPAddress = ipAddress
|
|
a.UserAgent = userAgent
|
|
}
|
|
|
|
// DetailsJSON 将详情转为 JSON 字符串
|
|
func (a *AuditLog) DetailsJSON() (string, error) {
|
|
if a.Details == nil {
|
|
return "{}", nil
|
|
}
|
|
data, err := json.Marshal(a.Details)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(data), nil
|
|
} |