This commit is contained in:
mangomqy
2025-11-13 02:54:06 +00:00
commit c5e51ed069
254 changed files with 54901 additions and 0 deletions

View File

@ -0,0 +1,44 @@
package dto
// RepositoryListResponse Repository 列表响应
type RepositoryListResponse struct {
RegistryID string `json:"registryId"`
RegistryURL string `json:"registryUrl"`
Repositories []string `json:"repositories"`
Total int `json:"total"`
CatalogSupported bool `json:"catalogSupported"` // Whether _catalog API is supported
Source string `json:"source"` // Data source: "catalog" | "preconfigured" | "unavailable"
Message string `json:"message,omitempty"` // User-friendly message
}
// ArtifactResponse Artifact 响应(简化版本,只包含核心字段)
type ArtifactResponse struct {
RepositoryName string `json:"repositoryName"`
Tag string `json:"tag"`
Digest string `json:"digest"`
Type string `json:"type"` // chart | image | other
Size int64 `json:"size"`
CreatedAt string `json:"createdAt"`
}
// TagResponse Tag 响应(前端期望的扁平化结构)
type TagResponse struct {
RepositoryName string `json:"repositoryName"` // Repository name
Tag string `json:"tag"` // Tag name (e.g. "1.0.0", "latest")
Type string `json:"type"` // Artifact type: chart, image, other
MediaType string `json:"mediaType,omitempty"`
Size int64 `json:"size"` // Artifact size (bytes)
}
// ArtifactListResponse Artifact 列表响应(包装格式,用于详细接口)
type ArtifactListResponse struct {
RepositoryName string `json:"repositoryName"`
Artifacts []*ArtifactResponse `json:"artifacts"`
Total int `json:"total"`
}
// ValuesSchemaResponse Values Schema 响应
type ValuesSchemaResponse struct {
Schema string `json:"schema"`
}

View File

