(ctx context.Context, config map[string]interface{}, resolver variable.Resolver)
| 453 | } |
| 454 | |
| 455 | func prepareProfiles(ctx context.Context, config map[string]interface{}, resolver variable.Resolver) (map[string]interface{}, error) { |
| 456 | rawProfiles := config["profiles"] |
| 457 | if rawProfiles == nil { |
| 458 | return config, nil |
| 459 | } |
| 460 | |
| 461 | resolved, err := resolve(ctx, rawProfiles, resolver) |
| 462 | if err != nil { |
| 463 | return nil, err |
| 464 | } |
| 465 | |
| 466 | profiles, ok := resolved.([]interface{}) |
| 467 | if !ok { |
| 468 | return nil, fmt.Errorf("error validating profiles: not an array") |
| 469 | } |
| 470 | |
| 471 | for idx, profile := range profiles { |
| 472 | resolvedProfile, err := resolve(ctx, profile, resolver) |
| 473 | if err != nil { |
| 474 | return nil, err |
| 475 | } |
| 476 | |
| 477 | profileMap, ok := resolvedProfile.(map[string]interface{}) |
| 478 | if !ok { |
| 479 | return nil, errors.Wrapf(err, "error resolving profiles[%d], object expected", idx) |
| 480 | } |
| 481 | |
| 482 | // Resolve merge field |
| 483 | if profileMap["merge"] != nil { |
| 484 | merge, err := resolve(ctx, profileMap["merge"], resolver) |
| 485 | if err != nil { |
| 486 | return nil, err |
| 487 | } |
| 488 | profileMap["merge"] = merge |
| 489 | } |
| 490 | |
| 491 | // Resolve patches field |
| 492 | if profileMap["patches"] != nil { |
| 493 | patches, err := resolve(ctx, profileMap["patches"], resolver) |
| 494 | if err != nil { |
| 495 | return nil, err |
| 496 | } |
| 497 | profileMap["patches"] = patches |
| 498 | } |
| 499 | |
| 500 | // Resolve replace field |
| 501 | if profileMap["replace"] != nil { |
| 502 | replace, err := resolve(ctx, profileMap["replace"], resolver) |
| 503 | if err != nil { |
| 504 | return nil, err |
| 505 | } |
| 506 | profileMap["replace"] = replace |
| 507 | } |
| 508 | |
| 509 | // Validate that the profile doesn't use forbidden expressions |
| 510 | err = validateProfile(profileMap) |
| 511 | if err != nil { |
| 512 | return nil, errors.Wrapf(err, "error validating profiles[%d]", idx) |
no test coverage detected