mirror of
https://github.com/orris-inc/orris.git
synced 2026-05-06 21:44:01 +08:00
- Change ForwardAgent.GroupID (single) to GroupIDs (array) to support multi-group membership - Add migration script 047 to convert group_id column to group_ids array - Update repository layer with array-based queries using ANY operator - Update ResourceGroupRepository to handle array-based forward agent group associations - Update all related use cases and DTOs to work with group arrays - Fix payment repository to use explicit column selection - Update handlers and tests to reflect new multi-group structure
48 lines
2.3 KiB
Go
48 lines
2.3 KiB
Go
package models
|
|
|
|
import (
|
|
"time"
|
|
|
|
"gorm.io/datatypes"
|
|
"gorm.io/gorm"
|
|
|
|
"github.com/orris-inc/orris/internal/shared/constants"
|
|
)
|
|
|
|
// ForwardAgentModel represents the database persistence model for forward agents.
|
|
type ForwardAgentModel struct {
|
|
ID uint `gorm:"primarykey"`
|
|
SID string `gorm:"column:sid;not null;size:20;uniqueIndex:idx_forward_agent_sid"` // Stripe-style prefixed ID (fa_xxx)
|
|
Name string `gorm:"not null;size:100;index:idx_forward_agent_name"`
|
|
TokenHash string `gorm:"not null;size:64;index:idx_forward_agent_token_hash"`
|
|
APIToken string `gorm:"column:api_token;size:255"` // stored token for retrieval
|
|
PublicAddress string `gorm:"size:255"` // public address for agent access (nullable)
|
|
TunnelAddress string `gorm:"size:255"` // tunnel address for entry to connect to exit (nullable, overrides public_address)
|
|
Status string `gorm:"not null;default:enabled;size:20;index:idx_forward_agent_status"`
|
|
Remark string `gorm:"size:500"`
|
|
GroupIDs datatypes.JSON `gorm:"column:group_ids"` // resource group IDs (JSON array)
|
|
AgentVersion string `gorm:"size:50"` // agent software version (e.g., "1.2.3")
|
|
Platform string `gorm:"size:20"` // OS platform (linux, darwin, windows)
|
|
Arch string `gorm:"size:20"` // CPU architecture (amd64, arm64, arm, 386)
|
|
AllowedPortRange *string `gorm:"column:allowed_port_range;type:text"`
|
|
BlockedProtocols datatypes.JSON `gorm:"column:blocked_protocols;type:json"` // protocols blocked by this agent
|
|
SortOrder int `gorm:"not null;default:0"`
|
|
MuteNotification bool `gorm:"not null;default:false"` // mute online/offline notifications
|
|
LastSeenAt *time.Time
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
}
|
|
|
|
// TableName specifies the table name for GORM.
|
|
func (ForwardAgentModel) TableName() string {
|
|
return constants.TableForwardAgents
|
|
}
|
|
|
|
// BeforeCreate hook for GORM.
|
|
func (m *ForwardAgentModel) BeforeCreate(tx *gorm.DB) error {
|
|
if m.Status == "" {
|
|
m.Status = "enabled"
|
|
}
|
|
return nil
|
|
}
|