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

Add 3scale referrer policy #728

Merged
merged 6 commits into from
May 30, 2018
Merged

Add 3scale referrer policy #728

merged 6 commits into from
May 30, 2018

Conversation

davidor
Copy link
Contributor

@davidor davidor commented May 29, 2018

Closes #414

return self
end

function _M.rewrite(_, context)
Copy link
Contributor Author

@davidor davidor May 29, 2018

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.

@davidor davidor changed the title [WIP] Add 3scale referrer policy Add 3scale referrer policy May 29, 2018
@davidor davidor requested a review from mikz May 29, 2018 15:25
@@ -0,0 +1,20 @@
local policy = require('apicast.policy')
local _M = policy.new('3scale Referrer policy')
Copy link
Contributor Author

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 = {}
Copy link
Contributor Author

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.

Copy link
Contributor

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 {}
Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

@davidor davidor May 29, 2018

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?

Copy link
Contributor

@mikz mikz May 29, 2018

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

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 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@davidor
Copy link
Contributor Author

davidor commented May 30, 2018

@mikz I addressed your comments. Ready for review.

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.

👍

@davidor davidor merged commit 0394efb into master May 30, 2018
@davidor davidor deleted the 3scale-referrer-policy branch May 30, 2018 09:09
@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