Skip to content

Commit

Permalink
policy/conditional: add first version of Engine
Browse files Browse the repository at this point in the history
This is just a first very basic version of the conditional engine.
  • Loading branch information
davidor committed Jul 12, 2018
1 parent a43f38f commit 18b72fa
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions gateway/src/apicast/policy/conditional/engine.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
local _M = {}

local value_of = {
request_method = function() return ngx.req.get_method() end,
request_host = function() return ngx.var.host end,
request_path = function() return ngx.var.uri end
}

function _M.evaluate(expression)
local match_attr = ngx.re.match(expression, [[^([\w]+)$]], 'oj')

if match_attr then
return value_of[match_attr[1]]()
end

local match_attr_and_value = ngx.re.match(expression, [[^([\w]+) == "([\w/]+)"$]], 'oj')

if not match_attr_and_value then
return nil, 'Error while parsing the condition'
end

local entity = match_attr_and_value[1]
local value = match_attr_and_value[2]

return value_of[entity]() == value
end

return _M

0 comments on commit 18b72fa

Please sign in to comment.