@@ -47,13 +47,17 @@ type ScopedVariable interface {
47
47
type MutableVariable interface {
48
48
Set (ctx * Context , value interface {}) error
49
49
Append (ctx * Context , value interface {}) error
50
- GetVariableOpts () VariableOpts
51
- SetVariableOpts (opts VariableOpts )
50
+ }
51
+
52
+ // MutableScopedVariable is the interface for scoped variables whose value can be changed
53
+ type MutableScopedVariable interface {
54
+ Set (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error
55
+ Append (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error
52
56
}
53
57
54
58
// settableVariable describes a SECL variable
55
59
type settableVariable struct {
56
- setFnc func (ctx * Context , value interface {}) error
60
+ setFnc func (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error
57
61
opts VariableOpts
58
62
}
59
63
@@ -62,16 +66,16 @@ type expirableVariable interface {
62
66
}
63
67
64
68
// Set the variable with the specified value
65
- func (v * settableVariable ) Set (ctx * Context , value interface {}) error {
69
+ func (v * settableVariable ) Set (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error {
66
70
if v .setFnc == nil {
67
71
return errors .New ("variable is not mutable" )
68
72
}
69
73
70
- return v .setFnc (ctx , value )
74
+ return v .setFnc (ctx , value , scopeFieldEvaluator )
71
75
}
72
76
73
77
// Append a value to the variable
74
- func (v * settableVariable ) Append (_ * Context , _ interface {}) error {
78
+ func (v * settableVariable ) Append (_ * Context , _ interface {}, _ Evaluator ) error {
75
79
return errAppendNotSupported
76
80
}
77
81
@@ -112,7 +116,7 @@ func (i *ScopedIntVariable) GetValue(ctx *Context) (interface{}, bool) {
112
116
}
113
117
114
118
// NewScopedIntVariable returns a new integer variable
115
- func NewScopedIntVariable (intFnc func (ctx * Context ) (int , bool ), setFnc func (ctx * Context , value interface {}) error ) * ScopedIntVariable {
119
+ func NewScopedIntVariable (intFnc func (ctx * Context ) (int , bool ), setFnc func (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error ) * ScopedIntVariable {
116
120
return & ScopedIntVariable {
117
121
settableVariable : settableVariable {
118
122
setFnc : setFnc ,
@@ -147,7 +151,7 @@ func (s *ScopedStringVariable) GetValue(ctx *Context) (interface{}, bool) {
147
151
}
148
152
149
153
// NewScopedStringVariable returns a new scoped string variable
150
- func NewScopedStringVariable (strFnc func (ctx * Context ) (string , bool ), setFnc func (ctx * Context , value interface {}) error ) * ScopedStringVariable {
154
+ func NewScopedStringVariable (strFnc func (ctx * Context ) (string , bool ), setFnc func (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error ) * ScopedStringVariable {
151
155
return & ScopedStringVariable {
152
156
strFnc : strFnc ,
153
157
settableVariable : settableVariable {
@@ -181,7 +185,7 @@ func (b *ScopedBoolVariable) GetValue(ctx *Context) (interface{}, bool) {
181
185
}
182
186
183
187
// NewScopedBoolVariable returns a new boolean variable
184
- func NewScopedBoolVariable (boolFnc func (ctx * Context ) (bool , bool ), setFnc func (ctx * Context , value interface {}) error ) * ScopedBoolVariable {
188
+ func NewScopedBoolVariable (boolFnc func (ctx * Context ) (bool , bool ), setFnc func (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error ) * ScopedBoolVariable {
185
189
return & ScopedBoolVariable {
186
190
boolFnc : boolFnc ,
187
191
settableVariable : settableVariable {
@@ -215,7 +219,7 @@ func (i *ScopedIPVariable) GetValue(ctx *Context) (interface{}, bool) {
215
219
}
216
220
217
221
// NewScopedIPVariable returns a new scoped IP variable
218
- func NewScopedIPVariable (ipFnc func (ctx * Context ) (net.IPNet , bool ), setFnc func (ctx * Context , value interface {}) error ) * ScopedIPVariable {
222
+ func NewScopedIPVariable (ipFnc func (ctx * Context ) (net.IPNet , bool ), setFnc func (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error ) * ScopedIPVariable {
219
223
return & ScopedIPVariable {
220
224
ipFnc : ipFnc ,
221
225
settableVariable : settableVariable {
@@ -249,24 +253,24 @@ func (s *ScopedStringArrayVariable) GetValue(ctx *Context) (interface{}, bool) {
249
253
}
250
254
251
255
// Set the array values
252
- func (s * ScopedStringArrayVariable ) Set (ctx * Context , value interface {}) error {
256
+ func (s * ScopedStringArrayVariable ) Set (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error {
253
257
if s , ok := value .(string ); ok {
254
258
value = []string {s }
255
259
}
256
- return s .settableVariable .Set (ctx , value )
260
+ return s .settableVariable .Set (ctx , value , scopeFieldEvaluator )
257
261
}
258
262
259
263
// Append a value to the array
260
- func (s * ScopedStringArrayVariable ) Append (ctx * Context , value interface {}) error {
264
+ func (s * ScopedStringArrayVariable ) Append (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error {
261
265
if val , ok := value .(string ); ok {
262
266
value = []string {val }
263
267
}
264
268
values , _ := s .strFnc (ctx )
265
- return s .Set (ctx , append (values , value .([]string )... ))
269
+ return s .Set (ctx , append (values , value .([]string )... ), scopeFieldEvaluator )
266
270
}
267
271
268
272
// NewScopedStringArrayVariable returns a new scoped string array variable
269
- func NewScopedStringArrayVariable (strFnc func (ctx * Context ) ([]string , bool ), setFnc func (ctx * Context , value interface {}) error ) * ScopedStringArrayVariable {
273
+ func NewScopedStringArrayVariable (strFnc func (ctx * Context ) ([]string , bool ), setFnc func (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error ) * ScopedStringArrayVariable {
270
274
return & ScopedStringArrayVariable {
271
275
strFnc : strFnc ,
272
276
settableVariable : settableVariable {
@@ -300,24 +304,24 @@ func (v *ScopedIntArrayVariable) GetValue(ctx *Context) (interface{}, bool) {
300
304
}
301
305
302
306
// Set the array values
303
- func (v * ScopedIntArrayVariable ) Set (ctx * Context , value interface {}) error {
307
+ func (v * ScopedIntArrayVariable ) Set (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error {
304
308
if i , ok := value .(int ); ok {
305
309
value = []int {i }
306
310
}
307
- return v .settableVariable .Set (ctx , value )
311
+ return v .settableVariable .Set (ctx , value , scopeFieldEvaluator )
308
312
}
309
313
310
314
// Append a value to the array
311
- func (v * ScopedIntArrayVariable ) Append (ctx * Context , value interface {}) error {
315
+ func (v * ScopedIntArrayVariable ) Append (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error {
312
316
if val , ok := value .(int ); ok {
313
317
value = []int {val }
314
318
}
315
319
values , _ := v .intFnc (ctx )
316
- return v .Set (ctx , append (values , value .([]int )... ))
320
+ return v .Set (ctx , append (values , value .([]int )... ), scopeFieldEvaluator )
317
321
}
318
322
319
323
// NewScopedIntArrayVariable returns a new integer array variable
320
- func NewScopedIntArrayVariable (intFnc func (ctx * Context ) ([]int , bool ), setFnc func (ctx * Context , value interface {}) error ) * ScopedIntArrayVariable {
324
+ func NewScopedIntArrayVariable (intFnc func (ctx * Context ) ([]int , bool ), setFnc func (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error ) * ScopedIntArrayVariable {
321
325
return & ScopedIntArrayVariable {
322
326
intFnc : intFnc ,
323
327
settableVariable : settableVariable {
@@ -351,24 +355,24 @@ func (i *ScopedIPArrayVariable) GetValue(ctx *Context) (interface{}, bool) {
351
355
}
352
356
353
357
// Set the array values
354
- func (i * ScopedIPArrayVariable ) Set (ctx * Context , value interface {}) error {
358
+ func (i * ScopedIPArrayVariable ) Set (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error {
355
359
if ip , ok := value .(net.IPNet ); ok {
356
360
value = []net.IPNet {ip }
357
361
}
358
- return i .settableVariable .Set (ctx , value )
362
+ return i .settableVariable .Set (ctx , value , scopeFieldEvaluator )
359
363
}
360
364
361
365
// Append a value to the array
362
- func (i * ScopedIPArrayVariable ) Append (ctx * Context , value interface {}) error {
366
+ func (i * ScopedIPArrayVariable ) Append (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error {
363
367
if val , ok := value .(net.IPNet ); ok {
364
368
value = []net.IPNet {val }
365
369
}
366
370
values , _ := i .ipFnc (ctx )
367
- return i .Set (ctx , append (values , value .([]net.IPNet )... ))
371
+ return i .Set (ctx , append (values , value .([]net.IPNet )... ), scopeFieldEvaluator )
368
372
}
369
373
370
374
// NewScopedIPArrayVariable returns a new IP array variable
371
- func NewScopedIPArrayVariable (ipFnc func (ctx * Context ) ([]net.IPNet , bool ), setFnc func (ctx * Context , value interface {}) error ) * ScopedIPArrayVariable {
375
+ func NewScopedIPArrayVariable (ipFnc func (ctx * Context ) ([]net.IPNet , bool ), setFnc func (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error ) * ScopedIPArrayVariable {
372
376
return & ScopedIPArrayVariable {
373
377
ipFnc : ipFnc ,
374
378
settableVariable : settableVariable {
@@ -952,7 +956,7 @@ type VariableScope interface {
952
956
}
953
957
954
958
// Scoper maps a variable to the entity its scoped to
955
- type Scoper func (ctx * Context ) VariableScope
959
+ type Scoper func (ctx * Context , scopeFieldEvaluator Evaluator ) VariableScope
956
960
957
961
// Variables holds a set of variables
958
962
type Variables struct {
@@ -1042,7 +1046,7 @@ func (v *ScopedVariables) Len() int {
1042
1046
// NewSECLVariable returns new variable of the type of the specified value
1043
1047
func (v * ScopedVariables ) NewSECLVariable (name string , value interface {}, opts VariableOpts ) (SECLVariable , error ) {
1044
1048
getVariable := func (ctx * Context ) MutableSECLVariable {
1045
- scope := v .scoper (ctx )
1049
+ scope := v .scoper (ctx , nil )
1046
1050
if scope == nil {
1047
1051
return nil
1048
1052
}
@@ -1060,8 +1064,8 @@ func (v *ScopedVariables) NewSECLVariable(name string, value interface{}, opts V
1060
1064
return vars [name ]
1061
1065
}
1062
1066
1063
- setVariable := func (ctx * Context , value interface {}) error {
1064
- scope := v .scoper (ctx )
1067
+ setVariable := func (ctx * Context , value interface {}, scopeFieldEvaluator Evaluator ) error {
1068
+ scope := v .scoper (ctx , scopeFieldEvaluator )
1065
1069
if scope == nil {
1066
1070
return fmt .Errorf ("failed to scope variable '%s'" , name )
1067
1071
}
0 commit comments