Skip to content

Commit 925e981

Browse files
committed
Move API examples to partials and reuse them
1 parent 54c5ce5 commit 925e981

File tree

5 files changed

+250
-218
lines changed

5 files changed

+250
-218
lines changed

src/content/docs/ruleset-engine/managed-rulesets/deploy-managed-ruleset.mdx

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

8-
import { RuleID } from "~/components";
8+
import { RuleID, Render } from "~/components";
99

1010
You can deploy a managed ruleset at the zone level or at the account level.
1111

@@ -22,111 +22,7 @@ Use the following workflow to deploy a managed ruleset to a phase at the zone le
2222

2323
### Example
2424

25-
The following example deploys a WAF managed ruleset to the `http_request_firewall_managed` phase of a given zone (`{zone_id}`).
26-
27-
1. Search for an existing [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) for the `http_request_firewall_managed` phase using the [List zone rulesets](/api/operations/listZoneRulesets) operation and take note of the ruleset ID. This ruleset, if it exists, has the following properties: `"kind": "zone"` and `"phase": "http_request_firewall_managed"`.
28-
29-
```bash
30-
curl "https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets" \
31-
--header "Authorization: Bearer <API_TOKEN>"
32-
```
33-
34-
```json output {5,9,12}
35-
{
36-
"result": [
37-
// ...
38-
{
39-
"id": "<RULESET_ID>",
40-
"name": "default",
41-
"description": "",
42-
"source": "firewall_managed",
43-
"kind": "zone",
44-
"version": "5",
45-
"last_updated": "2024-07-22T16:04:19.788697Z",
46-
"phase": "http_request_firewall_managed"
47-
}
48-
// ...
49-
],
50-
"success": true,
51-
"errors": [],
52-
"messages": []
53-
}
54-
```
55-
56-
2. If the entry point ruleset does not exist (the previous command returned a `404 Not Found` status code), create it using the [Create a zone ruleset](/api/operations/createZoneRuleset) operation. Include a single rule in the `rules` array that executes the [Cloudflare Managed Ruleset](/waf/managed-rules/reference/cloudflare-managed-ruleset/) (with ID <RuleID id="efb7b8c949ac4650a09736fc376e9aee" />) for all incoming requests in the zone.
57-
58-
```bash
59-
curl "https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets" \
60-
--header "Authorization: Bearer <API_TOKEN>" \
61-
--header "Content-Type: application/json" \
62-
--data '{
63-
"name": "My ruleset",
64-
"description": "Entry point ruleset for WAF managed rulesets",
65-
"kind": "zone",
66-
"phase": "http_request_firewall_managed",
67-
"rules": [
68-
{
69-
"action": "execute",
70-
"action_parameters": {
71-
"id": "efb7b8c949ac4650a09736fc376e9aee"
72-
},
73-
"expression": "true",
74-
"description": "Execute the Cloudflare Managed Ruleset"
75-
}
76-
]
77-
}'
78-
```
79-
80-
If the entry point ruleset already exists, add a rule to this ruleset (with ID `{ruleset_id}`) using the [Create a zone ruleset rule](/api/operations/createZoneRulesetRule) operation. This rule executes the Cloudflare Managed Ruleset (with ID <RuleID id="efb7b8c949ac4650a09736fc376e9aee" />) for all incoming requests in the zone.
81-
82-
```bash
83-
curl --request PUT \
84-
"https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/{ruleset_id}/rules" \
85-
--header "Authorization: Bearer <API_TOKEN>" \
86-
--header "Content-Type: application/json" \
87-
--data '{
88-
"action": "execute",
89-
"action_parameters": {
90-
"id": "efb7b8c949ac4650a09736fc376e9aee"
91-
},
92-
"expression": "true",
93-
"description": "Execute the Cloudflare Managed Ruleset"
94-
}'
95-
```
96-
97-
```json output
98-
{
99-
"result": {
100-
"id": "<RULESET_ID>",
101-
"name": "Zone-level phase entry point",
102-
"description": "",
103-
"kind": "zone",
104-
"version": "3",
105-
"rules": [
106-
// ... any existing rules
107-
{
108-
"id": "<RULE_ID>",
109-
"version": "1",
110-
"action": "execute",
111-
"action_parameters": {
112-
"id": "efb7b8c949ac4650a09736fc376e9aee",
113-
"version": "latest"
114-
},
115-
"expression": "true",
116-
"description": "Execute the Cloudflare Managed Ruleset",
117-
"last_updated": "2024-03-18T18:08:14.003361Z",
118-
"ref": "<RULE_REF>",
119-
"enabled": true
120-
}
121-
],
122-
"last_updated": "2024-03-18T18:08:14.003361Z",
123-
"phase": "http_request_firewall_managed"
124-
},
125-
"success": true,
126-
"errors": [],
127-
"messages": []
128-
}
129-
```
25+
<Render file="api-managed-rules-zone-example" product="waf" />
13026

