97 lines
2.4 KiB
Go
97 lines
2.4 KiB
Go
// Package constants provides centralized path definitions for the RedFlag agent.
|
|
// This package ensures consistency across all components and makes path management
|
|
// maintainable and testable.
|
|
package constants
|
|
|
|
import (
|
|
"runtime"
|
|
"path/filepath"
|
|
)
|
|
|
|
// Base directories
|
|
const (
|
|
LinuxBaseDir = "/var/lib/redflag"
|
|
WindowsBaseDir = "C:\\ProgramData\\RedFlag"
|
|
)
|
|
|
|
// Subdirectory structure
|
|
const (
|
|
AgentDir = "agent"
|
|
ServerDir = "server"
|
|
CacheSubdir = "cache"
|
|
StateSubdir = "state"
|
|
MigrationSubdir = "migration_backups"
|
|
)
|
|
|
|
// Config paths
|
|
const (
|
|
LinuxConfigBase = "/etc/redflag"
|
|
WindowsConfigBase = "C:\\ProgramData\\RedFlag"
|
|
ConfigFile = "config.json"
|
|
)
|
|
|
|
// Log paths
|
|
const (
|
|
LinuxLogBase = "/var/log/redflag"
|
|
)
|
|
|
|
// Legacy paths for migration
|
|
const (
|
|
LegacyConfigPath = "/etc/aggregator/config.json"
|
|
LegacyStatePath = "/var/lib/aggregator"
|
|
)
|
|
|
|
// GetBaseDir returns platform-specific base directory
|
|
func GetBaseDir() string {
|
|
if runtime.GOOS == "windows" {
|
|
return WindowsBaseDir
|
|
}
|
|
return LinuxBaseDir
|
|
}
|
|
|
|
// GetAgentStateDir returns /var/lib/redflag/agent/state
|
|
func GetAgentStateDir() string {
|
|
return filepath.Join(GetBaseDir(), AgentDir, StateSubdir)
|
|
}
|
|
|
|
// GetAgentCacheDir returns /var/lib/redflag/agent/cache
|
|
func GetAgentCacheDir() string {
|
|
return filepath.Join(GetBaseDir(), AgentDir, CacheSubdir)
|
|
}
|
|
|
|
// GetMigrationBackupDir returns /var/lib/redflag/agent/migration_backups
|
|
func GetMigrationBackupDir() string {
|
|
return filepath.Join(GetBaseDir(), AgentDir, MigrationSubdir)
|
|
}
|
|
|
|
// GetAgentConfigPath returns /etc/redflag/agent/config.json
|
|
func GetAgentConfigPath() string {
|
|
if runtime.GOOS == "windows" {
|
|
return filepath.Join(WindowsConfigBase, AgentDir, ConfigFile)
|
|
}
|
|
return filepath.Join(LinuxConfigBase, AgentDir, ConfigFile)
|
|
}
|
|
|
|
// GetAgentConfigDir returns /etc/redflag/agent
|
|
func GetAgentConfigDir() string {
|
|
if runtime.GOOS == "windows" {
|
|
return filepath.Join(WindowsConfigBase, AgentDir)
|
|
}
|
|
return filepath.Join(LinuxConfigBase, AgentDir)
|
|
}
|
|
|
|
// GetAgentLogDir returns /var/log/redflag/agent
|
|
func GetAgentLogDir() string {
|
|
return filepath.Join(LinuxLogBase, AgentDir)
|
|
}
|
|
|
|
// GetLegacyAgentConfigPath returns legacy /etc/aggregator/config.json
|
|
func GetLegacyAgentConfigPath() string {
|
|
return LegacyConfigPath
|
|
}
|
|
|
|
// GetLegacyAgentStatePath returns legacy /var/lib/aggregator
|
|
func GetLegacyAgentStatePath() string {
|
|
return LegacyStatePath
|
|
}
|