114 lines
3.0 KiB
Go
114 lines
3.0 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
type User struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Email string `json:"email"`
|
|
PasswordHash string `json:"-"`
|
|
Name string `json:"name"`
|
|
Role string `json:"role"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
}
|
|
|
|
type Protocol struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Code string `json:"code"`
|
|
Name string `json:"name"`
|
|
Description string `json:"description"`
|
|
Port int `json:"port"`
|
|
Enabled bool `json:"enabled"`
|
|
SortOrder int `json:"sort_order"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
|
|
InstalledOn []NodeProtoRef `json:"installed_on,omitempty"`
|
|
EnabledOn []NodeProtoRef `json:"enabled_on,omitempty"`
|
|
}
|
|
|
|
type NodeProtoRef struct {
|
|
NodeID uuid.UUID `json:"node_id"`
|
|
NodeName string `json:"node_name"`
|
|
Host string `json:"host"`
|
|
Status NodeStatus `json:"status"`
|
|
}
|
|
|
|
type NodeProtocol struct {
|
|
NodeID uuid.UUID `json:"node_id"`
|
|
ProtocolID uuid.UUID `json:"protocol_id"`
|
|
ProtocolCode string `json:"protocol_code"`
|
|
ProtocolName string `json:"protocol_name"`
|
|
Port int `json:"port"`
|
|
Installed bool `json:"installed"`
|
|
Enabled bool `json:"enabled"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func (p Protocol) EnabledLabel() string {
|
|
if p.Enabled {
|
|
return "Включён"
|
|
}
|
|
return "Выключен"
|
|
}
|
|
|
|
func (p Protocol) InstallCount() int { return len(p.InstalledOn) }
|
|
func (p Protocol) ActiveCount() int { return len(p.EnabledOn) }
|
|
|
|
|
|
type NodeStatus string
|
|
|
|
const (
|
|
NodeStatusPending NodeStatus = "pending"
|
|
NodeStatusInstalling NodeStatus = "installing"
|
|
NodeStatusOnline NodeStatus = "online"
|
|
NodeStatusOffline NodeStatus = "offline"
|
|
NodeStatusError NodeStatus = "error"
|
|
)
|
|
|
|
type Node struct {
|
|
ID uuid.UUID `json:"id"`
|
|
Name string `json:"name"`
|
|
Host string `json:"host"`
|
|
SSHPort int `json:"ssh_port"`
|
|
SSHUser string `json:"ssh_user"`
|
|
SSHAuthType string `json:"ssh_auth_type"` // password | key
|
|
SSHSecretEnc string `json:"-"`
|
|
NodePort int `json:"node_port"`
|
|
SecretKey string `json:"-"`
|
|
Status NodeStatus `json:"status"`
|
|
InstallMode string `json:"install_mode"` // auto | manual
|
|
LastError string `json:"last_error"`
|
|
InstallLog string `json:"install_log"`
|
|
AgentVersion string `json:"agent_version"`
|
|
LastSeenAt *time.Time `json:"last_seen_at,omitempty"`
|
|
CreatedAt time.Time `json:"created_at"`
|
|
UpdatedAt time.Time `json:"updated_at"`
|
|
}
|
|
|
|
func (n Node) StatusLabel() string {
|
|
switch n.Status {
|
|
case NodeStatusOnline:
|
|
return "Online"
|
|
case NodeStatusInstalling:
|
|
return "Установка"
|
|
case NodeStatusOffline:
|
|
return "Offline"
|
|
case NodeStatusError:
|
|
return "Ошибка"
|
|
default:
|
|
return "Ожидание"
|
|
}
|
|
}
|
|
|
|
type DashboardStats struct {
|
|
ProtocolsTotal int
|
|
ProtocolsEnabled int
|
|
AdminsTotal int
|
|
NodesTotal int
|
|
NodesOnline int
|
|
}
|