You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(event-gateway): add expression examples and info about the context (#3801)
* feat(event-gateway): add expression examples and info about the context
Add what is available when and some basic examples
Fix#3409
Signed-off-by: Charly Molter <[email protected]>
* fix lint
* table formatting
---------
Signed-off-by: Charly Molter <[email protected]>
Co-authored-by: Angel <[email protected]>
Conditions must be between 1 and 1000 characters long.
@@ -65,10 +65,115 @@ rows:
65
65
66
66
{{site.event_gateway}} supports the following string functions in conditional fields:
67
67
68
-
*`includes`: Performs a case-sensitive search to determine whether a given string may be found within this string, as defined in the [JavaScript standard](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes).
69
-
*`startsWith`: Determines whether the string begins with the characters of a specified string, [equivalent to the JavaScript standard function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith).
70
-
*`endsWith`: Determines whether the string ends with the characters of a specified string, [equivalent to the JavaScript standard function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith).
68
+
*`includes`: Performs a case-sensitive search to determine whether a given string may be found within this string, as
69
+
defined in
70
+
the [JavaScript standard](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes).
71
+
*`startsWith`: Determines whether the string begins with the characters of a specified
72
+
string, [equivalent to the JavaScript standard function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith).
73
+
*`endsWith`: Determines whether the string ends with the characters of a specified
74
+
string, [equivalent to the JavaScript standard function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith).
71
75
*`substring`: Returns the part of this string from the start index up to and excluding the end index.
72
-
*`match`: Retrieves the result of matching this string against an [RE2 regular expression](https://github.com/google/re2/wiki/syntax) string.
76
+
*`match`: Retrieves the result of matching this string against
77
+
an [RE2 regular expression](https://github.com/google/re2/wiki/syntax) string.
73
78
79
+
### Supported fields
74
80
81
+
Depending on where an expression is authored the fields available in the context vary.
82
+
In this section we state for each area how the context varies.
83
+
The source of truth for these is the `x-expression` field in
84
+
the [API specification](/api/konnect/event-gateway/v1/).
85
+
86
+
{% table %}
87
+
columns:
88
+
- title: Variable
89
+
key: variable
90
+
- title: Type
91
+
key: type
92
+
- title: Description
93
+
key: description
94
+
- title: Availability
95
+
key: availability
96
+
- title: Example
97
+
key: example
98
+
rows:
99
+
- variable: "`context.auth.type`"
100
+
type: "`string`"
101
+
description: |
102
+
The type of authentication used
103
+
availability: |
104
+
Cluster, Produce and Consume policies
105
+
example: |
106
+
`context.auth.type == 'anonymous'`
107
+
- variable: "`context.auth.principal.name`"
108
+
type: "`string`"
109
+
description: |
110
+
The name of the principal for this connection
111
+
availability: |
112
+
Cluster, Produce and Consume policies
113
+
example: |
114
+
`context.auth.principal.name == 'user1'`
115
+
- variable: "`context.topic.name`"
116
+
type: "`string`"
117
+
description: |
118
+
The name of the topic of the record
119
+
availability: |
120
+
Produce and Consume policies
121
+
example: |
122
+
`context.topic.name == 'my-ns.my-topic'`
123
+
- variable: "`record.headers`"
124
+
type: "`map<string, string>`"
125
+
description: |
126
+
The headers of the record
127
+
availability: |
128
+
Produce and Consume policies
129
+
example: |
130
+
`record.headers['skip-record'] == 'true'`
131
+
- variable: "`record.value.content`"
132
+
type: "`map<string, string>`"
133
+
description: |
134
+
The value of the record. Deep fields can be accessed using json object notation
135
+
availability: |
136
+
Produce and Consume policies used as children of Schema Validation
137
+
example: |
138
+
`record.value.content['sub.other'] == 3`
139
+
- variable: "`record.value.validated`"
140
+
type: "`boolean`"
141
+
description: |
142
+
Whether record validation succeeded or not
143
+
availability: |
144
+
Produce and Consume policies used as children of Schema Validation
145
+
example: |
146
+
`record.value.validated == true`
147
+
{% endtable %}
148
+
149
+
### Example expressions
150
+
151
+
152
+
Don't apply a policy if a record has a `x-restricted=true` header and user is not admin:
0 commit comments