Skip to main content

Workflow

This plugin introduces the lua-resty-expr for performing complex traffic control tasks on your APIs.

Attributes

NameTypeRequiredDefaultValid valuesDescription
rules.casearray[array]NoVariable list to match for filtering requests for conditional traffic split. It is in the format {variable operator value}. For example, {"arg_name", "==", "json"}. The variables here are consistent with NGINX internal variables.
rules.actionsarray[object]TrueThe action to be performed after matching successfully. Currently, only one element is supported in actions. The first child element of the actions' only element can be return or limit-count.

actions Attributes

  • return
NameTypeRequiredDefaultValid valuesDescription
actions[1].returnstringNoReturn directly to the client.
actions[1].[2].codeintegerNoHTTP status code returned to the client.
  • limit-count
NameTypeRequiredDefaultValid valuesDescription
actions[1].limit-countstringNoExecute the functions of the limit-count plugin.
actions[1].[2]objectNolimit-count plugin configuration, group is not supported.
note

Match case in order according to the index of the rules, and execute actions directly if case match.

Enable plugin

curl https://adrsearche-us-east.photoniq.macrometa.io:9080/api/stargate/v1/routes \
-H "X-API-KEY: $admin_key" -X PUT -d '
{
"uri":"/hello/*",
"plugins":{
"workflow":{
"rules":[
{
"case":[
["uri", "==", "/hello/pants"]
],
"actions":[
[
"return",
{"code": 403}
]
]
},
{
"case":[
["uri", "==", "/hello/v1/app"]
],
"actions":[
[
"limit-count",
{
"count":2,
"time_window":30,
"rejected_code":429
}
]
]
}
]
}
},
"upstream":{
"type":"roundrobin",
"nodes":{
"127.0.0.1:1980":1
}
}
}'

This example route configuration enables the workflow plugin and creates two rules:

  • Case 1: First rule returns a 403 status code if the requested uri is /hello/pants.
curl http://127.0.0.1:9080/hello/pants -i
HTTP/1.1 403 Forbidden
......

{"error_msg":"rejected by workflow"}
  • Case 2: if the request uri is /hello/v1/app, the workflow plugin executes the limit-count plugin
curl http://127.0.0.1:9080/hello/v1/app -i
HTTP/1.1 200 OK
curl http://127.0.0.1:9080/hello/v1/app -i
HTTP/1.1 200 OK
curl http://127.0.0.1:9080/hello/v1/app -i
HTTP/1.1 429 Too Many Requests