ReadConfig reads project configuration from the config.yaml file It does not attempt to set default values; that's NewApp's job. returns the list of config files read
(includeOverrides bool)
| 360 | // It does not attempt to set default values; that's NewApp's job. |
| 361 | // returns the list of config files read |
| 362 | func (app *DdevApp) ReadConfig(includeOverrides bool) ([]string, error) { |
| 363 | if app.ConfigPath == "" { |
| 364 | app.ConfigPath = app.GetConfigPath("config.yaml") |
| 365 | } |
| 366 | |
| 367 | configOverrides := []string{} |
| 368 | var err error |
| 369 | // Load config.*.y*ml after in glob order |
| 370 | if includeOverrides { |
| 371 | glob := filepath.Join(filepath.Dir(app.ConfigPath), "config.*.y*ml") |
| 372 | configOverrides, err = filepath.Glob(glob) |
| 373 | if err != nil { |
| 374 | return []string{}, err |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | allFiles := append([]string{app.ConfigPath}, configOverrides...) |
| 379 | fileContents := make(map[string][]byte) |
| 380 | |
| 381 | // Add Pre-Load Validation (Hook Checks) |
| 382 | for _, file := range allFiles { |
| 383 | source, err := os.ReadFile(file) |
| 384 | if err != nil { |
| 385 | return []string{}, fmt.Errorf("unable to read config file %s: %v", file, err) |
| 386 | } |
| 387 | err = validateHookYAML(source) |
| 388 | if err != nil { |
| 389 | return []string{}, fmt.Errorf("invalid configuration in %s: %v", file, err) |
| 390 | } |
| 391 | fileContents[file] = source |
| 392 | } |
| 393 | |
| 394 | // Sort WebExtraExposedPorts so the entry matching configured router ports comes first |
| 395 | SortWebExtraExposedPorts(app) |
| 396 | |
| 397 | // Determine overrides and their contents in correct order |
| 398 | var overrides []settings.OverrideConfig |
| 399 | var overrideKeys []string |
| 400 | for _, f := range configOverrides { |
| 401 | if f != app.ConfigPath { |
| 402 | overrides = append(overrides, settings.OverrideConfig{ |
| 403 | Path: f, |
| 404 | Content: fileContents[f], |
| 405 | }) |
| 406 | overrideKeys = append(overrideKeys, f) |
| 407 | } |
| 408 | } |
| 409 | |
| 410 | err = settings.LoadProjectConfigFromContents(fileContents[app.ConfigPath], overrides, app) |
| 411 | if err != nil { |
| 412 | return []string{}, fmt.Errorf("failed to load project config: %v", err) |
| 413 | } |
| 414 | |
| 415 | app.ConfigPostLoadCleanup() |
| 416 | |
| 417 | return append([]string{app.ConfigPath}, overrideKeys...), nil |
| 418 | } |
| 419 |