(ctx context.Context, name string, definition *latest.Variable)
| 556 | } |
| 557 | |
| 558 | func (r *resolver) fillVariable(ctx context.Context, name string, definition *latest.Variable) (interface{}, error) { |
| 559 | // is runtime variable |
| 560 | if strings.HasPrefix(name, "runtime.") { |
| 561 | return nil, fmt.Errorf("cannot resolve %s in this config area as this config region is loaded on startup. You can only use runtime variables in the following locations: \n %s", name, strings.Join(runtime.Locations, "\n ")) |
| 562 | } |
| 563 | |
| 564 | // fill variable without definition |
| 565 | if definition == nil { |
| 566 | return NewUndefinedVariable(name, r.localCache, r.log).Load(ctx, definition) |
| 567 | } |
| 568 | |
| 569 | // trim space from variable definition |
| 570 | definition.Name = strings.TrimSpace(definition.Name) |
| 571 | |
| 572 | // fill variable by source |
| 573 | switch definition.Source { |
| 574 | case latest.VariableSourceEnv: |
| 575 | return NewEnvVariable(name).Load(ctx, definition) |
| 576 | case latest.VariableSourceDefault, latest.VariableSourceInput, latest.VariableSourceAll: |
| 577 | return NewDefaultVariable(name, filepath.Dir(r.options.ConfigPath), r.localCache, r.log).Load(ctx, definition) |
| 578 | case latest.VariableSourceNone: |
| 579 | return NewNoneVariable(name).Load(ctx, definition) |
| 580 | case latest.VariableSourceCommand: |
| 581 | return NewCommandVariable(name, filepath.Dir(r.options.ConfigPath)).Load(ctx, definition) |
| 582 | default: |
| 583 | return nil, errors.Errorf("unrecognized variable source '%s', please choose one of 'all', 'input', 'env' or 'none'", name) |
| 584 | } |
| 585 | } |
no test coverage detected