LoadConfig read YAML-formatted config from filename into cfg.
(filename string, expandENV bool, cfg *cortex.Config)
| 244 | |
| 245 | // LoadConfig read YAML-formatted config from filename into cfg. |
| 246 | func LoadConfig(filename string, expandENV bool, cfg *cortex.Config) error { |
| 247 | buf, err := os.ReadFile(filename) |
| 248 | if err != nil { |
| 249 | return errors.Wrap(err, "Error reading config file") |
| 250 | } |
| 251 | |
| 252 | // create a sha256 hash of the config before expansion and expose it via |
| 253 | // the config_info metric |
| 254 | hash := sha256.Sum256(buf) |
| 255 | configHash.Reset() |
| 256 | configHash.WithLabelValues(fmt.Sprintf("%x", hash)).Set(1) |
| 257 | |
| 258 | if expandENV { |
| 259 | buf = expandEnv(buf) |
| 260 | } |
| 261 | |
| 262 | err = yaml.UnmarshalStrict(buf, cfg) |
| 263 | if err != nil { |
| 264 | return errors.Wrap(err, "Error parsing config file") |
| 265 | } |
| 266 | |
| 267 | return nil |
| 268 | } |
| 269 | |
| 270 | func DumpYaml(cfg *cortex.Config) { |
| 271 | out, err := yaml.Marshal(cfg) |