Skip to content

Commit 7880cb3

Browse files
[CF4SaaS] Use APIRequest component (#22410)
* First pass search for bash blocks and import APIRequest * Add placeholder component syntax * Remove component for missing csrs endpoint * Remove unused APIRequest component from uploading-certificates * Fill in APIRequest throughout * Fix breaking issues * Remove original bash code blocks
1 parent bc52df5 commit 7880cb3

File tree

4 files changed

+106
-108
lines changed

4 files changed

+106
-108
lines changed

src/content/docs/cloudflare-for-platforms/cloudflare-for-saas/domain-support/custom-metadata.mdx

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ head: []
77
description: Configure per-hostname settings such as URL rewriting and custom headers.
88
---
99

10-
import { Render } from "~/components";
10+
import { Render, APIRequest } from "~/components";
1111

1212
You may wish to configure per-hostname (customer) settings beyond the scale of Page Rules or Rate Limiting, which have a maximum of 125 rules each.
1313

@@ -32,26 +32,24 @@ Please speak with your Solutions Engineer to discuss additional logic and requir
3232

3333
You may add custom metadata to Cloudflare via the Custom Hostnames API. This data can be added via a [`PATCH` request](/api/resources/custom_hostnames/methods/edit/) to the specific hostname ID to set metadata for that hostname, for example:
3434

35-
```bash
36-
curl --request PATCH \
37-
"https://api.cloudflare.com/client/v4/zones/{zone_id}/custom_hostnames/{hostname_id}" \
38-
--header "X-Auth-Email: <EMAIL>" \
39-
--header "X-Auth-Key: <API_KEY>" \
40-
--header "Content-Type: application/json" \
41-
--data '{
42-
"ssl": {
35+
36+
<APIRequest
37+
path="/zones/{zone_id}/custom_hostnames/{custom_hostname_id}"
38+
method="PATCH"
39+
json={{
40+
"ssl": {
4341
"method": "http",
4442
"type": "dv"
4543
},
4644
"custom_metadata": {
4745
"customer_id": "12345",
4846
"redirect_to_https": true,
4947
"security_tag": "low"
50-
}
51-
}'
52-
```
48+
},
49+
}}
50+
/>
5351

54-
Changes to metadata will propagate across Cloudflares edge within 30 seconds.
52+
Changes to metadata will propagate across Cloudflare's edge within 30 seconds.
5553

5654
---
5755

@@ -103,7 +101,7 @@ lookup_json_string(cf.hostname.metadata, "security_tag") eq "low"
103101
- Define fallback behaviour in the non-presence of metadata
104102
- Define fallback behaviour if a key or value in the metadata are unknown
105103

