refactor: replace 899 lines of script generation with templates
Created InstallTemplateService with clean template-based script generation. Added linux.sh.tmpl and windows.ps1.tmpl for install scripts. Removed massive generateLinuxScript and generateWindowsScript functions. Downloads handler now uses template service (1073 lines → 174 lines). Templates easily maintainable without modifying Go code.
This commit is contained in:
@@ -636,14 +636,17 @@ func runAgent(cfg *config.Config) error {
|
||||
|
||||
apiClient := client.NewClient(cfg.ServerURL, cfg.Token)
|
||||
|
||||
// Initialize scanners
|
||||
// Initialize scanners for package updates (used by update orchestrator)
|
||||
aptScanner := scanner.NewAPTScanner()
|
||||
dnfScanner := scanner.NewDNFScanner()
|
||||
dockerScanner, _ := scanner.NewDockerScanner()
|
||||
windowsUpdateScanner := scanner.NewWindowsUpdateScanner()
|
||||
wingetScanner := scanner.NewWingetScanner()
|
||||
|
||||
// Initialize circuit breakers for each subsystem
|
||||
// Docker, Storage, and System scanners are created by individual subsystem handlers
|
||||
// dockerScanner is created in handleScanDocker
|
||||
// storageScanner and systemScanner are created in main for individual handlers
|
||||
|
||||
// Initialize circuit breakers for update scanners only
|
||||
aptCB := circuitbreaker.New("APT", circuitbreaker.Config{
|
||||
FailureThreshold: cfg.Subsystems.APT.CircuitBreaker.FailureThreshold,
|
||||
FailureWindow: cfg.Subsystems.APT.CircuitBreaker.FailureWindow,
|
||||
@@ -656,12 +659,6 @@ func runAgent(cfg *config.Config) error {
|
||||
OpenDuration: cfg.Subsystems.DNF.CircuitBreaker.OpenDuration,
|
||||
HalfOpenAttempts: cfg.Subsystems.DNF.CircuitBreaker.HalfOpenAttempts,
|
||||
})
|
||||
dockerCB := circuitbreaker.New("Docker", circuitbreaker.Config{
|
||||
FailureThreshold: cfg.Subsystems.Docker.CircuitBreaker.FailureThreshold,
|
||||
FailureWindow: cfg.Subsystems.Docker.CircuitBreaker.FailureWindow,
|
||||
OpenDuration: cfg.Subsystems.Docker.CircuitBreaker.OpenDuration,
|
||||
HalfOpenAttempts: cfg.Subsystems.Docker.CircuitBreaker.HalfOpenAttempts,
|
||||
})
|
||||
windowsCB := circuitbreaker.New("Windows Update", circuitbreaker.Config{
|
||||
FailureThreshold: cfg.Subsystems.Windows.CircuitBreaker.FailureThreshold,
|
||||
FailureWindow: cfg.Subsystems.Windows.CircuitBreaker.FailureWindow,
|
||||
@@ -678,33 +675,17 @@ func runAgent(cfg *config.Config) error {
|
||||
// Initialize scanner orchestrator for parallel execution and granular subsystem management
|
||||
scanOrchestrator := orchestrator.NewOrchestrator()
|
||||
|
||||
// Register update scanners
|
||||
// Register update scanners ONLY - package management systems
|
||||
scanOrchestrator.RegisterScanner("apt", orchestrator.NewAPTScannerWrapper(aptScanner), aptCB, cfg.Subsystems.APT.Timeout, cfg.Subsystems.APT.Enabled)
|
||||
scanOrchestrator.RegisterScanner("dnf", orchestrator.NewDNFScannerWrapper(dnfScanner), dnfCB, cfg.Subsystems.DNF.Timeout, cfg.Subsystems.DNF.Enabled)
|
||||
scanOrchestrator.RegisterScanner("docker", orchestrator.NewDockerScannerWrapper(dockerScanner), dockerCB, cfg.Subsystems.Docker.Timeout, cfg.Subsystems.Docker.Enabled)
|
||||
scanOrchestrator.RegisterScanner("windows", orchestrator.NewWindowsUpdateScannerWrapper(windowsUpdateScanner), windowsCB, cfg.Subsystems.Windows.Timeout, cfg.Subsystems.Windows.Enabled)
|
||||
scanOrchestrator.RegisterScanner("winget", orchestrator.NewWingetScannerWrapper(wingetScanner), wingetCB, cfg.Subsystems.Winget.Timeout, cfg.Subsystems.Winget.Enabled)
|
||||
|
||||
// Register storage and system scanners
|
||||
storageScanner := orchestrator.NewStorageScanner(AgentVersion)
|
||||
systemScanner := orchestrator.NewSystemScanner(AgentVersion)
|
||||
|
||||
// Storage and system scanners don't need circuit breakers (always available, fast operations)
|
||||
storageCB := circuitbreaker.New("Storage", circuitbreaker.Config{
|
||||
FailureThreshold: 5,
|
||||
FailureWindow: 10 * time.Minute,
|
||||
OpenDuration: 5 * time.Minute,
|
||||
HalfOpenAttempts: 1,
|
||||
})
|
||||
systemCB := circuitbreaker.New("System", circuitbreaker.Config{
|
||||
FailureThreshold: 5,
|
||||
FailureWindow: 10 * time.Minute,
|
||||
OpenDuration: 5 * time.Minute,
|
||||
HalfOpenAttempts: 1,
|
||||
})
|
||||
|
||||
scanOrchestrator.RegisterScanner("storage", storageScanner, storageCB, 30*time.Second, cfg.Subsystems.Storage.Enabled)
|
||||
scanOrchestrator.RegisterScanner("system", systemScanner, systemCB, 30*time.Second, true) // System scanner always enabled
|
||||
// NOTE: Docker, Storage, and System scanners are NOT registered with the update orchestrator
|
||||
// They have their own dedicated handlers and endpoints:
|
||||
// - Docker: handleScanDocker → ReportDockerImages()
|
||||
// - Storage: handleScanStorage → ReportMetrics()
|
||||
// - System: handleScanSystem → ReportMetrics()
|
||||
|
||||
// Initialize acknowledgment tracker for command result reliability
|
||||
ackTracker := acknowledgment.NewTracker(getStatePath())
|
||||
|
||||
Reference in New Issue
Block a user