Skip to content

Conversation

@tkan145
Copy link
Contributor

@tkan145 tkan145 commented Mar 17, 2025

What

Fix https://issues.redhat.com/browse/THREESCALE-11738

Verification steps:

  • Checkout this branch
  • Build new runtime-image
make runtime-image IMAGE_NAME=apicast-test
  • Get into dev-environments
cd plain-http-upstream 
  • Update apicast-config.json
diff --git a/dev-environments/plain-http-upstream/apicast-config.json b/dev-environments/plain-http-upstream/apicast-config.json
index ff944273..147a0d51 100644
--- a/dev-environments/plain-http-upstream/apicast-config.json
+++ b/dev-environments/plain-http-upstream/apicast-config.json
@@ -13,6 +13,38 @@
         "policy_chain": [
           {
             "name": "apicast.policy.apicast"
+          },
+          {
+            "name": "conditional",
+            "version": "builtin",
+            "configuration": {
+              "condition": {
+                "operations": [
+                  {
+                    "left": "{{ uri }}",
+                    "left_type": "liquid",
+                    "op": "==",
+                    "right": "/foo",
+                    "right_type": "plain"
+                  }
+                ]
+              },
+              "policy_chain": [
+                {
+                  "name": "example",
+                  "version": "1.0",
+                  "configuration": {}
+                },
+                {
+                  "name": "on_failed",
+                  "version": "builtin",
+                  "configuration": {
+                    "error_status_code": 419
+                  }
+                }
+              ]
+            },
+            "enabled": true
           }
         ],
         "proxy_rules": [
  • Start APIcast
make gateway IMAGE_NAME=apicast-test
  • Send request
curl --resolve get.example.com:8080:127.0.0.1 -v "http://get.example.com:8080/?user_key=123" 

You should see HTTP/1.1 200 OK

  • Send another request to trigger on_failed policy
curl --resolve get.example.com:8080:127.0.0.1 -v "http://get.example.com:8080/foo?user_key=123" 

419 will be returned this time

…olicy

Previously, we used "load_policy" to load and create a new conditional
chain. However, if one or more policies in the chain failed to load,
it would terminate the entire chain.

With this PR, we will use "add_policy" instead, which will skip the failed
policy and load the next policy in the chain.
@tkan145 tkan145 requested a review from a team as a code owner March 17, 2025 04:20
Copy link
Member

@eguzki eguzki left a comment

Choose a reason for hiding this comment

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

LGTM

Verification steps worked

@tkan145 tkan145 merged commit 47a7d99 into 3scale:master Mar 17, 2025
14 checks passed
@tkan145 tkan145 deleted the THREESCALE-11738-conditional-policy branch March 17, 2025 08:56
@tkan145 tkan145 restored the THREESCALE-11738-conditional-policy branch June 10, 2025 02:32
@tkan145 tkan145 deleted the THREESCALE-11738-conditional-policy branch June 10, 2025 02:37
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