106-
General guidance is to follow [Googles JSON Style guide](https://google.github.io/styleguide/jsoncstyleguide.xml) where appropriate.
104+
General guidance is to follow [Google's JSON Style guide](https://google.github.io/styleguide/jsoncstyleguide.xml) where appropriate.
107105

108106
---
109107

@@ -112,7 +110,7 @@ General guidance is to follow [Google’s JSON Style guide](https://google.githu
112110
There are some limitations to the metadata that can be provided to Cloudflare:
113111

114112
- It must be valid JSON.
115-
- Any origin resolution — for example, directing requests for a given hostname to a specific backend — must be provided as a hostname that exists within Cloudflares DNS (even for non-authoritative setups). Providing an IP address directly will cause requests to error.
113+
- Any origin resolution — for example, directing requests for a given hostname to a specific backend — must be provided as a hostname that exists within Cloudflare's DNS (even for non-authoritative setups). Providing an IP address directly will cause requests to error.
116114
- The total payload must not exceed 4 KB.
117115
- It requires a Cloudflare Worker that knows how to process the schema and trigger logic based on the contents.
118116
- Custom metadata cannot be set on custom hostnames that contain wildcards.

src/content/docs/cloudflare-for-platforms/cloudflare-for-saas/performance/early-hints-for-saas.mdx

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ sidebar:
66

77
---
88

9+
import { APIRequest } from "~/components";
10+
911
[Early Hints](/cache/advanced-configuration/early-hints/) allows the browser to begin loading resources while the origin server is compiling the full response. This improves webpage’s loading speed for the end user. As a SaaS provider, you may prioritize speed for some of your custom hostnames. Using custom metadata, you can [enable Early Hints](/cache/advanced-configuration/early-hints/#enable-early-hints) per custom hostname.
1012

1113
***
@@ -24,56 +26,53 @@ Before you can employ Early Hints for SaaS, you need to create a custom hostname
2426

2527
3. If you are [creating a new custom hostname](/api/resources/custom_hostnames/methods/create/), make an API call such as the example below, specifying `"early_hints": "on"`:
2628

27-
```bash
28-
curl "https://api.cloudflare.com/client/v4/zones/{zone_id}/custom_hostnames" \
29-
--header "X-Auth-Email: <EMAIL>" \
30-
--header "X-Auth-Key: <API_KEY>" \
31-
--header "Content-Type: application/json" \
32-
--data '{
33-
"hostname": "{hostname}",
34-
"ssl": {
35-
"method": "http",
36-
"type": "dv",
37-
"settings": {
38-
"http2": "on",
39-
"min_tls_version": "1.2",
40-
"tls_1_3": "on",
41-
"early_hints": "on"
42-
},
43-
"bundle_method": "ubiquitous",
44-
"wildcard": false
45-
}
46-
}'
47-
```
29+
<APIRequest
30+
path="/zones/{zone_id}/custom_hostnames"
31+
method="POST"
32+
json={{
33+
"hostname": "<CUSTOM_HOSTNAME>",
34+
"ssl": {
35+
"method": "http",
36+
"type": "dv",
37+
"settings": {
38+
"http2": "on",
39+
"min_tls_version": "1.2",
40+
"tls_1_3": "on",
41+
"early_hints": "on"
42+
},
43+
"bundle_method": "ubiquitous",
44+
"wildcard": false
45+
},
46+
}}
47+
/>
4848

4949
4. For an existing custom hostname, locate the `id` of that hostname via a `GET` call:
5050

51-
```bash
52-
curl "https://api.cloudflare.com/client/v4/zones/{zone_id}/custom_hostnames?hostname={hostname}" \
53-
--header "X-Auth-Email: <EMAIL>" \
54-
--header "X-Auth-Key: <API_KEY>"
55-
```
51+
<APIRequest
52+
path="/zones/{zone_id}/custom_hostnames"
53+
method="GET"
54+
parameters={{
55+
hostname:"{hostname}"
56+
}}
57+
/>
5658

5759
5. Then make an API call such as the example below, specifying `"early_hints": "on"`:
5860

59-
```bash
60-
curl --request PATCH \
61-
"https://api.cloudflare.com/client/v4/zones/{zone_id}/custom_hostnames/{id}" \
62-
--header "X-Auth-Email: <EMAIL>" \
63-
--header "X-Auth-Key: <API_KEY>" \
64-
--header "Content-Type: application/json" \
65-
--data '{
66-
"ssl": {
67-
"method": "http",
68-
"type": "dv",
69-
"settings": {
70-
"http2": "on", // Note: These settings will be set to default if not included when updating early hints
71-
"min_tls_version": "1.2",
72-
"tls_1_3": "on",
73-
"early_hints": "on"
74-
}
75-
}
76-
}'
77-
```
61+
<APIRequest
62+
path="/zones/{zone_id}/custom_hostnames/{custom_hostname_id}"
63+
method="PATCH"
64+
json={{
65+
"ssl": {
66+
"method": "http",
67+
"type": "dv",
68+
"settings": {
69+
"http2": "on", // Note: These settings will be set to default if not included when updating early hints
70+
"min_tls_version": "1.2",
71+
"tls_1_3": "on",
72+
"early_hints": "on"
73+
}
74+
},
75+
}}
76+
/>
7877

7978
Currently, all options within `settings` are required in order to prevent those options from being set to default. You can pull the current settings state prior to updating Early Hints by leveraging the output that returns the `id` for the hostname.

src/content/docs/cloudflare-for-platforms/cloudflare-for-saas/security/certificate-management/custom-certificates/certificate-signing-requests.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ head:
99

1010
---
1111

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

1414
<Render file="csr-definition" product="ssl" />
1515

@@ -79,7 +79,6 @@ curl https://api.cloudflare.com/client/v4/zones/{zone_id}/custom_csrs \
7979
"csr": "-----BEGIN CERTIFICATE REQUEST-----\nMIIBSzCB8gIBADBiMQswaQYDVQQGEwJVUzELMAkGA1UECBMCTUExDzANBgNVBAcT\nBkJvc3RvbjEaMBgGA1UEChMRQ2l0eSBvZiBDaGFtcGlvbnMxGTAXBgNVBAMTEGNz\nci1wcm9kLnRscy5mdW4wWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAaTKf70NYlwr\n20P6P8xj8/4mTN5q28dbZR/gM3u4m/RPs24+PxAfMZCNvkVKAPVWYfUAadZI4Ha/\ndxLh5Q6X5bhIoC4wLAYJKoZIhvcNAQkOMR8wHTAbBqNVHREEFDASghBjc3ItcHJv\nZC50bHMuZnVuMAoGCCqGSM49BAMCA0gAMEUCIQDgtFUZav466SbT2FGBsIBlahDI\nVkg4y+u+V/K5DlY1+gIgQ9xLfUSKnSnJYbM9TwWr4Z964+lBtB9af4O5pp7/PSA=\n-----END CERTIFICATE REQUEST-----\n"
8080
},
8181
"success": true
82-
}
8382
```
8483
8584
Replace the `\n` characters with actual newlines before passing to your customer. This can be accomplished by piping the output of the prior call to a tool like jq and perl, such as:

src/content/docs/cloudflare-for-platforms/cloudflare-for-saas/security/waf-for-saas/index.mdx

Lines changed: 48 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ sidebar:
66
label: Setup
77
---
88

9+
import { APIRequest } from "~/components";
10+
911
[Web Application Firewall (WAF)](/waf/) allows you to create additional security measures through Cloudflare. As a SaaS provider, you can link custom rules, rate limiting rules, and managed rules to your custom hostnames. This provides more control to keep your domains safe from malicious traffic.
1012

1113
As a SaaS provider, you may want to apply different security measures to different custom hostnames. With WAF for SaaS, you can create multiple WAF configuration that you can apply to different sets of custom hostnames. This added flexibility and security leads to optimal protection across the domains of your end customers.
@@ -18,13 +20,16 @@ Before you can use WAF for SaaS, you need to create a custom hostname. Review [G
1820

1921
You can also create a custom hostname through the API:
2022

21-
```bash
22-
curl "https://api.cloudflare.com/client/v4/zones/{zone_id}/custom_hostnames" \
23-
--header "X-Auth-Email: <EMAIL>" \
24-
--header "X-Auth-Key: <API_KEY>" \
25-
--header "Content-Type: application/json" \
26-
--data '{"Hostname":"example.com"}, "Ssl":{wildcard:false}}'
27-
```
23+
<APIRequest
24+
path="/zones/{zone_id}/custom_hostnames"
25+
method="POST"
26+
json={{
27+
"hostname": "<CUSTOM_HOSTNAME>",
28+
"ssl": {
29+
wildcard: false
30+
},
31+
}}
32+
/>
2833

2934
## 1. Associate custom metadata to a custom hostname
3035

@@ -36,11 +41,10 @@ To apply WAF to your custom hostname, you need to create an association between
3641

3742
3. Locate your custom hostname ID by making a `GET` call in the API:
3843

39-
```bash
40-
curl "https://api.cloudflare.com/client/v4/zones/{zone_id}/custom_hostnames" \
41-
--header "X-Auth-Email: <EMAIL>" \
42-
--header "X-Auth-Key: <API_KEY>"
43-
```
44+
<APIRequest
45+
path="/zones/{zone_id}/custom_hostnames"
46+
method="GET"
47+
/>
4448

4549
4. Plan your [custom metadata](/cloudflare-for-platforms/cloudflare-for-saas/domain-support/custom-metadata/). It is fully customizable. In the example below, we have chosen the tag `"security_level"` to which we expect to assign three values (low, medium, and high).
4650

@@ -52,19 +56,16 @@ One instance of low, medium, and high rules could be rate limiting. You can spec
5256

5357
5. Make an API call in the format below using your Cloudflare email and the IDs gathered above:
5458

55-
```bash
56-
curl --request PATCH \
57-
"https://api.cloudflare.com/client/v4/zones/{zone_id}/custom_hostnames/{custom_hostname_id}" \
58-
--header "X-Auth-Email: <EMAIL>"
59-
--header "X-Auth-Key: <API_KEY>" \
60-
--header "Content-Type: application/json" \
61-
--data '{
62-
"custom_metadata": {
59+
<APIRequest
60+
path="/zones/{zone_id}/custom_hostnames/{custom_hostname_id}"
61+
method="PATCH"
62+
json={{
63+
"custom_metadata": {
6364
"customer_id": "12345",
6465
"security_level": "low"
65-
}
66-
}'
67-
```
66+
},
67+
}}
68+
/>
6869

6970
This assigns custom metadata to your custom hostname so that it has a security tag associated with its ID.
7071

@@ -74,29 +75,30 @@ This assigns custom metadata to your custom hostname so that it has a security t
7475

7576
2. Build your rules either [through the dashboard](/waf/custom-rules/create-dashboard/) or via the API. An example rate limiting rule, corresponding to `"security_level"` low, is shown below as an API call.
7677

77-
```bash
78-
curl --request PUT \
79-
"https://api.cloudflare.com/client/v4/zones/{zone_id}/rulesets/phases/http_ratelimit/entrypoint" \
80-
--header "Authorization: Bearer <API_TOKEN>" \
81-
--header "Content-Type: application/json" \
82-
--data '{
83-
"rules": [
84-
{
85-
"action": "block",
86-
"ratelimit": {
87-
"characteristics": [
88-
"cf.colo.id",
89-
"ip.src"
90-
],
91-
"period": 10,
92-
"requests_per_period": 2,
93-
"mitigation_timeout": 60
94-
},
95-
"expression": "lookup_json_string(cf.hostname.metadata, \"security_level\") eq \"low\" and http.request.uri contains \"login\""
96-
}
97-
]
98-
}'
99-
```
78+
<APIRequest
79+
path="/zones/{zone_id}/rulesets/phases/{ruleset_phase}/entrypoint"
80+
method="PUT"
81+
json={{
82+
"rules": [
83+
{
84+
"action": "block",
85+
"ratelimit": {
86+
"characteristics": [
87+
"cf.colo.id",
88+
"ip.src"
89+
],
90+
"period": 10,
91+
"requests_per_period": 2,
92+
"mitigation_timeout": 60
93+
},
94+
"expression": "lookup_json_string(cf.hostname.metadata, \"security_level\") eq \"low\" and http.request.uri contains \"login\""
95+
}
96+
]
97+
}}
98+
parameters={{
99+
ruleset_phase: "http_ratelimit"
100+
}}
101+
/>
100102

101103
To build rules through the dashboard:
102104

0 commit comments

Comments
 (0)