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

Closed
huhamhire opened this issue Jul 10, 2024 · 4 comments
Closed

feat: Support logical operators for route expressions #2261

huhamhire opened this issue Jul 10, 2024 · 4 comments
Labels

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

Copy link

This issue has been marked as stale due to 90 days of inactivity. It will be closed in 30 days if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the [email protected] list. Thank you for your contributions.

@github-actions github-actions bot added the stale label Nov 22, 2024
Copy link

This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants