Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Liquid: Available context move to readwrite linked list. #1107

Merged
merged 1 commit into from
Aug 23, 2019

Conversation

eloycoto
Copy link
Contributor

@eloycoto eloycoto commented Aug 9, 2019

This commit allows users to use capture in their liquid expressions and
assign variables if they needed.

Due to the available_context return a readonly list, capture function
cannot assign the variable and things start to mess up[0]. Due to allow
users to define variables in liquid is quite bad, a new read-write
linked list is created with an empty table to allow write to a temporal
table.

[0] Exception:

2019/08/09 13:51:23 [error] 15620#15620: *9 lua entry thread aborted: runtime error: /home/centos/gateway/src/apicast/linked_list.lua:19: readonly list
stack traceback:
coroutine 0:
        [C]: in function 'error'
        /home/centos/gateway/src/apicast/linked_list.lua:19: in function '__newindex'
        ./lua_modules/share/lua/5.1/liquid.lua:2512: in function 'define_var'
        ./lua_modules/share/lua/5.1/liquid.lua:2459: in function 'visit'
        ./lua_modules/share/lua/5.1/liquid.lua:1975: in function 'render'
        /home/centos/gateway/src/apicast/policy/headers/headers.lua:91: in function 'run_commands'
        /home/centos/gateway/src/apicast/policy/headers/headers.lua:151: in function </home/centos/gateway/src/apicast/policy/headers/headers.lua:147>
        /home/centos/gateway/src/apicast/policy_chain.lua:200: in function 'rewrite'
        ...s/gateway/src/apicast/policy/local_chain/local_chain.lua:59: in function <...s/gateway/src/apicast/policy/local_chain/local_chain.lua:54>
        /home/centos/gateway/src/apicast/policy_chain.lua:200: in function 'rewrite'
        rewrite_by_lua(lua_Iy6Gdl:498):3: in main chunk, client: 172.18.0.1, server: _, request: "GET /bridge-1/?user_key=132 HTTP/1.1", host: "one"

Fix THREESCALE-1911

Signed-off-by: Eloy Coto eloy.coto@gmail.com

@eloycoto eloycoto requested a review from a team as a code owner August 9, 2019 14:31
{
"op": "set",
"header": "New-Header-1",
"value": "{% capture foo%}bar{% endcapture%}{{foo}}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we limit the number of allocations using the liquid lib? Otherwise, this might not be safe.
Ref:

-- Set resource limits to avoid loops

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -17,7 +17,8 @@ local function context_values()
end

function _M.available_context(policies_context)
return LinkedList.readonly(context_values(), policies_context)
return LinkedList.readwrite({}, LinkedList.readonly(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make it read-write in the LiquidTemplateString:render function instead?
That way other callers of this function will get a read-only list which I think is less surprising.

This commit allows users to use capture in their liquid expressions and
assign variables if they needed.

Due to the available_context return a readonly list, capture function
cannot assign the variable and things start to mess up[0]. Due to allow
users to define variables in liquid is quite bad, a new read-write
linked list is created with an empty table to allow write to a temporal
table.

[0] Exception:
```
2019/08/09 13:51:23 [error] 15620#15620: *9 lua entry thread aborted: runtime error: /home/centos/gateway/src/apicast/linked_list.lua:19: readonly list
stack traceback:
coroutine 0:
        [C]: in function 'error'
        /home/centos/gateway/src/apicast/linked_list.lua:19: in function '__newindex'
        ./lua_modules/share/lua/5.1/liquid.lua:2512: in function 'define_var'
        ./lua_modules/share/lua/5.1/liquid.lua:2459: in function 'visit'
        ./lua_modules/share/lua/5.1/liquid.lua:1975: in function 'render'
        /home/centos/gateway/src/apicast/policy/headers/headers.lua:91: in function 'run_commands'
        /home/centos/gateway/src/apicast/policy/headers/headers.lua:151: in function </home/centos/gateway/src/apicast/policy/headers/headers.lua:147>
        /home/centos/gateway/src/apicast/policy_chain.lua:200: in function 'rewrite'
        ...s/gateway/src/apicast/policy/local_chain/local_chain.lua:59: in function <...s/gateway/src/apicast/policy/local_chain/local_chain.lua:54>
        /home/centos/gateway/src/apicast/policy_chain.lua:200: in function 'rewrite'
        rewrite_by_lua(lua_Iy6Gdl:498):3: in main chunk, client: 172.18.0.1, server: _, request: "GET /bridge-1/?user_key=132 HTTP/1.1", host: "one"

```

Fix THREESCALE-1911

Signed-off-by: Eloy Coto <eloy.coto@gmail.com>
@davidor davidor merged commit 24761b4 into 3scale:master Aug 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants