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

feat: Support logical operators for route expressions #2261

Open
huhamhire opened this issue Jul 10, 2024 · 2 comments
Open

feat: Support logical operators for route expressions #2261

huhamhire opened this issue Jul 10, 2024 · 2 comments

Comments

@huhamhire
Copy link

Description

APISIX supports logical operators to combine multiple expressions.

e.g.

[
    "AND",
    ["arg_version", "==", "v2"],
    [
        "OR",
        ["arg_action", "==", "signup"],
        ["arg_action", "==", "subscribe"]
    ]
]

https://docs.api7.ai/apisix/reference/apisix-expressions#logical-operators

However, the ApisixRoute CRD only supports selecting route when "one of the expression is matched".

There is no clue about how to use logical operators by declarative ways. Neither from the document, nor from source code.

@kayx23 kayx23 added the documentation Improvements or additions to documentation label Aug 23, 2024
@kayx23
Copy link
Member

kayx23 commented Aug 23, 2024

This seems to translate to an AND:

apiVersion: apisix.apache.org/v2
kind: ApisixRoute
metadata:
  name: httpbin-route
spec:
  http:
    - name: httpbin-route
      match:
        paths:
          - /anything
        methods:
          - GET
        exprs:
        - subject:
            scope: Header
            name: X-Foo
          op: Equal
          value: bar
        - subject:
            scope: Header
            name: X-Foo-1
          op: Equal
          value: bar1
      backends:
        - serviceName: httpbin
          servicePort: 80
image
"vars": [
  ["http_x_foo","==","bar"],
  ["http_x_foo_1","==","bar1"]
]

But not sure how to make it an OR; or create a more complex composite logic. I checked the test cases and don't see anything relevant.

@kayx23 kayx23 removed the documentation Improvements or additions to documentation label Aug 23, 2024
@huhamhire
Copy link
Author

huhamhire commented Aug 23, 2024

From what I've learned from lua-resty-expr, which is used by lua-resty-expr. The default operator for combining multiple expressions is AND, which is not how it says from the document.

https://github.com/api7/lua-resty-expr/blob/e91910500cfda40a7c976b832d59df5efab970c5/lib/resty/expr/v1.lua#L244

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

No branches or pull requests

2 participants