@@ -6,13 +6,12 @@ package transpiler
66
77import (
88 "fmt"
9+ "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/composable"
910 "regexp"
1011 "strings"
1112 "unicode"
1213
1314 "github.com/elastic/beats/v7/libbeat/common"
14-
15- "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/composable"
1615)
1716
1817var varsRegex = regexp .MustCompile (`\${([\p{L}\d\s\\\-_|.'"]*)}` )
@@ -59,22 +58,6 @@ func (v *Vars) Replace(value string) (Node, error) {
5958 }
6059 set := false
6160 for _ , val := range vars {
62- for providerName , provider := range v .fetchContextProviders {
63- if varPrefixMatched (val .Value (), providerName ) {
64- fetchProvider := provider .(composable.FetchContextProvider )
65- fval , found := fetchProvider .Fetch (val .Value ())
66- if found {
67- result += value [lastIndex :r [0 ]] + fval
68- set = true
69- break
70- } else {
71- return NewStrVal ("" ), ErrNoMatch
72- }
73- }
74- }
75- if set {
76- continue
77- }
7861 switch val .(type ) {
7962 case * constString :
8063 result += value [lastIndex :r [0 ]] + val .Value ()
@@ -110,6 +93,19 @@ func (v *Vars) Replace(value string) (Node, error) {
11093
11194// Lookup returns the value from the vars.
11295func (v * Vars ) Lookup (name string ) (interface {}, bool ) {
96+ // check if the value can be retrieved from a FetchContextProvider
97+ for providerName , provider := range v .fetchContextProviders {
98+ if varPrefixMatched (name , providerName ) {
99+ fetchProvider := provider .(composable.FetchContextProvider )
100+ fval , found := fetchProvider .Fetch (name )
101+ if found {
102+ return & StrVal {value : fval }, true
103+ } else {
104+ return & StrVal {value : "" }, false
105+ }
106+ }
107+ }
108+ // lookup in the AST tree
113109 return v .tree .Lookup (name )
114110}
115111
0 commit comments