13127
In this example, the managed ruleset executes the behavior configured by Cloudflare. To customize the behavior of managed rulesets, refer to [Override a managed ruleset](/ruleset-engine/managed-rulesets/override-managed-ruleset/).
13228

@@ -141,115 +37,6 @@ Use the following workflow to deploy a managed ruleset to a phase at the account
14137

14238
### Example
14339

144-
The following example deploys a WAF managed ruleset to the `http_request_firewall_managed` phase of a given account (`{account_id}`) by creating a rule that executes the managed ruleset. The rules in the managed ruleset are executed when the zone name matches one of `example.com` or `anotherexample.com`.
145-
146-
1. Search for an existing [entry point ruleset](/ruleset-engine/about/rulesets/#entry-point-ruleset) for the `http_request_firewall_managed` phase using the [List account rulesets](/api/operations/listAccountRulesets) operation and take note of the ruleset ID. This ruleset, if it exists, has the following properties: `"kind": "root"` and `"phase": "http_request_firewall_managed"`.
147-
148-
```bash
149-
curl "https://api.cloudflare.com/client/v4/account/{account_id}/rulesets" \
150-
--header "Authorization: Bearer <API_TOKEN>"
151-
```
152-
153-
```json output {5,9,12}
154-
{
155-
"result": [
156-
// ...
157-
{
158-
"id": "<RULESET_ID>",
159-
"name": "default",
160-
"description": "",
161-
"source": "firewall_managed",
162-
"kind": "root",
163-
"version": "5",
164-
"last_updated": "2024-07-22T16:04:19.788697Z",
165-
"phase": "http_request_firewall_managed"
166-
}
167-
// ...
168-
],
169-
"success": true,
170-
"errors": [],
171-
"messages": []
172-
}
173-
```
174-
175-
2. If the entry point ruleset does not exist (the previous command returned a `404 Not Found` status code), create it using the [Create an account ruleset](/api/operations/createAccountRuleset) operation. Include a single rule in the `rules` array that executes the [Cloudflare Managed Ruleset](/waf/managed-rules/reference/cloudflare-managed-ruleset/) (with ID <RuleID id="efb7b8c949ac4650a09736fc376e9aee" />) for all incoming requests where the zone name matches one of `example.com` or `anotherexample.com`.
176-
177-
```bash
178-
curl --request PUT \
179-
"https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets" \
180-
--header "Authorization: Bearer <API_TOKEN>" \
181-
--header "Content-Type: application/json" \
182-
--data '{
183-
"name": "My ruleset",
184-
"description": "Entry point ruleset for WAF managed rulesets",
185-
"kind": "root",
186-
"phase": "http_request_firewall_managed",
187-
"rules": [
188-
{
189-
"action": "execute",
190-
"action_parameters": {
191-
"id": "efb7b8c949ac4650a09736fc376e9aee"
192-
},
193-
"expression": "(cf.zone.name in {\"example.com\" \"anotherexample.com\"}) and cf.zone.plan eq \"ENT\"",
194-
"description": "Execute Cloudflare Managed Ruleset"
195-
}
196-
]
197-
}'
198-
```
199-
200-
If the entry point ruleset already exists, add a rule to this ruleset (with ID `{ruleset_id}`) using the [Create an account ruleset rule](/api/operations/createAccountRulesetRule) operation. This rule executes the Cloudflare Managed Ruleset (with ID <RuleID id="efb7b8c949ac4650a09736fc376e9aee" />) for all incoming requests where the zone name matches one of `example.com` or `anotherexample.com`.
201-
202-
```bash
203-
curl --request PUT \
204-
"https://api.cloudflare.com/client/v4/accounts/{account_id}/rulesets/{ruleset_id}/rules" \
205-
--header "Authorization: Bearer <API_TOKEN>" \
206-
--header "Content-Type: application/json" \
207-
--data '{
208-
"action": "execute",
209-
"action_parameters": {
210-
"id": "efb7b8c949ac4650a09736fc376e9aee"
211-
},
212-
"expression": "true",
213-
"description": "Execute the Cloudflare Managed Ruleset"
214-
}'
215-
```
216-
217-
```json output
218-
{
219-
"result": {
220-
"id": "<RULESET_ID>",
221-
"name": "Account-level phase entry point",
222-
"description": "",
223-
"kind": "root",
224-
"version": "3",
225-
"rules": [
226-
// ... any existing rules
227-
{
228-
"id": "<RULE_ID>",
229-
"version": "1",
230-
"action": "execute",
231-
"action_parameters": {
232-
"id": "efb7b8c949ac4650a09736fc376e9aee",
233-
"version": "latest"
234-
},
235-
"expression": "(cf.zone.name in {\"example.com\" \"anotherexample.com\"}) and cf.zone.plan eq \"ENT\"",
236-
"description": "Execute Cloudflare Managed Ruleset",
237-
"last_updated": "2024-03-18T18:30:08.122758Z",
238-
"ref": "<RULE_REF>",
239-
"enabled": true
240-
}
241-
],
242-
"last_updated": "2024-03-18T18:30:08.122758Z",
243-
"phase": "http_request_firewall_managed"
244-
},
245-
"success": true,
246-
"errors": [],
247-
"messages": []
248-
}
249-
```
250-
251-
:::caution
252-
Managed rulesets deployed at the account level will only apply to incoming traffic of zones on an Enterprise plan. The expression of your `execute` rule must end with `and cf.zone.plan eq "ENT"` or else the API operation will fail.
253-
:::
40+
<Render file="api-managed-rules-account-example" product="waf" />
25441

25542
In this example, the managed ruleset executes the behavior configured by Cloudflare. To customize the behavior of managed rulesets, refer to [Override a managed ruleset](/ruleset-engine/managed-rulesets/override-managed-ruleset/).

src/content/docs/waf/account/managed-rulesets/deploy-api.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ head:
99
content: Deploy a WAF managed ruleset via API for an account
1010
---
1111

12+
import { Render } from "~/components";
13+
1214
:::note
1315
This feature requires an Enterprise plan with a paid add-on.
1416
:::
@@ -17,7 +19,9 @@ Use the [Rulesets API](/ruleset-engine/rulesets-api/) to deploy a WAF managed ru
1719

1820
The [WAF Managed Rules](/waf/managed-rules/#managed-rulesets) page includes the IDs of the different WAF managed rulesets. You will need this information when deploying rulesets via API.
1921

20-
Refer to [Deploy a managed ruleset](/ruleset-engine/managed-rulesets/deploy-managed-ruleset/#deploy-a-managed-ruleset-to-a-phase-at-the-account-level) for instructions on deploying a managed ruleset via API.
22+
## Example
23+
24+
<Render file="api-managed-rules-account-example" />
2125

2226
## Next steps
2327

@@ -26,3 +30,7 @@ To customize the behavior of the rules included in a managed ruleset, [create an
2630
To skip the execution of WAF managed rulesets or some of their rules, [create an exception](/waf/managed-rules/waf-exceptions/define-api/) (also called a skip rule).
2731

2832
Exceptions have priority over overrides.
33+
34+
## More resources
35+
36+
For more information on working with managed rulesets via API, refer to [Work with managed rulesets](/ruleset-engine/managed-rulesets/) in the Ruleset Engine documentation.

src/content/docs/waf/managed-rules/deploy-api.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,19 @@ head:
99
content: Deploy a WAF managed ruleset via API for a zone
1010
---
1111

12+
import { Render } from "~/components";
13+
1214
Use the [Rulesets API](/ruleset-engine/rulesets-api/) to deploy a managed ruleset at the account level or at the zone level.
1315

1416
Deploy WAF managed rulesets to the `http_request_firewall_managed` phase. Other managed rulesets, like DDoS Attack Protection managed rulesets, must be deployed to a different phase. Refer to the specific managed ruleset documentation for details.
1517

1618
The [WAF Managed Rules](/waf/managed-rules/#managed-rulesets) page includes the IDs of the different WAF managed rulesets. You will need this information when deploying the rulesets via API.
1719

18-
Refer to [Deploy a managed ruleset](/ruleset-engine/managed-rulesets/deploy-managed-ruleset/) for instructions on deploying a managed ruleset via API.
20+
## Example
21+
22+
<Render file="api-managed-rules-zone-example" />
23+
24+
Refer to [Deploy a managed ruleset](/ruleset-engine/managed-rulesets/deploy-managed-ruleset/) for additional information on deploying a managed ruleset via API.
1925

2026
## Next steps
2127

@@ -24,3 +30,7 @@ To customize the behavior of the rules included in a managed ruleset, [create an
2430
To skip the execution of WAF managed rulesets or some of their rules, [create an exception](/waf/managed-rules/waf-exceptions/define-api/) (also called a skip rule).
2531

2632
Exceptions have priority over overrides.
33+
34+
## More resources
35+
36+
For more information on working with managed rulesets via API, refer to [Work with managed rulesets](/ruleset-engine/managed-rulesets/) in the Ruleset Engine documentation.

0 commit comments

Comments
 (0)