SaveConfig saves configuration to file
()
| 356 | |
| 357 | // SaveConfig saves configuration to file |
| 358 | func (m *Manager) SaveConfig() error { |
| 359 | if err := m.setupDirectories(); err != nil { |
| 360 | return err |
| 361 | } |
| 362 | |
| 363 | configViper := viper.New() |
| 364 | configViper.Set("patchmon_server", m.config.PatchmonServer) |
| 365 | configViper.Set("api_version", m.config.APIVersion) |
| 366 | configViper.Set("credentials_file", m.config.CredentialsFile) |
| 367 | configViper.Set("log_file", m.config.LogFile) |
| 368 | configViper.Set("log_level", m.config.LogLevel) |
| 369 | configViper.Set("skip_ssl_verify", m.config.SkipSSLVerify) |
| 370 | configViper.Set("update_interval", m.config.UpdateInterval) |
| 371 | configViper.Set("report_offset", m.config.ReportOffset) |
| 372 | configViper.Set("package_cache_refresh_mode", m.config.PackageCacheRefreshMode) |
| 373 | configViper.Set("package_cache_refresh_max_age", m.config.PackageCacheRefreshMaxAge) |
| 374 | |
| 375 | // Always save integrations map with all available integrations |
| 376 | if m.config.Integrations == nil { |
| 377 | m.config.Integrations = make(map[string]interface{}) |
| 378 | } |
| 379 | m.ensureComplianceNested() |
| 380 | for _, integrationName := range AvailableIntegrations { |
| 381 | if _, exists := m.config.Integrations[integrationName]; !exists { |
| 382 | switch integrationName { |
| 383 | case "compliance": |
| 384 | m.config.Integrations[integrationName] = map[string]interface{}{ |
| 385 | "enabled": "on-demand", "openscap_enabled": true, "docker_bench_enabled": false, |
| 386 | } |
| 387 | case "ssh-proxy-enabled": |
| 388 | m.config.Integrations[integrationName] = false |
| 389 | case "rdp-proxy-enabled": |
| 390 | m.config.Integrations[integrationName] = false |
| 391 | default: |
| 392 | m.config.Integrations[integrationName] = false |
| 393 | } |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | configViper.Set("integrations", m.config.Integrations) |
| 398 | |
| 399 | if err := configViper.WriteConfigAs(m.configFile); err != nil { |
| 400 | return fmt.Errorf("error writing config file: %w", err) |
| 401 | } |
| 402 | |
| 403 | return nil |
| 404 | } |
| 405 | |
| 406 | // SetUpdateInterval sets the update interval and saves it to config file |
| 407 | func (m *Manager) SetUpdateInterval(interval int) error { |
no test coverage detected