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

Headers policy: allow templating using liquid #716

Merged
merged 7 commits into from
May 17, 2018

Conversation

davidor
Copy link
Contributor

@davidor davidor commented May 17, 2018

Closes #708

@davidor davidor force-pushed the liquid-templating-headers-policy branch from 59410f5 to faa2735 Compare May 17, 2018 09:49
@davidor davidor requested a review from mikz May 17, 2018 09:49
-- Expose only ngx.* functions that we think could be useful and that do not
-- have any side-effects.
local liquid_filters = {
ngx_excape_uri = ngx.escape_uri,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm torn on this.

On one hand customer should not care if it is ngx or what. All functions to escape_uri should behave the same.
On the other hand it is the nginx function and in theory we might provide some other in the future.

Also, would be good to add ldoc with links to those functions so we can see it in the documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mikz I had the same doubt while writing this code.

I'm thinking about users configuring this from 3scale's UI. I think that for them it'd be more natural to write something like 'md5' rather than 'ngx_md5'. In theory, they don't even need to know that apicast is based on nginx.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Exactly 👍

-- Can be 'liquid' or 'plain'
-- @treturn a template string
function _M.new(value, type)
return template[type].new(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

This will crash when it gets unknown type. It should handle missing types and return nil, err IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed 👍

Copy link
Contributor

@mikz mikz left a comment

Choose a reason for hiding this comment

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

👍 This is excellent. Really simple and powerful. Good job! 🥇

@mikz
Copy link
Contributor

mikz commented May 17, 2018

@davidor davidor force-pushed the liquid-templating-headers-policy branch from faa2735 to 33e891e Compare May 17, 2018 13:07
@davidor davidor force-pushed the liquid-templating-headers-policy branch 2 times, most recently from 5c68091 to be687f9 Compare May 17, 2018 15:52
@davidor
Copy link
Contributor Author

davidor commented May 17, 2018

@mikz I added an integration test with jwt tokens as you suggested. Check the last 2 commits.
@nmasse-itix : you might be interested in the example. It's based in one of the custom policies of your apicast fork.

@@ -0,0 +1,23 @@
local http_authorization = require 'resty.http_authorization'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mikz after doing this, I wondered whether it would be better to just expose the jwt token in the policies context instead of creating this fixture policy specifically for this. So I went ahead and did that in a separate branch based on this one: https://github.com/3scale/apicast/tree/expose-jwt-tokens-context (4 last commits)
Let's discuss and decide what we want to include in this PR.

Copy link
Contributor Author

@davidor davidor May 17, 2018

Choose a reason for hiding this comment

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

@mikz I'll try to explain this better.

In order to test that the templating introduced in this PR allows setting headers with some jwt information, I needed to create an example policy specifically for testing that. The reason is that none of the current policies expose a decoded jwt in the policies context.

After adding that example policy, I realized that we should probably expose the decoded jwt in the policies context so other policies can use it, for example, the rate-limit one. That's why I created a new branch that does that.

My suggestion is to delete the commits of this branch that implement the example policy and the test (last 2 commits), merge, and then, create a new PR from the new branch I created.

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes total sense 👍
I thought jwt is already exposed. If it is not then we definitely should do it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done 👍
I'll continue working on the other PR tomorrow.

@davidor davidor force-pushed the liquid-templating-headers-policy branch from be687f9 to 6ec4307 Compare May 17, 2018 18:09
@davidor davidor merged commit ef868e5 into master May 17, 2018
@davidor davidor deleted the liquid-templating-headers-policy branch May 17, 2018 18:17
@davidor davidor added this to the 3.3 milestone Jun 1, 2018
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