MCPcopy
hub / github.com/PatchMon/PatchMon / SaveConfig

Method SaveConfig

agent-source-code/internal/config/config.go:358–404  ·  view source on GitHub ↗

SaveConfig saves configuration to file

()

Source from the content-addressed store, hash-verified

356
357// SaveConfig saves configuration to file
358func (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
407func (m *Manager) SetUpdateInterval(interval int) error {

Callers 9

LoadConfigMethod · 0.95
SetUpdateIntervalMethod · 0.95
SetReportOffsetMethod · 0.95
SetIntegrationEnabledMethod · 0.95
SetComplianceModeMethod · 0.95
SetComplianceScannersMethod · 0.95
configureCredsFunction · 0.80

Calls 3

setupDirectoriesMethod · 0.95
SetMethod · 0.45

Tested by

no test coverage detected