Some checks failed
Tests / 🛃 Unit tests (push) Failing after 13s
Tests / 🗄 DB tests (push) Failing after 19s
Tests / 🐍 Lint python scripts (push) Failing after 1s
Tests / ⌨ Golang Lint (push) Failing after 1s
Tests / 📦 Packit config lint (push) Failing after 1s
Tests / 🔍 Check source preparation (push) Failing after 1s
Tests / 🔍 Check for valid snapshot urls (push) Failing after 1s
Tests / 🔍 Check for missing or unused runner repos (push) Failing after 1s
Tests / 🐚 Shellcheck (push) Failing after 1s
Tests / 📦 RPMlint (push) Failing after 1s
Tests / Gitlab CI trigger helper (push) Failing after 1s
Tests / 🎀 kube-linter (push) Failing after 1s
Tests / 🧹 cloud-cleaner-is-enabled (push) Successful in 3s
Tests / 🔍 Check spec file osbuild/images dependencies (push) Failing after 1s
187 lines
4.6 KiB
Go
187 lines
4.6 KiB
Go
package advanced
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
)
|
|
|
|
// AdvancedConfigManager handles loading and saving advanced features configuration
|
|
type AdvancedConfigManager struct {
|
|
configPath string
|
|
config *AdvancedConfig
|
|
}
|
|
|
|
// LoadAdvancedConfig loads advanced features configuration from file
|
|
func LoadAdvancedConfig(configPath string) (*AdvancedConfig, error) {
|
|
manager := &AdvancedConfigManager{
|
|
configPath: configPath,
|
|
}
|
|
|
|
return manager.Load()
|
|
}
|
|
|
|
// Load loads configuration from file
|
|
func (acm *AdvancedConfigManager) Load() (*AdvancedConfig, error) {
|
|
// Check if config file exists
|
|
if _, err := os.Stat(acm.configPath); os.IsNotExist(err) {
|
|
// Create default configuration
|
|
acm.config = acm.createDefaultConfig()
|
|
return acm.config, acm.Save()
|
|
}
|
|
|
|
// Read existing configuration
|
|
data, err := os.ReadFile(acm.configPath)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to read config file: %w", err)
|
|
}
|
|
|
|
// Parse configuration
|
|
acm.config = &AdvancedConfig{}
|
|
if err := json.Unmarshal(data, acm.config); err != nil {
|
|
return nil, fmt.Errorf("failed to parse config file: %w", err)
|
|
}
|
|
|
|
return acm.config, nil
|
|
}
|
|
|
|
// Save saves configuration to file
|
|
func (acm *AdvancedConfigManager) Save() error {
|
|
if acm.config == nil {
|
|
return fmt.Errorf("no configuration to save")
|
|
}
|
|
|
|
// Create directory if it doesn't exist
|
|
configDir := filepath.Dir(acm.configPath)
|
|
if err := os.MkdirAll(configDir, 0755); err != nil {
|
|
return fmt.Errorf("failed to create config directory: %w", err)
|
|
}
|
|
|
|
// Marshal configuration
|
|
data, err := json.MarshalIndent(acm.config, "", " ")
|
|
if err != nil {
|
|
return fmt.Errorf("failed to marshal config: %w", err)
|
|
}
|
|
|
|
// Write to file
|
|
if err := os.WriteFile(acm.configPath, data, 0644); err != nil {
|
|
return fmt.Errorf("failed to write config file: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// UpdateConfig updates configuration and saves to file
|
|
func (acm *AdvancedConfigManager) UpdateConfig(updates map[string]interface{}) error {
|
|
if acm.config == nil {
|
|
return fmt.Errorf("no configuration loaded")
|
|
}
|
|
|
|
// Apply updates
|
|
for key, value := range updates {
|
|
switch key {
|
|
case "enabled":
|
|
if boolVal, ok := value.(bool); ok {
|
|
acm.config.Enabled = boolVal
|
|
}
|
|
case "multi_arch":
|
|
if boolVal, ok := value.(bool); ok {
|
|
acm.config.MultiArch = boolVal
|
|
}
|
|
case "customization":
|
|
if boolVal, ok := value.(bool); ok {
|
|
acm.config.Customization = boolVal
|
|
}
|
|
case "future_proof":
|
|
if boolVal, ok := value.(bool); ok {
|
|
acm.config.FutureProof = boolVal
|
|
}
|
|
case "metadata":
|
|
if mapVal, ok := value.(map[string]string); ok {
|
|
acm.config.Metadata = mapVal
|
|
}
|
|
}
|
|
}
|
|
|
|
// Save updated configuration
|
|
return acm.Save()
|
|
}
|
|
|
|
// createDefaultConfig creates a default advanced features configuration
|
|
func (acm *AdvancedConfigManager) createDefaultConfig() *AdvancedConfig {
|
|
return &AdvancedConfig{
|
|
Enabled: true,
|
|
MultiArch: true,
|
|
Customization: true,
|
|
FutureProof: true,
|
|
Metadata: map[string]string{
|
|
"version": "1.0.0",
|
|
"created": time.Now().Format(time.RFC3339),
|
|
"description": "Default advanced features configuration for Debian Forge",
|
|
},
|
|
}
|
|
}
|
|
|
|
// ValidateConfig validates the configuration
|
|
func (acm *AdvancedConfigManager) ValidateConfig() error {
|
|
if acm.config == nil {
|
|
return fmt.Errorf("no configuration loaded")
|
|
}
|
|
|
|
// Validate that at least one feature is enabled
|
|
if !acm.config.MultiArch && !acm.config.Customization && !acm.config.FutureProof {
|
|
return fmt.Errorf("at least one advanced feature must be enabled")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// GetMultiArchConfig returns multi-architecture configuration
|
|
func (acm *AdvancedConfigManager) GetMultiArchConfig() *MultiArchConfig {
|
|
if acm.config == nil {
|
|
return nil
|
|
}
|
|
|
|
return &MultiArchConfig{
|
|
Enabled: acm.config.MultiArch,
|
|
ARM64: true,
|
|
RISC_V: true,
|
|
MultiArchGen: true,
|
|
Optimization: true,
|
|
Metadata: acm.config.Metadata,
|
|
}
|
|
}
|
|
|
|
// GetCustomizationConfig returns customization configuration
|
|
func (acm *AdvancedConfigManager) GetCustomizationConfig() *CustomizationConfig {
|
|
if acm.config == nil {
|
|
return nil
|
|
}
|
|
|
|
return &CustomizationConfig{
|
|
Enabled: acm.config.Customization,
|
|
KernelConfig: true,
|
|
HardwareOpt: true,
|
|
Partitioning: true,
|
|
Bootloader: true,
|
|
Metadata: acm.config.Metadata,
|
|
}
|
|
}
|
|
|
|
// GetFutureProofConfig returns future-proofing configuration
|
|
func (acm *AdvancedConfigManager) GetFutureProofConfig() *FutureProofConfig {
|
|
if acm.config == nil {
|
|
return nil
|
|
}
|
|
|
|
return &FutureProofConfig{
|
|
Enabled: acm.config.FutureProof,
|
|
Technologies: true,
|
|
DebianVersions: true,
|
|
Upstream: true,
|
|
Roadmap: true,
|
|
Metadata: acm.config.Metadata,
|
|
}
|
|
}
|