@ -0,0 +1,35 @@
package dto
// RegisterRequest 用户注册请求
type RegisterRequest struct {
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required,min=6"`
}
// LoginRequest 用户登录请求
type LoginRequest struct {
Username string `json:"username" binding:"required"`
Password string `json:"password" binding:"required"`
}
// RefreshTokenRequest 刷新 Token 请求
type RefreshTokenRequest struct {
RefreshToken string `json:"refreshToken" binding:"required"`
}
// AuthResponse 认证响应
type AuthResponse struct {
AccessToken string `json:"accessToken"`
RefreshToken string `json:"refreshToken"`
UserID string `json:"userId"`
Username string `json:"username"`
}
// UserResponse 用户信息响应
type UserResponse struct {
ID string `json:"id"`
Username string `json:"username"`
Email string `json:"email"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}

View File

@ -0,0 +1,82 @@
package dto
// CreateClusterRequest 创建集群请求
type CreateClusterRequest struct {
Name string `json:"name" binding:"required"`
Host string `json:"host" binding:"required"`
CAData string `json:"caData"`
CADataAlt string `json:"ca_data"`
CertData string `json:"certData"`
CertDataAlt string `json:"cert_data"`
KeyData string `json:"keyData"`
KeyDataAlt string `json:"key_data"`
Token string `json:"token"`
Description string `json:"description"`
}
// UpdateClusterRequest 更新集群请求
type UpdateClusterRequest struct {
Name string `json:"name"`
Host string `json:"host"`
CAData string `json:"caData"`
CADataAlt string `json:"ca_data"`
CertData string `json:"certData"`
CertDataAlt string `json:"cert_data"`
KeyData string `json:"keyData"`
KeyDataAlt string `json:"key_data"`
Token string `json:"token"`
Description string `json:"description"`
}
// Normalize 将多种命名风格的字段合并到统一字段
func (r *CreateClusterRequest) Normalize() {
if r.CAData == "" {
r.CAData = r.CADataAlt
}
if r.CertData == "" {
r.CertData = r.CertDataAlt
}
if r.KeyData == "" {
r.KeyData = r.KeyDataAlt
}
}
// Normalize 将多种命名风格的字段合并到统一字段
func (r *UpdateClusterRequest) Normalize() {
if r.CAData == "" {
r.CAData = r.CADataAlt
}
if r.CertData == "" {
r.CertData = r.CertDataAlt
}
if r.KeyData == "" {
r.KeyData = r.KeyDataAlt
}
}
// ClusterResponse 集群响应(敏感数据已脱敏)
type ClusterResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Host string `json:"host"`
Description string `json:"description"`
// 认证配置状态(不返回实际证书数据,仅返回是否已配置)
HasCAData bool `json:"hasCaData"`
HasCertData bool `json:"hasCertData"`
HasKeyData bool `json:"hasKeyData"`
HasToken bool `json:"hasToken"`
// 脱敏数据(仅用于前端显示,实际值为掩码)
CAData string `json:"caData,omitempty"` // 脱敏显示(••••••••)
CertData string `json:"certData,omitempty"` // 脱敏显示(••••••••)
KeyData string `json:"keyData,omitempty"` // 脱敏显示(••••••••)
Token string `json:"token,omitempty"` // 脱敏显示(••••••••)
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
// ClusterHealthResponse 集群健康状态响应
type ClusterHealthResponse struct {
Healthy bool `json:"healthy"`
Message string `json:"message,omitempty"`
Version string `json:"version,omitempty"`
}

View File

@ -0,0 +1,63 @@
package dto
import (
"github.com/ocdp/cluster-service/internal/domain/entity"
"github.com/ocdp/cluster-service/internal/pkg/crypto"
)
// ToRegistryResponse 转换 Registry 实体为响应 DTO脱敏
func ToRegistryResponse(registry *entity.Registry) *RegistryResponse {
response := &RegistryResponse{
ID: registry.ID,
Name: registry.Name,
URL: registry.URL,
Description: registry.Description,
Username: registry.Username,
Insecure: registry.Insecure,
CreatedAt: registry.CreatedAt.Format("2006-01-02T15:04:05Z07:00"),
UpdatedAt: registry.UpdatedAt.Format("2006-01-02T15:04:05Z07:00"),
}
// 脱敏处理密码
if registry.Password != "" {
response.HasPassword = true
response.Password = crypto.MaskSensitiveData(registry.Password)
}
return response
}
// ToClusterResponse 转换 Cluster 实体为响应 DTO脱敏
func ToClusterResponse(cluster *entity.Cluster) *ClusterResponse {
response := &ClusterResponse{
ID: cluster.ID,
Name: cluster.Name,
Host: cluster.Host,
Description: cluster.Description,
CreatedAt: cluster.CreatedAt.Format("2006-01-02T15:04:05Z07:00"),
UpdatedAt: cluster.UpdatedAt.Format("2006-01-02T15:04:05Z07:00"),
}
// 设置认证配置状态标志
response.HasCAData = cluster.CAData != ""
response.HasCertData = cluster.CertData != ""
response.HasKeyData = cluster.KeyData != ""
response.HasToken = cluster.Token != ""
// 脱敏处理敏感数据(仅显示掩码)
if cluster.CAData != "" {
response.CAData = crypto.MaskSensitiveData(cluster.CAData)
}
if cluster.CertData != "" {
response.CertData = crypto.MaskSensitiveData(cluster.CertData)
}
if cluster.KeyData != "" {
response.KeyData = crypto.MaskSensitiveData(cluster.KeyData)
}
if cluster.Token != "" {
response.Token = crypto.MaskSensitiveData(cluster.Token)
}
return response
}

View File

@ -0,0 +1,15 @@
package dto
// ErrorResponse 错误响应
type ErrorResponse struct {
Error string `json:"error"`
Message string `json:"message,omitempty"`
Code int `json:"code,omitempty"`
}
// SuccessResponse 成功响应
type SuccessResponse struct {
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}

View File

@ -0,0 +1,133 @@
package dto
// CreateInstanceRequest 创建实例请求
type CreateInstanceRequest struct {
Name string `json:"name" binding:"required"`
Namespace string `json:"namespace" binding:"required"`
RegistryID string `json:"registryId" binding:"required"`
RegistryIDAlt string `json:"registry_id"`
Repository string `json:"repository" binding:"required"`
Tag string `json:"tag" binding:"required"`
Description string `json:"description"`
Values map[string]interface{} `json:"values"`
ValuesYAML string `json:"valuesYaml"`
}
// UpdateInstanceRequest 更新实例请求
type UpdateInstanceRequest struct {
Version string `json:"version"`
Description string `json:"description"`
Values map[string]interface{} `json:"values"`
ValuesYAML string `json:"valuesYaml"`
}
// Normalize 将多种命名风格的字段合并到统一字段
func (r *CreateInstanceRequest) Normalize() {
if r.RegistryID == "" {
r.RegistryID = r.RegistryIDAlt
}
}
// RollbackInstanceRequest 回滚实例请求
type RollbackInstanceRequest struct {
Revision int `json:"revision" binding:"required"`
Wait bool `json:"wait"`
Timeout int `json:"timeout"` // seconds
}
// DeleteInstanceRequest 删除实例请求
type DeleteInstanceRequest struct {
KeepHistory bool `json:"keepHistory"`
Timeout int `json:"timeout"` // seconds
}
// InstanceResponse 实例响应
type InstanceResponse struct {
ID string `json:"id"`
ClusterID string `json:"clusterId"`
Name string `json:"name"`
Namespace string `json:"namespace"`
RegistryID string `json:"registryId"`
Repository string `json:"repository"`
Chart string `json:"chart"`
Version string `json:"version"`
Description string `json:"description"`
Status string `json:"status"`
StatusReason string `json:"statusReason,omitempty"`
LastOperation string `json:"lastOperation,omitempty"`
LastError string `json:"lastError,omitempty"`
Revision int `json:"revision"`
Values map[string]interface{} `json:"values,omitempty"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
// InstanceStatusResponse 实例状态响应
type InstanceStatusResponse struct {
ID string `json:"id"`
Name string `json:"name"`
Namespace string `json:"namespace"`
Status string `json:"status"`
Revision int `json:"revision"`
Chart string `json:"chart"`
Version string `json:"version"`
UpdatedAt string `json:"updatedAt"`
}
// ReleaseHistoryResponse Release 历史响应
type ReleaseHistoryResponse struct {
Revision int `json:"revision"`
Updated string `json:"updated"`
Status string `json:"status"`
Chart string `json:"chart"`
AppVersion string `json:"appVersion"`
Description string `json:"description"`
}
// InstanceListResponse 实例列表响应
type InstanceListResponse struct {
Instances []*InstanceResponse `json:"instances"`
Total int `json:"total"`
}
// InstanceEntryPortResponse Service 端口响应
type InstanceEntryPortResponse struct {
Name string `json:"name,omitempty"`
Protocol string `json:"protocol"`
Port int32 `json:"port"`
TargetPort string `json:"targetPort,omitempty"`
NodePort int32 `json:"nodePort,omitempty"`
}
// InstanceEntryPathResponse Ingress path 响应
type InstanceEntryPathResponse struct {
Path string `json:"path"`
ServiceName string `json:"serviceName,omitempty"`
ServicePort string `json:"servicePort,omitempty"`
}
// InstanceEntryHostResponse Ingress host 响应
type InstanceEntryHostResponse struct {
Host string `json:"host"`
Paths []InstanceEntryPathResponse `json:"paths,omitempty"`
}
// InstanceEntryTLSResponse Ingress TLS 响应
type InstanceEntryTLSResponse struct {
Hosts []string `json:"hosts,omitempty"`
SecretName string `json:"secretName,omitempty"`
}
// InstanceEntryResponse 实例入口响应
type InstanceEntryResponse struct {
Kind string `json:"kind"`
Name string `json:"name"`
Namespace string `json:"namespace"`
Type string `json:"type,omitempty"`
ClusterIP string `json:"clusterIP,omitempty"`
ExternalIPs []string `json:"externalIPs,omitempty"`
LoadBalancerIngress []string `json:"loadBalancerIngress,omitempty"`
Ports []InstanceEntryPortResponse `json:"ports,omitempty"`
Hosts []InstanceEntryHostResponse `json:"hosts,omitempty"`
TLS []InstanceEntryTLSResponse `json:"tls,omitempty"`
}

View File

@ -0,0 +1,143 @@
package dto
import (
"time"
"github.com/ocdp/cluster-service/internal/domain/entity"
)
// ClusterMetricsResponse 集群监控响应
type ClusterMetricsResponse struct {
ClusterID string `json:"clusterId"`
ClusterName string `json:"clusterName"`
Status string `json:"status"`
Uptime string `json:"uptime"`
NodeCount int `json:"nodeCount"`
PodCount int `json:"podCount"`
LastCheck time.Time `json:"lastCheck"`
TotalCPU string `json:"totalCpu"`
TotalMemory string `json:"totalMemory"`
TotalGPU int `json:"totalGpu"`
UsedCPU string `json:"usedCpu"`
UsedMemory string `json:"usedMemory"`
UsedGPU int `json:"usedGpu"`
CPUUsage float64 `json:"cpuUsage"`
MemoryUsage float64 `json:"memoryUsage"`
GPUUsage float64 `json:"gpuUsage"`
MaxNodeCPU string `json:"maxNodeCpu"`
MaxNodeMemory string `json:"maxNodeMemory"`
MaxNodeGPU int `json:"maxNodeGpu"`
MaxNodeCPUUsage float64 `json:"maxNodeCpuUsage"`
MaxNodeMemUsage float64 `json:"maxNodeMemUsage"`
MaxNodeGPUUsage float64 `json:"maxNodeGpuUsage"`
Nodes []NodeMetricsResponse `json:"nodes,omitempty"`
}
// NodeMetricsResponse 节点监控响应
type NodeMetricsResponse struct {
NodeName string `json:"nodeName"`
Status string `json:"status"`
Role string `json:"role"`
Age string `json:"age"`
PodCount int `json:"podCount"`
CPUCapacity string `json:"cpuCapacity"`
CPUAllocatable string `json:"cpuAllocatable"`
CPUUsage string `json:"cpuUsage"`
CPUPercent float64 `json:"cpuPercent"`
MemoryCapacity string `json:"memoryCapacity"`
MemoryAllocatable string `json:"memoryAllocatable"`
MemoryUsage string `json:"memoryUsage"`
MemoryPercent float64 `json:"memoryPercent"`
GPUCapacity int `json:"gpuCapacity"`
GPUUsage int `json:"gpuUsage"`
GPUPercent float64 `json:"gpuPercent"`
GPUType string `json:"gpuType,omitempty"`
OSImage string `json:"osImage,omitempty"`
KernelVersion string `json:"kernelVersion,omitempty"`
ContainerRuntime string `json:"containerRuntime,omitempty"`
KubeletVersion string `json:"kubeletVersion,omitempty"`
}
// MonitoringSummaryResponse 监控汇总响应
type MonitoringSummaryResponse struct {
TotalClusters int `json:"totalClusters"`
HealthyClusters int `json:"healthyClusters"`
WarningClusters int `json:"warningClusters"`
ErrorClusters int `json:"errorClusters"`
TotalNodes int `json:"totalNodes"`
TotalPods int `json:"totalPods"`
LastUpdate time.Time `json:"lastUpdate"`
}
// ToClusterMetricsResponse 转换为响应
func ToClusterMetricsResponse(m *entity.ClusterMetrics) *ClusterMetricsResponse {
resp := &ClusterMetricsResponse{
ClusterID: m.ClusterID,
ClusterName: m.ClusterName,
Status: m.Status,
Uptime: m.Uptime,
NodeCount: m.NodeCount,
PodCount: m.PodCount,
LastCheck: m.LastCheck,
TotalCPU: m.TotalCPU,
TotalMemory: m.TotalMemory,
TotalGPU: m.TotalGPU,
UsedCPU: m.UsedCPU,
UsedMemory: m.UsedMemory,
UsedGPU: m.UsedGPU,
CPUUsage: m.CPUUsage,
MemoryUsage: m.MemoryUsage,
GPUUsage: m.GPUUsage,
MaxNodeCPU: m.MaxNodeCPU,
MaxNodeMemory: m.MaxNodeMemory,
MaxNodeGPU: m.MaxNodeGPU,
MaxNodeCPUUsage: m.MaxNodeCPUUsage,
MaxNodeMemUsage: m.MaxNodeMemUsage,
MaxNodeGPUUsage: m.MaxNodeGPUUsage,
}
if len(m.Nodes) > 0 {
resp.Nodes = make([]NodeMetricsResponse, len(m.Nodes))
for i, node := range m.Nodes {
resp.Nodes[i] = NodeMetricsResponse{
NodeName: node.NodeName,
Status: node.Status,
Role: node.Role,
Age: node.Age,
PodCount: node.PodCount,
CPUCapacity: node.CPUCapacity,
CPUAllocatable: node.CPUAllocatable,
CPUUsage: node.CPUUsage,
CPUPercent: node.CPUPercent,
MemoryCapacity: node.MemoryCapacity,
MemoryAllocatable: node.MemoryAllocatable,
MemoryUsage: node.MemoryUsage,
MemoryPercent: node.MemoryPercent,
GPUCapacity: node.GPUCapacity,
GPUUsage: node.GPUUsage,
GPUPercent: node.GPUPercent,
GPUType: node.GPUType,
OSImage: node.OSImage,
KernelVersion: node.KernelVersion,
ContainerRuntime: node.ContainerRuntime,
KubeletVersion: node.KubeletVersion,
}
}
}
return resp
}
// ToMonitoringSummaryResponse 转换为汇总响应
func ToMonitoringSummaryResponse(s *entity.MonitoringSummary) *MonitoringSummaryResponse {
return &MonitoringSummaryResponse{
TotalClusters: s.TotalClusters,
HealthyClusters: s.HealthyClusters,
WarningClusters: s.WarningClusters,
ErrorClusters: s.ErrorClusters,
TotalNodes: s.TotalNodes,
TotalPods: s.TotalPods,
LastUpdate: s.LastUpdate,
}
}

View File

@ -0,0 +1,42 @@
package dto
// CreateRegistryRequest 创建 Registry 请求
type CreateRegistryRequest struct {
Name string `json:"name" binding:"required"`
URL string `json:"url" binding:"required"`
Username string `json:"username"`
Password string `json:"password"`
Description string `json:"description"`
Insecure bool `json:"insecure"`
}
// UpdateRegistryRequest 更新 Registry 请求
type UpdateRegistryRequest struct {
Name string `json:"name"`
URL string `json:"url"`
Username string `json:"username"`
Password string `json:"password"`
Description string `json:"description"`
Insecure bool `json:"insecure"`
}
// RegistryResponse Registry 响应(敏感数据已脱敏)
type RegistryResponse struct {
ID string `json:"id"`
Name string `json:"name"`
URL string `json:"url"`
Description string `json:"description"`
Username string `json:"username,omitempty"` // 明文返回用户名(不敏感)
Password string `json:"password,omitempty"` // 脱敏显示(••••••••)
HasPassword bool `json:"hasPassword"` // 是否已设置密码
Insecure bool `json:"insecure"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
// RegistryHealthResponse Registry 健康状态响应
type RegistryHealthResponse struct {
Healthy bool `json:"healthy"`
Message string `json:"message,omitempty"`
}