Skip to content

Commit 5dca0a8

Browse files
authored
[WAF] Use APIRequest component in API examples (#21216)
1 parent 13434ae commit 5dca0a8

File tree

19 files changed

+845
-892
lines changed

19 files changed

+845
-892
lines changed

src/content/docs/waf/account/custom-rulesets/create-api.mdx

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ head:
99
content: Create a WAF custom ruleset using the API
1010
---
1111

12-
import { Render } from "~/components";
12+
import { Render, APIRequest } from "~/components";
1313

1414
:::note
1515
This feature requires an Enterprise plan with a paid add-on.
@@ -30,24 +30,23 @@ Currently, you can only deploy WAF custom rulesets at the account level.
3030

3131
The following example creates a custom ruleset with a single rule in the `rules` array.
3232

33-
```bash
34-
curl "https://api.cloudflare.com/api/v4/accounts/{account_id}/rulesets" \
35-
--header "Authorization: Bearer <API_TOKEN>" \
36-
--header "Content-Type: application/json" \
37-
--data '{
38-
"description": "",
39-
"kind": "custom",
40-
"name": "My custom ruleset",
41-
"rules": [
42-
{
43-
"description": "Challenge web traffic (not /api)",
44-
"expression": "not starts_with(http.request.uri.path, \"/api/\")",
45-
"action": "managed_challenge"
46-
}
47-
],
48-
"phase": "http_request_firewall_custom"
49-
}'
50-
```
33+
<APIRequest
34+
path="/accounts/{account_id}/rulesets"
35+
method="POST"
36+
json={{
37+
description: "",
38+
kind: "custom",
39+
name: "My custom ruleset",
40+
rules: [
41+
{
42+
description: "Challenge web traffic (not /api)",
43+
expression: 'not starts_with(http.request.uri.path, "/api/")',
44+
action: "managed_challenge",
45+
},
46+
],
47+
phase: "http_request_firewall_custom",
48+
}}
49+
/>
5150

5251
Save the ruleset ID in the response for the next step.
5352

@@ -60,10 +59,13 @@ To deploy the custom ruleset, add a rule with `"action": "execute"` to the `http
6059
params={{ phaseName: "http_request_firewall_custom" }}
6160
/>
6261

63-
```bash
64-
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets/phases/http_request_firewall_custom/entrypoint" \
65-
--header "Authorization: Bearer <API_TOKEN>"
66-
```
62+
<APIRequest
63+
path="/accounts/{account_id}/rulesets/phases/{ruleset_phase}/entrypoint"
64+
method="GET"
65+
parameters={{
66+
ruleset_phase: "http_request_firewall_custom",
67+
}}
68+
/>
6769

6870
```json output {4}
6971
{
@@ -94,20 +96,19 @@ To deploy the custom ruleset, add a rule with `"action": "execute"` to the `http
9496

9597
The following request creates a rule that executes the custom ruleset with ID `<CUSTOM_RULESET_ID>` for all Enterprise zones in the account:
9698

97-
```bash
98-
curl "https://dash.cloudflare.com/api/v4/accounts/{account_id}/rulesets/{ruleset_id}/rules" \
99-
--header "Authorization: Bearer <API_TOKEN>" \
100-
--header "Content-Type: application/json" \
101-
--data '{
102-
"description": "Execute custom ruleset",
103-
"expression": "(cf.zone.plan eq \"ENT\")",
104-
"action": "execute",
105-
"action_parameters": {
106-
"id": "<CUSTOM_RULESET_ID>"
107-
},
108-
"enabled": true
109-
}'
110-
```
99+
<APIRequest
100+
path="/accounts/{account_id}/rulesets/{ruleset_id}/rules"
101+
method="POST"
102+
json={{
103+
description: "Execute custom ruleset",
104+
expression: '(cf.zone.plan eq "ENT")',
105+
action: "execute",
106+
action_parameters: {
107+
id: "<CUSTOM_RULESET_ID>",
108+
},
109+
enabled: true,
110+
}}
111+
/>
111112

112113
:::caution
113114
You can only apply custom rulesets to incoming traffic of zones on an Enterprise plan. To enforce this requirement, you must include `cf.zone.plan eq "ENT"` in the expression of the `execute` rule deploying the custom ruleset.
@@ -121,26 +122,25 @@ To deploy the custom ruleset, add a rule with `"action": "execute"` to the `http
121122
}}
122123
/>
123124

