-
Notifications
You must be signed in to change notification settings - Fork 170
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
Add 3scale referrer policy #728
Conversation
d1a76dc
to
3d97208
Compare
return self | ||
end | ||
|
||
function _M.rewrite(_, context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to be able to use export
instead of rewrite()
but can't because we need to add to the existing table, not overwrite it.
@@ -0,0 +1,20 @@ | |||
local policy = require('apicast.policy') | |||
local _M = policy.new('3scale Referrer policy') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the 3scale prefix here because this is 3scale specific. Like the 3scale_batcher
policy.
-- Params to send in 3scale backend calls that are not the typical ones | ||
-- (credentials, usage, etc.). | ||
-- This allows us, for example, to send a referrer. | ||
extra_params_backend_authrep = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opted for this because it's way easier than propagating these extra params to all the methods that need them.
I think this makes the code more readable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it is fine. Proxy object mutates internal state anyway, so it is not really ready to be used by multiple clients.
local referrer = ngx.var.http_referer | ||
|
||
if referrer then | ||
context.extra_params_backend_authrep = context.extra_params_backend_authrep or {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to find a better way to handle those. They are basically global variables and it starts becoming really ugly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this policy manipulate the proxy object directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but the proxy object should also be in context
(stored by local_chain.lua
). Do you think that's a better solution?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it already is there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. The proxy is stored in context
in local_chain.lua
(edited my comment at the same time you were writing).
Now that I think about it, I feel like manipulating here the proxy object is a slightly better solution because it avoids the extra step of doing it in the APIcast policy. Instead of doing that, every policy would be responsible for adding the extra backend params it wants. Is that the benefit you were thinking about?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that would reduce the number of objects we store in the context root. And then changing the params basically becomes proxy public API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
|
||
local new = _M.new | ||
|
||
function _M.new(config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't even need to override new, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. This is the first policy we have with an empty configuration, so we don't need to override new
. Didn't realize that 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
04bd58b
to
b60284f
Compare
b60284f
to
35adacd
Compare
@mikz I addressed your comments. Ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Closes #414