SOGOMS v1.0.7 - 2FA obligatoire et Infrastructure Management
Phase 17g - Double Authentification: - TOTP avec Google Authenticator/Authy - QR code pour enrôlement - Codes de backup (10 codes usage unique) - Page /admin/security pour gestion 2FA - Page /admin/users avec Reset 2FA (super_admin) - 2FA obligatoire pour rôles configurés Phase 21 - Infrastructure Management: - SQLite pour données infra (/data/infra.db) - SSH Pool avec reconnexion auto - Gestion Incus (list, start, stop, restart, sync) - Gestion Nginx (test, reload, deploy, sync, certbot) - Interface admin /admin/infra - Formulaire ajout serveur - Page détail serveur avec containers et sites Fichiers créés: - internal/infra/ (db, models, migrations, repository, ssh, incus, nginx) - cmd/sogoms/admin/totp.go - cmd/sogoms/admin/handlers_2fa.go - cmd/sogoms/admin/handlers_infra.go - Templates: 2fa_*, security, users, infra, server_* 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
129
internal/infra/models.go
Normal file
129
internal/infra/models.go
Normal file
@@ -0,0 +1,129 @@
|
||||
// Package infra gère l'infrastructure (serveurs, containers, nginx).
|
||||
package infra
|
||||
|
||||
import "time"
|
||||
|
||||
// ServerStatus représente l'état d'un serveur.
|
||||
type ServerStatus string
|
||||
|
||||
const (
|
||||
ServerStatusOnline ServerStatus = "online"
|
||||
ServerStatusOffline ServerStatus = "offline"
|
||||
ServerStatusUnknown ServerStatus = "unknown"
|
||||
)
|
||||
|
||||
// ContainerStatus représente l'état d'un container.
|
||||
type ContainerStatus string
|
||||
|
||||
const (
|
||||
ContainerStatusRunning ContainerStatus = "running"
|
||||
ContainerStatusStopped ContainerStatus = "stopped"
|
||||
ContainerStatusUnknown ContainerStatus = "unknown"
|
||||
)
|
||||
|
||||
// NginxConfigStatus représente l'état d'une config Nginx.
|
||||
type NginxConfigStatus string
|
||||
|
||||
const (
|
||||
NginxConfigStatusActive NginxConfigStatus = "active"
|
||||
NginxConfigStatusInactive NginxConfigStatus = "inactive"
|
||||
NginxConfigStatusError NginxConfigStatus = "error"
|
||||
)
|
||||
|
||||
// NginxConfigType représente le type de config Nginx.
|
||||
type NginxConfigType string
|
||||
|
||||
const (
|
||||
NginxTypeProxy NginxConfigType = "proxy"
|
||||
NginxTypeStatic NginxConfigType = "static"
|
||||
NginxTypeSocket NginxConfigType = "socket"
|
||||
)
|
||||
|
||||
// BindingType représente le type de binding app.
|
||||
type BindingType string
|
||||
|
||||
const (
|
||||
BindingTypeContainer BindingType = "container"
|
||||
BindingTypeNginx BindingType = "nginx"
|
||||
BindingTypeServer BindingType = "server"
|
||||
)
|
||||
|
||||
// Server représente un serveur physique ou VM.
|
||||
type Server struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Host string `json:"host"`
|
||||
VpnIP string `json:"vpn_ip,omitempty"`
|
||||
SSHPort int `json:"ssh_port"`
|
||||
SSHUser string `json:"ssh_user"`
|
||||
SSHKeyFile string `json:"ssh_key_file"`
|
||||
HasIncus bool `json:"has_incus"`
|
||||
HasNginx bool `json:"has_nginx"`
|
||||
Status ServerStatus `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// Container représente un container Incus.
|
||||
type Container struct {
|
||||
ID int64 `json:"id"`
|
||||
ServerID int64 `json:"server_id"`
|
||||
Name string `json:"name"`
|
||||
IncusName string `json:"incus_name"`
|
||||
IP string `json:"ip"`
|
||||
VpnIP string `json:"vpn_ip,omitempty"`
|
||||
Image string `json:"image"`
|
||||
Status ContainerStatus `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// Relation (populé par query)
|
||||
Server *Server `json:"server,omitempty"`
|
||||
}
|
||||
|
||||
// NginxConfig représente une configuration Nginx.
|
||||
type NginxConfig struct {
|
||||
ID int64 `json:"id"`
|
||||
ServerID int64 `json:"server_id"`
|
||||
Domain string `json:"domain"`
|
||||
Type NginxConfigType `json:"type"`
|
||||
Template string `json:"template,omitempty"`
|
||||
Upstream string `json:"upstream,omitempty"`
|
||||
SSLEnabled bool `json:"ssl_enabled"`
|
||||
ConfigContent string `json:"config_content,omitempty"`
|
||||
Status NginxConfigStatus `json:"status"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
|
||||
// Relation (populé par query)
|
||||
Server *Server `json:"server,omitempty"`
|
||||
}
|
||||
|
||||
// AppBinding représente le lien entre une app SOGOMS et l'infrastructure.
|
||||
type AppBinding struct {
|
||||
ID int64 `json:"id"`
|
||||
AppID string `json:"app_id"`
|
||||
ContainerID *int64 `json:"container_id,omitempty"`
|
||||
NginxConfigID *int64 `json:"nginx_config_id,omitempty"`
|
||||
ServerID *int64 `json:"server_id,omitempty"`
|
||||
Type BindingType `json:"type"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
|
||||
// Relations (populées par query)
|
||||
Container *Container `json:"container,omitempty"`
|
||||
NginxConfig *NginxConfig `json:"nginx_config,omitempty"`
|
||||
Server *Server `json:"server,omitempty"`
|
||||
}
|
||||
|
||||
// ServerWithContainers représente un serveur avec ses containers.
|
||||
type ServerWithContainers struct {
|
||||
Server
|
||||
Containers []Container `json:"containers"`
|
||||
}
|
||||
|
||||
// InfraOverview représente une vue globale de l'infrastructure.
|
||||
type InfraOverview struct {
|
||||
Servers []ServerWithContainers `json:"servers"`
|
||||
NginxConfigs []NginxConfig `json:"nginx_configs"`
|
||||
AppBindings []AppBinding `json:"app_bindings"`
|
||||
}
|
||||
Reference in New Issue
Block a user