Skip to content

Commit 8810388

Browse files
[Ruleset Engine] Use APIRequest component (#21252)
--------- Co-authored-by: Rebecca Tamachiro <[email protected]>
1 parent bbc8ca7 commit 8810388

19 files changed

+830
-822
lines changed

src/content/docs/ruleset-engine/basic-operations/add-rule-phase-rulesets.mdx

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar:
66
order: 3
77
---
88

9-
import { Details } from "~/components";
9+
import { Details, APIRequest } from "~/components";
1010

1111
A [phase entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) contains an ordered list of rules that run in that phase. A rule in an entry point ruleset can execute a different ruleset. You can have entry point rulesets for each phase at the account level and at the zone level.
1212

@@ -22,30 +22,31 @@ Instead of relying on the automatic creation of an entry point ruleset, you can
2222

2323
The following example sets the rules of a phase entry point ruleset at the zone level for the `http_request_firewall_managed` phase using the [Update a zone entry point ruleset](/api/resources/rulesets/subresources/phases/methods/update/) operation.
2424

25-
```bash
26-
curl --request PUT \
27-
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/phases/http_request_firewall_managed/entrypoint \
28-
--header "Authorization: Bearer <API_TOKEN>" \
29-
--header "Content-Type: application/json" \
30-
--data '{
31-
"rules": [
32-
{
33-
"action": "execute",
34-
"action_parameters": {
35-
"id": "<MANAGED_RULESET_ID_1>"
36-
},
37-
"expression": "true"
38-
},
39-
{
40-
"action": "execute",
41-
"action_parameters": {
42-
"id": "<MANAGED_RULESET_ID_2>"
43-
},
44-
"expression": "true"
45-
}
46-
]
47-
}'
48-
```
25+
<APIRequest
26+
path="/zones/{zone_id}/rulesets/phases/{ruleset_phase}/entrypoint"
27+
method="PUT"
28+
parameters={{
29+
ruleset_phase: "http_request_firewall_managed",
30+
}}
31+
json={{
32+
rules: [
33+
{
34+
action: "execute",
35+
action_parameters: {
36+
id: "<MANAGED_RULESET_ID_1>",
37+
},
38+
expression: "true",
39+
},
40+
{
41+
action: "execute",
42+
action_parameters: {
43+
id: "<MANAGED_RULESET_ID_2>",
44+
},
45+
expression: "true",
46+
},
47+
],
48+
}}
49+
/>
4950

5051
```json output
5152
{
@@ -90,20 +91,19 @@ https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/phases/http_reques
9091

9192
<Details header="Example: Add a single rule to a phase entry point ruleset at the zone level">
9293

93-
The following example adds a single rule to a phase entry point ruleset (with ID `{ruleset_id}`) at the zone level using the [Create a zone ruleset rule](/api/resources/rulesets/subresources/rules/methods/create/) operation.
94+
The following example adds a single rule to a phase entry point ruleset (with ID `$RULESET_ID`) at the zone level using the [Create a zone ruleset rule](/api/resources/rulesets/subresources/rules/methods/create/) operation.
9495

95-
```bash
96-
curl https://api.cloudflare.com/client/v4/zone/{zone_id}/rulesets/{ruleset_id}/rules \
97-
--header "Authorization: Bearer <API_TOKEN>" \
98-
--header "Content-Type: application/json" \
99-
--data '{
100-
"action": "execute",
101-
"action_parameters": {
102-
"id": "<MANAGED_RULESET_ID>"
103-
},
104-
"expression": "true"
105-
}'
106-
```
96+
<APIRequest
97+
path="/zones/{zone_id}/rulesets/{ruleset_id}/rules"
98+
method="POST"
99+
json={{
100+
action: "execute",
101+
action_parameters: {
102+
id: "<MANAGED_RULESET_ID>",
103+
},
104+
expression: "true",
105+
}}
106+
/>
107107

108108
```json output
109109
{

src/content/docs/ruleset-engine/basic-operations/deploy-rulesets.mdx

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ sidebar:
66
order: 4
77
---
88

9-
Use the [Rulesets API](/ruleset-engine/rulesets-api/) to deploy a ruleset. To deploy a ruleset, add a rule with `"action": "execute"` to a phase entry point ruleset, specifying the ruleset ID to execute as an action parameter. Use a separate rule for each ruleset you want to deploy.
9+
import { APIRequest } from "~/components";
10+
11+
Use the [Rulesets API](/ruleset-engine/rulesets-api/) to deploy a ruleset. To deploy a ruleset, add a rule with `"action": "execute"` to a [phase entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset), specifying the ruleset ID to execute as an action parameter. Use a separate rule for each ruleset you want to deploy.
1012

1113
A rule that executes a ruleset consists of:
1214

@@ -22,26 +24,27 @@ To apply a rule to every request in a phase at the **zone** level, set the rule
2224

2325
## Example
2426

25-
The following example deploys a managed ruleset to the `http_request_firewall_managed` phase of a given zone (`{zone_id}`) by adding a rule that executes the managed ruleset.
27+
The following example deploys a managed ruleset to the `http_request_firewall_managed` phase of a given zone (`$ZONE_ID`) by adding a rule that executes the managed ruleset.
2628

27-
```bash
28-
curl --request PUT \
29-
https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/phases/http_request_firewall_managed/entrypoint \
30-
--header "Authorization: Bearer <API_TOKEN>" \
31-
--header "Content-Type: application/json" \
32-
--data '{
33-
"rules": [
34-
{
35-
"action": "execute",
36-
"action_parameters": {
37-
"id": "<CLOUDFLARE_MANAGED_RULESET_ID>"
38-
},
39-
"expression": "true",
40-
"description": "Execute Cloudflare Managed Ruleset on my zone ruleset"
41-
}
42-
]
43-
}'
44-
```
29+
<APIRequest
30+
path="/zones/{zone_id}/rulesets/phases/{ruleset_phase}/entrypoint"
31+
method="PUT"
32+
parameters={{
33+
ruleset_phase: "http_request_firewall_managed",
34+
}}
35+
json={{
36+
rules: [
37+
{
38+
action: "execute",
39+
action_parameters: {
40+
id: "<CLOUDFLARE_MANAGED_RULESET_ID>",
41+
},
42+
expression: "true",
43+
description: "Execute Cloudflare Managed Ruleset on my zone ruleset",
44+
},
45+
],
46+
}}
47+
/>
4548

4649
```json output
4750
{

src/content/docs/ruleset-engine/basic-operations/view-rulesets.mdx

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar:
66
order: 2
77
---
88

9-
import { Details } from "~/components";
9+
import { Details, APIRequest } from "~/components";
1010

1111
## View available rulesets
1212

@@ -20,10 +20,7 @@ The response to the `GET` request will include the following rulesets:
2020
- Zone-level phase entry points, if configured, indicated by `"kind": "zone"`.
2121
- Custom rulesets, if configured, indicated by `"kind": "custom"`.
2222

23-
```bash title="Request"
24-
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets \
25-
--header "Authorization: Bearer <API_TOKEN>"
26-
```
23+
<APIRequest path="/zones/{zone_id}/rulesets" method="GET" />
2724

2825
```json output
2926
{
@@ -72,10 +69,7 @@ The response will include the following rulesets:
7269
- Account-level phase entry points, if configured, indicated by `"kind": "root"`.
7370
- Custom rulesets, if configured, indicated by `"kind": "custom"`.
7471

75-
```bash
76-
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets \
77-
--header "Authorization: Bearer <API_TOKEN>"
78-
```
72+
<APIRequest path="/accounts/{account_id}/rulesets" method="GET" />
7973

8074
```json output
8175
{
@@ -133,10 +127,14 @@ You can view all versions of phase entry points (at the account and zone levels)
133127

134128
The following example lists the rules in version `2` of the `http_request_firewall_managed` phase entry point ruleset at the zone level.
135129

136-
```bash
137-
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/phases/http_request_firewall_managed/entrypoint/versions/2 \
138-
--header "Authorization: Bearer <API_TOKEN>"
139-
```
130+
<APIRequest
131+
path="/zones/{zone_id}/rulesets/phases/{ruleset_phase}/entrypoint/versions/{ruleset_version}"
132+
method="GET"
133+
parameters={{
134+
ruleset_phase: "http_request_firewall_managed",
135+
ruleset_version: "2",
136+
}}
137+
/>
140138

141139
```json output
142140
{
@@ -175,10 +173,14 @@ The following example lists the rules in version `2` of a managed ruleset (the m
175173

176174
Each rule in a managed ruleset can have associated tags or categories, listed in the `categories` field.
177175

178-
```bash
179-
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets/{managed_ruleset_id}/versions/2 \
180-
--header "Authorization: Bearer <API_TOKEN>"
181-
```
176+
<APIRequest
177+
path="/accounts/{account_id}/rulesets/{ruleset_id}/versions/{ruleset_version}"
178+
method="GET"
179+
parameters={{
180+
ruleset_id: "$MANAGED_RULESET_ID",
181+
ruleset_version: "2",
182+
}}
183+
/>
182184

183185
```json output
184186
{

src/content/docs/ruleset-engine/custom-rulesets/add-rules-ruleset.mdx

Lines changed: 41 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ sidebar:
55
order: 3
66
---
77

8+
import { APIRequest } from "~/components";
9+
810
To add rules to an existing custom ruleset, use the [Update an account ruleset](/api/resources/rulesets/methods/update/) operation and pass the rules in an array. Each rule has an expression and an action.
911

1012
:::note[Choosing the appropriate API method]
@@ -20,32 +22,31 @@ You can use other API operations depending on the type of operation:
2022

2123
## Add rules
2224

23-
The following request adds two rules to a custom ruleset. These will be the only two rules in the ruleset.
25+
The following request adds two rules to a custom ruleset with ID `$RULESET_ID`. These will be the only two rules in the ruleset.
2426

2527
The response will include the rule ID of the new rules in the `id` field.
2628

27-
```bash
28-
curl --request PUT \
29-
https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets/{custom_ruleset_id} \
30-
--header "Authorization: Bearer <API_TOKEN>" \
31-
--header "Content-Type: application/json" \
32-
--data '{
33-
"rules": [
34-
{
35-
"expression": "(ip.src.country eq \"GB\" or ip.src.country eq \"FR\") or cf.threat_score > 0",
36-
"action": "challenge",
37-
"description": "challenge GB and FR or based on IP Reputation"
38-
},
39-
{
40-
"expression": "not http.request.uri.path matches \"^/api/.*$\"",
41-
"action": "challenge",
42-
"description": "challenge not /api"
43-
}
44-
]
45-
}'
46-
```
29+
<APIRequest
30+
path="/accounts/{account_id}/rulesets/{ruleset_id}"
31+
method="PUT"
32+
json={{
33+
rules: [
34+
{
35+
expression:
36+
'(ip.src.country eq "GB" or ip.src.country eq "FR") or cf.threat_score > 0',
37+
action: "challenge",
38+
description: "challenge GB and FR or based on IP Reputation",
39+
},
40+
{
41+
expression: 'not http.request.uri.path matches "^/api/.*$"',
42+
action: "challenge",
43+
description: "challenge not /api",
44+
},
45+
],
46+
}}
47+
/>
4748

48-
```json output
49+
```json output {9,19}
4950
{
5051
"result": {
5152
"id": "<CUSTOM_RULESET_ID>",
@@ -87,29 +88,27 @@ https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets/{custom_rule
8788

8889
To update one or more rules in a custom ruleset, use the [Update an account ruleset](/api/resources/rulesets/methods/update/) operation. Include the ID of the rules you want to modify in the rules array and add the fields you wish to update. The request replaces the entire ruleset with a new version. Therefore, you must include the ID of all the rules you wish to keep.
8990

90-
The following request edits one rule in a custom ruleset and updates the execution order of the rules.
91+
The following `PUT` request edits one rule in a custom ruleset and updates the execution order of the rules.
9192

9293
The response will include the modified custom ruleset. Note that the updated rule and ruleset version number increment.
9394

94-
```bash
95-
curl --request PUT \
96-
https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets/{ruleset_id} \
97-
--header "Authorization: Bearer <API_TOKEN>" \
98-
--header "Content-Type: application/json" \
99-
--data '{
100-
"rules": [
101-
{
102-
"id": "<CUSTOM_RULE_ID_2>",
103-
"expression": "not http.request.uri.path matches \"^/api/.*$\"",
104-
"action": "js_challenge",
105-
"description": "js_challenge when not /api"
106-
},
107-
{
108-
"id": "<CUSTOM_RULE_ID_1>"
109-
}
110-
]
111-
}'
112-
```
95+
<APIRequest
96+
path="/accounts/{account_id}/rulesets/{ruleset_id}"
97+
method="PUT"
98+
json={{
99+
rules: [
100+
{
101+
id: "<CUSTOM_RULE_ID_2>",
102+
expression: 'not http.request.uri.path matches "^/api/.*$"',
103+
action: "js_challenge",
104+
description: "js_challenge when not /api",
105+
},
106+
{
107+
id: "<CUSTOM_RULE_ID_1>",
108+
},
109+
],
110+
}}
111+
/>
113112

114113
```json output
115114
{

src/content/docs/ruleset-engine/custom-rulesets/create-custom-ruleset.mdx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ sidebar:
55
order: 2
66
---
77

8+
import { APIRequest } from "~/components";
9+
810
Use the [Create an account ruleset](/api/resources/rulesets/methods/create/) operation to create a custom ruleset, making sure that you:
911

1012
- Set the `kind` field to `custom`.
@@ -14,19 +16,18 @@ Use the [Create an account ruleset](/api/resources/rulesets/methods/create/) ope
1416

1517
The following request creates a new custom ruleset. The response will include the ID of the new custom ruleset in the `id` field.
1618

17-
```bash
18-
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets \
19-
--header "Authorization: Bearer <API_TOKEN>" \
20-
--header "Content-Type: application/json" \
21-
--data '{
22-
"name": "Custom Ruleset 1",
23-
"description": "My First Custom Ruleset",
24-
"kind": "custom",
25-
"phase": "http_request_firewall_custom"
26-
}'
27-
```
19+
<APIRequest
20+
path="/accounts/{account_id}/rulesets"
21+
method="POST"
22+
json={{
23+
name: "Custom Ruleset 1",
24+
description: "My First Custom Ruleset",
25+
kind: "custom",
26+
phase: "http_request_firewall_custom",
27+
}}
28+
/>
2829

29-
```json output
30+
```json output {3}
3031
{
3132
"result": {
3233
"id": "f82ccda3d21f4a02825d3fe45b5e1c10",

0 commit comments

Comments
 (0)