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.
71 lines
2.7 KiB
Go
71 lines
2.7 KiB
Go
package service
|
||
|
||
import (
|
||
"context"
|
||
"time"
|
||
|
||
"github.com/google/uuid"
|
||
"github.com/ocdp/cluster-service/internal/domain/entity"
|
||
"github.com/ocdp/cluster-service/internal/domain/repository"
|
||
)
|
||
|
||
// AuditService 审计日志领域服务
|
||
type AuditService struct {
|
||
auditLogRepo repository.AuditLogRepository
|
||
}
|
||
|
||
// NewAuditService 创建审计服务
|
||
func NewAuditService(auditLogRepo repository.AuditLogRepository) *AuditService {
|
||
return &AuditService{
|
||
auditLogRepo: auditLogRepo,
|
||
}
|
||
}
|
||
|
||
// Log 创建审计日志
|
||
func (s *AuditService) Log(ctx context.Context, workspaceID, userID string, action entity.AuditAction, resourceType entity.AuditResourceType, resourceID, resourceName string, details map[string]interface{}, ipAddress, userAgent string) error {
|
||
auditLog := &entity.AuditLog{
|
||
ID: uuid.New().String(),
|
||
WorkspaceID: workspaceID,
|
||
UserID: userID,
|
||
Action: action,
|
||
ResourceType: resourceType,
|
||
ResourceID: resourceID,
|
||
ResourceName: resourceName,
|
||
Details: details,
|
||
IPAddress: ipAddress,
|
||
UserAgent: userAgent,
|
||
CreatedAt: time.Now(),
|
||
}
|
||
|
||
return s.auditLogRepo.Create(ctx, auditLog)
|
||
}
|
||
|
||
// LogAction 简化版日志记录
|
||
func (s *AuditService) LogAction(ctx context.Context, workspaceID, userID string, action entity.AuditAction, resourceType entity.AuditResourceType, resourceName string) error {
|
||
return s.Log(ctx, workspaceID, userID, action, resourceType, "", resourceName, nil, "", "")
|
||
}
|
||
|
||
// LogWithDetails 带详情的日志记录
|
||
func (s *AuditService) LogWithDetails(ctx context.Context, workspaceID, userID string, action entity.AuditAction, resourceType entity.AuditResourceType, resourceID, resourceName string, details map[string]interface{}) error {
|
||
return s.Log(ctx, workspaceID, userID, action, resourceType, resourceID, resourceName, details, "", "")
|
||
}
|
||
|
||
// GetLogs 获取审计日志
|
||
func (s *AuditService) GetLogs(ctx context.Context, workspaceID string, limit int) ([]*entity.AuditLog, error) {
|
||
return s.auditLogRepo.GetByWorkspace(ctx, workspaceID, limit)
|
||
}
|
||
|
||
// GetUserLogs 获取用户的审计日志
|
||
func (s *AuditService) GetUserLogs(ctx context.Context, userID string, limit int) ([]*entity.AuditLog, error) {
|
||
return s.auditLogRepo.GetByUser(ctx, userID, limit)
|
||
}
|
||
|
||
// GetResourceLogs 获取资源的审计日志
|
||
func (s *AuditService) GetResourceLogs(ctx context.Context, resourceType entity.AuditResourceType, resourceID string, limit int) ([]*entity.AuditLog, error) {
|
||
return s.auditLogRepo.GetByResource(ctx, resourceType, resourceID, limit)
|
||
}
|
||
|
||
// GetAllLogs 获取所有审计日志(Admin)
|
||
func (s *AuditService) GetAllLogs(ctx context.Context, limit int, offset int) ([]*entity.AuditLog, error) {
|
||
return s.auditLogRepo.List(ctx, limit, offset)
|
||
} |