Skip to content

Commit 65beeea

Browse files
feat: feat(resource_tagging): add summary endpoint mapping
* feat(resource_tagging): add summary endpoint mapping
1 parent 264cebe commit 65beeea

45 files changed

Lines changed: 564 additions & 266 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ jobs:
2626
runs-on: ${{ github.repository == 'stainless-sdks/cloudflare-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
2727
if: (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata')
2828
steps:
29-
- uses: actions/checkout@v6
29+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
3030

3131
- name: Install uv
32-
uses: astral-sh/setup-uv@v5
32+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
3333
with:
3434
version: '0.10.2'
3535

@@ -48,10 +48,10 @@ jobs:
4848
id-token: write
4949
runs-on: ${{ github.repository == 'stainless-sdks/cloudflare-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
5050
steps:
51-
- uses: actions/checkout@v6
51+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
5252

5353
- name: Install uv
54-
uses: astral-sh/setup-uv@v5
54+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
5555
with:
5656
version: '0.10.2'
5757

@@ -66,7 +66,7 @@ jobs:
6666
github.repository == 'stainless-sdks/cloudflare-python' &&
6767
!startsWith(github.ref, 'refs/heads/stl/')
6868
id: github-oidc
69-
uses: actions/github-script@v8
69+
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
7070
with:
7171
script: core.setOutput('github_token', await core.getIDToken());
7272

@@ -86,10 +86,10 @@ jobs:
8686
runs-on: ${{ github.repository == 'stainless-sdks/cloudflare-python' && 'depot-ubuntu-24.04' || 'ubuntu-latest' }}
8787
if: github.event_name == 'push' || github.event.pull_request.head.repo.fork
8888
steps:
89-
- uses: actions/checkout@v6
89+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
9090

9191
- name: Install uv
92-
uses: astral-sh/setup-uv@v5
92+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
9393
with:
9494
version: '0.10.2'
9595

@@ -110,10 +110,10 @@ jobs:
110110
if: github.repository == 'cloudflare/cloudflare-python' && (github.event_name == 'push' || github.event.pull_request.head.repo.fork) && (github.event_name != 'push' || github.event.head_commit.message != 'codegen metadata')
111111

112112
steps:
113-
- uses: actions/checkout@v6
113+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
114114

115115
- name: Install uv
116-
uses: astral-sh/setup-uv@v5
116+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
117117
with:
118118
version: '0.10.2'
119119
- name: Install dependencies

.github/workflows/detect-breaking-changes.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@ jobs:
1616
run: |
1717
echo "FETCH_DEPTH=$(expr ${{ github.event.pull_request.commits }} + 1)" >> $GITHUB_ENV
1818
19-
- uses: actions/checkout@v6
19+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2020
with:
2121
# Ensure we can check out the pull request base in the script below.
2222
fetch-depth: ${{ env.FETCH_DEPTH }}
2323

2424
- name: Install uv
25-
uses: astral-sh/setup-uv@v5
25+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
2626
with:
2727
version: '0.10.2'
2828
- name: Install dependencies

.github/workflows/publish-pypi.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ jobs:
1616
runs-on: ubuntu-latest
1717

1818
steps:
19-
- uses: actions/checkout@v6
19+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2020

2121
- name: Install uv
22-
uses: astral-sh/setup-uv@v5
22+
uses: astral-sh/setup-uv@d4b2f3b6ecc6e67c4457f6d3e41ec42d3d0fcb86 # v5.4.2
2323
with:
2424
version: '0.9.13'
2525

.github/workflows/release-doctor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
if: github.repository == 'cloudflare/cloudflare-python' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || startsWith(github.head_ref, 'release-please') || github.head_ref == 'next')
2121

2222
steps:
23-
- uses: actions/checkout@v6
23+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
2424

2525
- name: Check release environment
2626
run: |

.stats.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 2304
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-a6c352830d1270d0abb5bb983058ea21815e1bb7d2e163965335dcb0e706f057.yml
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare/cloudflare-cab0533c32650305eaa27491714d017535dfff5cf1f642d0c5dc06b3906b339f.yml
33
openapi_spec_hash: f88a1f57da1f979400b58e284e8a8191
4-
config_hash: 23fee7da67ba558209f67d29de98f8c2
4+
config_hash: bbf9427136a35ea3704b605309480336

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ show_error_codes = true
155155
#
156156
# We also exclude our `tests` as mypy doesn't always infer
157157
# types correctly and Pyright will still catch any type errors.
158-
exclude = ['src/cloudflare/_files.py', '_dev/.*.py', 'tests/.*', 'src/cloudflare/resources/zero_trust/identity_providers\.py', 'src/cloudflare/resources/zero_trust/access/applications/applications\.py', 'src/cloudflare/resources/workers/ai\.py', 'src/cloudflare/resources/magic_transit/apps\.py']
158+
exclude = ["src/cloudflare/_files.py", "_dev/.*.py", "tests/.*", "src/cloudflare/resources/zero_trust/identity_providers\\.py", "src/cloudflare/resources/zero_trust/access/applications/applications\\.py", "src/cloudflare/resources/workers/ai\\.py", "src/cloudflare/resources/magic_transit/apps\\.py"]
159159

160160
strict_equality = true
161161
implicit_reexport = true

scripts/bootstrap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44

55
cd "$(dirname "$0")/.."
66

7-
if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "$SKIP_BREW" != "1" ] && [ -t 0 ]; then
7+
if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "${SKIP_BREW:-}" != "1" ] && [ -t 0 ]; then
88
brew bundle check >/dev/null 2>&1 || {
99
echo -n "==> Install Homebrew dependencies? (y/N): "
1010
read -r response

src/cloudflare/_base_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def _build_request(
536536
f"Expected query input to be a dictionary for multipart requests but got {type(json_data)} instead."
537537
)
538538

539-
if options.multipart_syntax == 'json':
539+
if options.multipart_syntax == "json":
540540
json_data = cast("Mapping[str, object]", json_data)
541541
if is_mapping_t(files):
542542
files = {

src/cloudflare/_client.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@
2121
RequestOptions,
2222
not_given,
2323
)
24-
from ._utils import is_given, get_async_library
24+
from ._utils import (
25+
is_given,
26+
is_mapping_t,
27+
get_async_library,
28+
)
2529
from ._compat import cached_property
2630
from ._version import __version__
2731
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
@@ -377,8 +381,16 @@ def __init__(
377381
base_url = f"https://api.cloudflare.com/client/v4"
378382

379383
if api_version is None:
380-
api_version = datetime.today().strftime('%Y-%m-%d')
381-
384+
api_version = datetime.today().strftime("%Y-%m-%d")
385+
386+
custom_headers_env = os.environ.get("CLOUDFLARE_CUSTOM_HEADERS")
387+
if custom_headers_env is not None:
388+
parsed: dict[str, str] = {}
389+
for line in custom_headers_env.split("\n"):
390+
colon = line.find(":")
391+
if colon >= 0:
392+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
393+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
382394
super().__init__(
383395
version=__version__,
384396
base_url=base_url,
@@ -1291,8 +1303,16 @@ def __init__(
12911303
base_url = f"https://api.cloudflare.com/client/v4"
12921304

12931305
if api_version is None:
1294-
api_version = datetime.today().strftime('%Y-%m-%d')
1295-
1306+
api_version = datetime.today().strftime("%Y-%m-%d")
1307+
1308+
custom_headers_env = os.environ.get("CLOUDFLARE_CUSTOM_HEADERS")
1309+
if custom_headers_env is not None:
1310+
parsed: dict[str, str] = {}
1311+
for line in custom_headers_env.split("\n"):
1312+
colon = line.find(":")
1313+
if colon >= 0:
1314+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
1315+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
12961316
super().__init__(
12971317
version=__version__,
12981318
base_url=base_url,

src/cloudflare/_files.py

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import io
44
import os
55
import pathlib
6-
from typing import overload
7-
from typing_extensions import TypeGuard
6+
from typing import Sequence, cast, overload
7+
from typing_extensions import TypeVar, TypeGuard
88

99
import anyio
1010

@@ -17,7 +17,9 @@
1717
HttpxFileContent,
1818
HttpxRequestFiles,
1919
)
20-
from ._utils import is_tuple_t, is_mapping_t, is_sequence_t
20+
from ._utils import is_list, is_mapping, is_tuple_t, is_mapping_t, is_sequence_t
21+
22+
_T = TypeVar("_T")
2123

2224

2325
def is_base64_file_input(obj: object) -> TypeGuard[Base64FileInput]:
@@ -97,7 +99,7 @@ async def async_to_httpx_files(files: RequestFiles | None) -> HttpxRequestFiles
9799
elif is_sequence_t(files):
98100
files = [(key, await _async_transform_file(file)) for key, file in files]
99101
else:
100-
raise TypeError("Unexpected file type input {type(files)}, expected mapping or sequence")
102+
raise TypeError(f"Unexpected file type input {type(files)}, expected mapping or sequence")
101103

102104
return files
103105

@@ -121,3 +123,51 @@ async def async_read_file_content(file: FileContent) -> HttpxFileContent:
121123
return await anyio.Path(file).read_bytes()
122124

123125
return file
126+
127+
128+
def deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]]) -> _T:
129+
"""Copy only the containers along the given paths.
130+
131+
Used to guard against mutation by extract_files without copying the entire structure.
132+
Only dicts and lists that lie on a path are copied; everything else
133+
is returned by reference.
134+
135+
For example, given paths=[["foo", "files", "file"]] and the structure:
136+
{
137+
"foo": {
138+
"bar": {"baz": {}},
139+
"files": {"file": <content>}
140+
}
141+
}
142+
The root dict, "foo", and "files" are copied (they lie on the path).
143+
"bar" and "baz" are returned by reference (off the path).
144+
"""
145+
return _deepcopy_with_paths(item, paths, 0)
146+
147+
148+
def _deepcopy_with_paths(item: _T, paths: Sequence[Sequence[str]], index: int) -> _T:
149+
if not paths:
150+
return item
151+
if is_mapping(item):
152+
key_to_paths: dict[str, list[Sequence[str]]] = {}
153+
for path in paths:
154+
if index < len(path):
155+
key_to_paths.setdefault(path[index], []).append(path)
156+
157+
# if no path continues through this mapping, it won't be mutated and copying it is redundant
158+
if not key_to_paths:
159+
return item
160+
161+
result = dict(item)
162+
for key, subpaths in key_to_paths.items():
163+
if key in result:
164+
result[key] = _deepcopy_with_paths(result[key], subpaths, index + 1)
165+
return cast(_T, result)
166+
if is_list(item):
167+
array_paths = [path for path in paths if index < len(path) and path[index] == "<array>"]
168+
169+
# if no path expects a list here, nothing will be mutated inside it - return by reference
170+
if not array_paths:
171+
return cast(_T, item)
172+
return cast(_T, [_deepcopy_with_paths(entry, array_paths, index + 1) for entry in item])
173+
return item

0 commit comments

Comments
 (0)