124-
```bash
125-
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets" \
126-
--header "Authorization: Bearer <API_TOKEN>" \
127-
--header "Content-Type: application/json" \
128-
--data '{
129-
"description": "",
130-
"kind": "root",
131-
"name": "Account-level phase entry point",
132-
"rules": [
133-
{
134-
"action": "execute",
135-
"expression": "(cf.zone.plan eq \"ENT\")",
136-
"action_parameters": {
137-
"id": "<CUSTOM_RULESET_ID>"
138-
}
139-
}
140-
],
141-
"phase": "http_request_firewall_custom"
142-
}'
143-
```
125+
<APIRequest
126+
path="/accounts/{account_id}/rulesets"
127+
method="POST"
128+
json={{
129+
description: "",
130+
kind: "root",
131+
name: "Account-level phase entry point",
132+
rules: [
133+
{
134+
action: "execute",
135+
expression: '(cf.zone.plan eq "ENT")',
136+
action_parameters: {
137+
id: "<CUSTOM_RULESET_ID>",
138+
},
139+
},
140+
],
141+
phase: "http_request_firewall_custom",
142+
}}
143+
/>
144144

145145
## Next steps
146146

src/content/docs/waf/account/managed-rulesets/index.mdx

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ sidebar:
55
order: 4
66
---
77

8-
import { Render, Tabs, TabItem, Details } from "~/components";
8+
import { Render, Tabs, TabItem, Details, APIRequest } from "~/components";
99

1010
:::note
1111
This feature requires an Enterprise plan with a paid add-on.
@@ -52,57 +52,57 @@ Once you finish your configuration, the **Deployed managed rulesets** list will
5252

5353
The following `POST` request for the [Create an account ruleset](/api/resources/rulesets/methods/create/) operation creates an [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) for the `http_request_firewall_managed` phase at the account level. The ruleset includes two rules deploying the Cloudflare OWASP Core Ruleset twice with different configurations.
5454

55-
```bash
56-
curl "https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets" \
57-
--header "Authorization: Bearer <API_TOKEN>" \
58-
--header "Content-Type: application/json" \
59-
--data '{
60-
"name": "My ruleset",
61-
"description": "Entry point ruleset for WAF managed rulesets (account)",
62-
"kind": "root",
63-
"phase": "http_request_firewall_managed",
64-
"rules": [
65-
{
66-
"action": "execute",
67-
"action_parameters": {
68-
"id": "4814384a9e5d4991b9815dcfc25d2f1f",
69-
"overrides": {
70-
"categories": [
71-
{
72-
"category": "paranoia-level-4",
73-
"enabled": false
74-
}
75-
],
76-
"rules": [
77-
{
78-
"id": "6179ae15870a4bb7b2d480d4843b323c",
79-
"action": "managed_challenge"
80-
}
81-
]
82-
}
83-
},
84-
"expression": "cf.zone.plan eq \"ENT\"",
85-
"description": "Execute OWASP ruleset at PL3 with Managed Challenge action"
86-
},
87-
{
88-
"action": "execute",
89-
"action_parameters": {
90-
"id": "4814384a9e5d4991b9815dcfc25d2f1f",
91-
"overrides": {
92-
"rules": [
93-
{
94-
"id": "6179ae15870a4bb7b2d480d4843b323c",
95-
"action": "log"
96-
}
97-
]
98-
}
99-
},
100-
"expression": "cf.zone.plan eq \"ENT\"",
101-
"description": "Execute OWASP ruleset at PL4 with Log action"
102-
}
103-
]
104-
}'
105-
```
55+
<APIRequest
56+
path="/accounts/{account_id}/rulesets"
57+
method="POST"
58+
json={{
59+
name: "My ruleset",
60+
description: "Entry point ruleset for WAF managed rulesets (account)",
61+
kind: "root",
62+
phase: "http_request_firewall_managed",
63+
rules: [
64+
{
65+
action: "execute",
66+
action_parameters: {
67+
id: "4814384a9e5d4991b9815dcfc25d2f1f",
68+
overrides: {
69+
categories: [
70+
{
71+
category: "paranoia-level-4",
72+
enabled: false,
73+
},
74+
],
75+
rules: [
76+
{
77+
id: "6179ae15870a4bb7b2d480d4843b323c",
78+
action: "managed_challenge",
79+
},
80+
],
81+
},
82+
},
83+
expression: 'cf.zone.plan eq "ENT"',
84+
description:
85+
"Execute OWASP ruleset at PL3 with Managed Challenge action",
86+
},
87+
{
88+
action: "execute",
89+
action_parameters: {
90+
id: "4814384a9e5d4991b9815dcfc25d2f1f",
91+
overrides: {
92+
rules: [
93+
{
94+
id: "6179ae15870a4bb7b2d480d4843b323c",
95+
action: "log",
96+
},
97+
],
98+
},
99+
},
100+
expression: 'cf.zone.plan eq "ENT"',
101+
description: "Execute OWASP ruleset at PL4 with Log action",
102+
},
103+
],
104+
}}
105+
/>
106106

107107
</TabItem> </Tabs>
108108

0 commit comments

Comments
 (0)