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:
Fimeg
2025-11-10 22:03:43 -05:00
parent ddaa9ac637
commit 4531ca34c5
9 changed files with 98 additions and 59 deletions

View File

@@ -9,29 +9,19 @@ import (
"path/filepath"
"strings"
"time"
)
// AgentFile represents a file associated with the agent
type AgentFile struct {
Path string `json:"path"`
Size int64 `json:"size"`
ModifiedTime time.Time `json:"modified_time"`
Version string `json:"version,omitempty"`
Checksum string `json:"checksum"`
Required bool `json:"required"`
Migrate bool `json:"migrate"`
Description string `json:"description"`
}
"github.com/Fimeg/RedFlag/aggregator/pkg/common"
)
// 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"`
OldDirectoryPaths []string `json:"old_directory_paths"`
NewDirectoryPaths []string `json:"new_directory_paths"`
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"`
OldDirectoryPaths []string `json:"old_directory_paths"`
NewDirectoryPaths []string `json:"new_directory_paths"`
}
// MigrationDetection represents the result of migration detection
@@ -184,8 +174,8 @@ func scanAgentFiles(config *FileDetectionConfig) (*AgentFileInventory, error) {
}
// scanDirectory scans a directory for files matching specific patterns
func scanDirectory(dirPath string, patterns map[string][]string) ([]AgentFile, error) {
var files []AgentFile
func scanDirectory(dirPath string, patterns map[string][]string) ([]common.AgentFile, error) {
var files []common.AgentFile
err := filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error {
if err != nil {
@@ -203,7 +193,7 @@ func scanDirectory(dirPath string, patterns map[string][]string) ([]AgentFile, e
return nil
}
file := AgentFile{
file := common.AgentFile{
Path: path,
Size: info.Size(),
ModifiedTime: info.ModTime(),