-
Notifications
You must be signed in to change notification settings - Fork 11
Custom rules, predicates and expression trees
Michał Kowal edited this page Mar 19, 2024
·
1 revision
Custom rules have been created to give the user the possibility to describe custom request validation rules, this way a lot of the validation can be configured from the configuration.
Currently, custom rules need to be described under rules:
and then custom:
YAML tags as the list of rules is described by the name
and predicate
:
rules:
custom:
- name: "request payload must contain at least one character and should contain at least one header"
predicate: "p => LEN(p.payload) > 0 && LEN(p.headers) > 0"
Whenever the config is edited and there is a change in the custom rules, those are compiled on each WAFFLE run. Then those rules are executed on each request.
The predicate structure is simple and is based on the C# lambda predicates. You can divide predicate into 3 parts:
<variable> => <expression>
- variable
- lambda
- expression
Currently supported characters and methods:
var (
tokenVariable = "var"
tokenFunction = "func"
tokenNumber = "token_number"
tokenField = "field"
tokenSpace = "space"
tokenLParen = "("
tokenRParen = ")"
tokenDot = "."
tokenDoubleAmpersand = "&&"
tokenMoreThan = ">"
tokenLessThan = "<"
tokenSingleApostrophe = "'"
specialCharacters = []string{
tokenLParen,
tokenRParen,
tokenDot,
tokenDoubleAmpersand,
tokenMoreThan,
tokenLessThan,
tokenSingleApostrophe,
}
methodLen = "LEN"
methodFormat = "FORMAT"
methods = []string{
methodLen,
methodFormat,
}
fieldPayload = "payload"
fieldHeaders = "headers"
fields = []string{
fieldPayload,
fieldHeaders,
}
)