Skip to content

Commit

Permalink
[Policy] routing using the valid context on operations
Browse files Browse the repository at this point in the history
Due to liquid filter was using ngx.ctx instead of the original context,
the value mismatch and a valid content can't be used.

This commit refactor the operations to always use context instead
context.request

Signed-off-by: Eloy Coto <[email protected]>
  • Loading branch information
eloycoto committed Sep 13, 2019
1 parent 367665d commit 605eadd
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions gateway/src/apicast/policy/routing/routing_operation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,45 @@ local function new(evaluate_left_side_func, op, value, value_type)
end

function _M.new_op_with_path(op, value, value_type)
local eval_left_func = function(request) return request:get_uri() end
local eval_left_func = function(context) return context.request:get_uri() end
return new(eval_left_func, op, value, value_type)
end

function _M.new_op_with_header(header_name, op, value, value_type)
local eval_left_func = function(request)
return request:get_header(header_name)
local eval_left_func = function(context)
return context.request:get_header(header_name)
end

return new(eval_left_func, op, value, value_type)
end

function _M.new_op_with_query_arg(query_arg_name, op, value, value_type)
local eval_left_func = function(request)
return request:get_uri_arg(query_arg_name)
local eval_left_func = function(context)
return context.request:get_uri_arg(query_arg_name)
end

return new(eval_left_func, op, value, value_type)
end

function _M.new_op_with_jwt_claim(jwt_claim_name, op, value, value_type)
local eval_left_func = function(request)
local jwt = request:get_validated_jwt()
local eval_left_func = function(context)
local jwt = context.request:get_validated_jwt()
return (jwt and jwt[jwt_claim_name]) or nil
end

return new(eval_left_func, op, value, value_type)
end

function _M.new_op_with_liquid_templating(liquid_expression, op, value, value_type)
local eval_left_func = function()
return TemplateString.new(liquid_expression or "" , "liquid"):render(ngx.ctx)
local eval_left_func = function(context)
return TemplateString.new(liquid_expression or "" , "liquid"):render(context)
end

return new(eval_left_func, op, value, value_type)
end

function _M:evaluate(context)
local left_operand_val = self.evaluate_left_side_func(context.request)
local left_operand_val = self.evaluate_left_side_func(context)

local op = Operation.new(
left_operand_val, 'plain', self.op, self.value, self.value_type
Expand Down

0 comments on commit 605eadd

Please sign in to comment.