refactor: consolidate AgentFile struct into common package
Created aggregator/pkg/common module with shared AgentFile type. Removed duplicate definitions from migration and services packages. Both agent and server now use common.AgentFile.
This commit is contained in:
@@ -12,6 +12,7 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/Fimeg/RedFlag/aggregator v0.0.0
|
||||
github.com/bytedance/sonic v1.14.0 // indirect
|
||||
github.com/bytedance/sonic/loader v0.3.0 // indirect
|
||||
github.com/cloudwego/base64x v0.1.6 // indirect
|
||||
@@ -43,3 +44,5 @@ require (
|
||||
golang.org/x/tools v0.34.0 // indirect
|
||||
google.golang.org/protobuf v1.36.9 // indirect
|
||||
)
|
||||
|
||||
replace github.com/Fimeg/RedFlag/aggregator => ../aggregator
|
||||
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Fimeg/RedFlag/aggregator/pkg/common"
|
||||
)
|
||||
|
||||
// NewBuildRequest represents a request for a new agent build
|
||||
@@ -57,25 +59,13 @@ type InstallationDetection struct {
|
||||
|
||||
// AgentFileInventory represents all files associated with an agent installation
|
||||
type AgentFileInventory struct {
|
||||
ConfigFiles []AgentFile `json:"config_files"`
|
||||
StateFiles []AgentFile `json:"state_files"`
|
||||
BinaryFiles []AgentFile `json:"binary_files"`
|
||||
LogFiles []AgentFile `json:"log_files"`
|
||||
CertificateFiles []AgentFile `json:"certificate_files"`
|
||||
ExistingPaths []string `json:"existing_paths"`
|
||||
MissingPaths []string `json:"missing_paths"`
|
||||
}
|
||||
|
||||
// AgentFile represents a file associated with the agent
|
||||
type AgentFile struct {
|
||||
Path string `json:"path"`
|
||||
Size int64 `json:"size"`
|
||||
ModifiedTime string `json:"modified_time"`
|
||||
Version string `json:"version,omitempty"`
|
||||
Checksum string `json:"checksum"`
|
||||
Required bool `json:"required"`
|
||||
Migrate bool `json:"migrate"`
|
||||
Description string `json:"description"`
|
||||
ConfigFiles []common.AgentFile `json:"config_files"`
|
||||
StateFiles []common.AgentFile `json:"state_files"`
|
||||
BinaryFiles []common.AgentFile `json:"binary_files"`
|
||||
LogFiles []common.AgentFile `json:"log_files"`
|
||||
CertificateFiles []common.AgentFile `json:"certificate_files"`
|
||||
ExistingPaths []string `json:"existing_paths"`
|
||||
MissingPaths []string `json:"missing_paths"`
|
||||
}
|
||||
|
||||
// MigrationDetection represents migration detection results (from existing migration system)
|
||||
@@ -115,8 +105,8 @@ func (id *InstallationDetector) DetectExistingInstallation(agentID string) (*Ins
|
||||
}
|
||||
|
||||
// scanDirectory scans a directory for agent-related files
|
||||
func (id *InstallationDetector) scanDirectory(dirPath string) ([]AgentFile, error) {
|
||||
var files []AgentFile
|
||||
func (id *InstallationDetector) scanDirectory(dirPath string) ([]common.AgentFile, error) {
|
||||
var files []common.AgentFile
|
||||
|
||||
entries, err := os.ReadDir(dirPath)
|
||||
if err != nil {
|
||||
@@ -143,10 +133,10 @@ func (id *InstallationDetector) scanDirectory(dirPath string) ([]AgentFile, erro
|
||||
checksum = ""
|
||||
}
|
||||
|
||||
file := AgentFile{
|
||||
file := common.AgentFile{
|
||||
Path: fullPath,
|
||||
Size: info.Size(),
|
||||
ModifiedTime: info.ModTime().Format(time.RFC3339),
|
||||
ModifiedTime: info.ModTime(),
|
||||
Checksum: checksum,
|
||||
Required: id.isRequiredFile(entry.Name()),
|
||||
Migrate: id.shouldMigrateFile(entry.Name()),
|
||||
@@ -160,7 +150,7 @@ func (id *InstallationDetector) scanDirectory(dirPath string) ([]AgentFile, erro
|
||||
}
|
||||
|
||||
// categorizeFile categorizes a file into the appropriate inventory section
|
||||
func (id *InstallationDetector) categorizeFile(file AgentFile, inventory *AgentFileInventory) {
|
||||
func (id *InstallationDetector) categorizeFile(file common.AgentFile, inventory *AgentFileInventory) {
|
||||
filename := filepath.Base(file.Path)
|
||||
|
||||
switch {
|
||||
|
||||
Reference in New Issue
Block a user