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

request help: support get the key from function in limit-* plugins #5634

Closed
starsz opened this issue Nov 29, 2021 · 4 comments · Fixed by #5941
Closed

request help: support get the key from function in limit-* plugins #5634

starsz opened this issue Nov 29, 2021 · 4 comments · Fixed by #5941
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@starsz
Copy link
Contributor

starsz commented Nov 29, 2021

Issue description

Hi,
Now, I see we had support var, var_combination in apisix limit-* plugins yet.
I think we can support a type like function so that we can write some logic as a function in the key.
Then we can get the key from the function.

Environment

  • apisix version (cmd: apisix version): 2.10.2
  • OS (cmd: uname -a):
  • OpenResty / Nginx version (cmd: nginx -V or openresty -V):
  • etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API):
  • apisix-dashboard version, if have:
  • the plugin runner version, if the issue is about a plugin runner (cmd: depended on the kind of runner):
  • luarocks version, if the issue is about installation (cmd: luarocks --version):
@spacewander
Copy link
Member

What about allowing user to register their var in

__index = function(t, key)
?

@starsz
Copy link
Contributor Author

starsz commented Nov 30, 2021

What about allowing user to register their var in

__index = function(t, key)

?

I think support function would be more flexible.
We can write the function like this:

function generate_key(ctx)
  if ctx.var.http_x_consumer == "a" then
       return "a"
  end

  return "default"
end

Then we can limit the specific request with a special header.

@spacewander
Copy link
Member

We can register the variable with a custom function, like:

core.ctx.register_var("my_consumer", function (...)
end)

@starsz
Copy link
Contributor Author

starsz commented Dec 1, 2021

We can register the variable with a custom function, like:

core.ctx.register_var("my_consumer", function (...)
end)

Oh, that's good. Wait for the new feature.

@spacewander spacewander added enhancement New feature or request good first issue Good for newcomers labels Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants