responsible for central config distribution
(n *Nylon)
| 76 | |
| 77 | // responsible for central config distribution |
| 78 | func checkForConfigUpdates(n *Nylon) error { |
| 79 | if n.CentralCfg.Dist == nil { |
| 80 | return errors.New("nylon is not configured for automatic config distribution") |
| 81 | } |
| 82 | key := n.CentralCfg.Dist.Key |
| 83 | currentTimestamp := n.Timestamp |
| 84 | repos := slices.Clone(n.CentralCfg.Dist.Repos) |
| 85 | for _, repoStr := range repos { |
| 86 | go func(repo string) { |
| 87 | err := func() error { |
| 88 | config, err := FetchConfig(repo, key, n.MaxConfigSize) |
| 89 | if err != nil { |
| 90 | return err |
| 91 | } |
| 92 | if config.Timestamp <= currentTimestamp { |
| 93 | if n.DBG_log_repo_updates { |
| 94 | n.Log.Debug(fmt.Sprintf("found old update bundle at %s, skipping", repo)) |
| 95 | } |
| 96 | return nil |
| 97 | } |
| 98 | n.Dispatch(func() error { |
| 99 | if config.Timestamp <= n.Timestamp { |
| 100 | return nil |
| 101 | } |
| 102 | n.Log.Info("Found a new config update in repo", "repo", repo) |
| 103 | result, err := n.ApplyCentralConfig(config) |
| 104 | if err != nil { |
| 105 | n.Log.Error("failed to apply central config update", "repo", repo, "result", result, "err", err) |
| 106 | return nil |
| 107 | } |
| 108 | if n.ConfigPath != "" { |
| 109 | bytes, err := yaml.Marshal(config) |
| 110 | if err != nil { |
| 111 | n.Log.Error("Error marshalling new config", "err", err.Error()) |
| 112 | return nil |
| 113 | } |
| 114 | err = os.WriteFile(n.ConfigPath, bytes, 0600) |
| 115 | if err != nil { |
| 116 | n.Log.Error("Error writing new config", "err", err.Error()) |
| 117 | } |
| 118 | } |
| 119 | return nil |
| 120 | }) |
| 121 | return nil |
| 122 | }() |
| 123 | if err != nil { |
| 124 | n.Log.Error("Error updating config", "err", err.Error()) |
| 125 | } |
| 126 | }(repoStr) |
| 127 | } |
| 128 | return nil |
| 129 | } |
no test coverage detected