Skip to content

Commit 1373bb4

Browse files
feat: feat: enable treeshaking and client options for setting zone and account IDs
* feat: add env var readability for zone_id and account_id client options * feat: enable treeshaking and client options for setting zone and account IDs
1 parent 919dbc1 commit 1373bb4

1,583 files changed

Lines changed: 13773 additions & 6065 deletions

File tree

Some content is hidden

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

.stats.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
configured_endpoints: 2130
22
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-ab609e3619850ae80630427118b42ff5b46f6ce33df8c5d921a06ee1fbc9ead4.yml
33
openapi_spec_hash: 4bf317165b24e2deef370e50d511e5b0
4-
config_hash: fce4390351fe38ffbbe66f8b173ece0a
4+
config_hash: 65784195b02c76984fb4a94b71ad36c3

src/cloudflare/_client.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ class Cloudflare(SyncAPIClient):
292292
api_key: str | None
293293
api_email: str | None
294294
user_service_key: str | None
295+
account_id: str | None
296+
zone_id: str | None
295297

296298
def __init__(
297299
self,
@@ -300,6 +302,8 @@ def __init__(
300302
api_key: str | None = None,
301303
api_email: str | None = None,
302304
user_service_key: str | None = None,
305+
account_id: str | None = None,
306+
zone_id: str | None = None,
303307
base_url: str | httpx.URL | None = None,
304308
api_version: str | None = None,
305309
timeout: float | Timeout | None | NotGiven = not_given,
@@ -327,6 +331,8 @@ def __init__(
327331
- `api_key` from `CLOUDFLARE_API_KEY`
328332
- `api_email` from `CLOUDFLARE_EMAIL`
329333
- `user_service_key` from `CLOUDFLARE_API_USER_SERVICE_KEY`
334+
- `account_id` from `CLOUDFLARE_ACCOUNT_ID`
335+
- `zone_id` from `CLOUDFLARE_ZONE_ID`
330336
"""
331337
if api_token is None:
332338
api_token = os.environ.get("CLOUDFLARE_API_TOKEN")
@@ -344,6 +350,14 @@ def __init__(
344350
user_service_key = os.environ.get("CLOUDFLARE_API_USER_SERVICE_KEY")
345351
self.user_service_key = user_service_key
346352

353+
if account_id is None:
354+
account_id = os.environ.get("CLOUDFLARE_ACCOUNT_ID")
355+
self.account_id = account_id
356+
357+
if zone_id is None:
358+
zone_id = os.environ.get("CLOUDFLARE_ZONE_ID")
359+
self.zone_id = zone_id
360+
347361
if base_url is None:
348362
base_url = os.environ.get("CLOUDFLARE_BASE_URL")
349363
if base_url is None:
@@ -1078,6 +1092,8 @@ def copy(
10781092
api_key: str | None = None,
10791093
api_email: str | None = None,
10801094
user_service_key: str | None = None,
1095+
account_id: str | None = None,
1096+
zone_id: str | None = None,
10811097
base_url: str | httpx.URL | None = None,
10821098
api_version: str | None = None,
10831099
timeout: float | Timeout | None | NotGiven = not_given,
@@ -1116,6 +1132,8 @@ def copy(
11161132
api_key=api_key or self.api_key,
11171133
api_email=api_email or self.api_email,
11181134
user_service_key=user_service_key or self.user_service_key,
1135+
account_id=account_id or self.account_id,
1136+
zone_id=zone_id or self.zone_id,
11191137
base_url=base_url or self.base_url,
11201138
api_version=api_version or self.api_version,
11211139
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
@@ -1130,6 +1148,24 @@ def copy(
11301148
# client.with_options(timeout=10).foo.create(...)
11311149
with_options = copy
11321150

1151+
def _get_account_id_path_param(self) -> str:
1152+
from_client = self.account_id
1153+
if from_client is not None:
1154+
return from_client
1155+
1156+
raise ValueError(
1157+
"Missing account_id argument; Please provide it at the client level, e.g. Cloudflare(account_id='abcd') or per method."
1158+
)
1159+
1160+
def _get_zone_id_path_param(self) -> str:
1161+
from_client = self.zone_id
1162+
if from_client is not None:
1163+
return from_client
1164+
1165+
raise ValueError(
1166+
"Missing zone_id argument; Please provide it at the client level, e.g. Cloudflare(zone_id='abcd') or per method."
1167+
)
1168+
11331169
@override
11341170
def _make_status_error(
11351171
self,
@@ -1170,6 +1206,8 @@ class AsyncCloudflare(AsyncAPIClient):
11701206
api_key: str | None
11711207
api_email: str | None
11721208
user_service_key: str | None
1209+
account_id: str | None
1210+
zone_id: str | None
11731211

11741212
def __init__(
11751213
self,
@@ -1178,6 +1216,8 @@ def __init__(
11781216
api_key: str | None = None,
11791217
api_email: str | None = None,
11801218
user_service_key: str | None = None,
1219+
account_id: str | None = None,
1220+
zone_id: str | None = None,
11811221
base_url: str | httpx.URL | None = None,
11821222
api_version: str | None = None,
11831223
timeout: float | Timeout | None | NotGiven = not_given,
@@ -1205,6 +1245,8 @@ def __init__(
12051245
- `api_key` from `CLOUDFLARE_API_KEY`
12061246
- `api_email` from `CLOUDFLARE_EMAIL`
12071247
- `user_service_key` from `CLOUDFLARE_API_USER_SERVICE_KEY`
1248+
- `account_id` from `CLOUDFLARE_ACCOUNT_ID`
1249+
- `zone_id` from `CLOUDFLARE_ZONE_ID`
12081250
"""
12091251
if api_token is None:
12101252
api_token = os.environ.get("CLOUDFLARE_API_TOKEN")
@@ -1222,6 +1264,14 @@ def __init__(
12221264
user_service_key = os.environ.get("CLOUDFLARE_API_USER_SERVICE_KEY")
12231265
self.user_service_key = user_service_key
12241266

1267+
if account_id is None:
1268+
account_id = os.environ.get("CLOUDFLARE_ACCOUNT_ID")
1269+
self.account_id = account_id
1270+
1271+
if zone_id is None:
1272+
zone_id = os.environ.get("CLOUDFLARE_ZONE_ID")
1273+
self.zone_id = zone_id
1274+
12251275
if base_url is None:
12261276
base_url = os.environ.get("CLOUDFLARE_BASE_URL")
12271277
if base_url is None:
@@ -1956,6 +2006,8 @@ def copy(
19562006
api_key: str | None = None,
19572007
api_email: str | None = None,
19582008
user_service_key: str | None = None,
2009+
account_id: str | None = None,
2010+
zone_id: str | None = None,
19592011
base_url: str | httpx.URL | None = None,
19602012
api_version: str | None = None,
19612013
timeout: float | Timeout | None | NotGiven = not_given,
@@ -1994,6 +2046,8 @@ def copy(
19942046
api_key=api_key or self.api_key,
19952047
api_email=api_email or self.api_email,
19962048
user_service_key=user_service_key or self.user_service_key,
2049+
account_id=account_id or self.account_id,
2050+
zone_id=zone_id or self.zone_id,
19972051
base_url=base_url or self.base_url,
19982052
api_version=api_version or self.api_version,
19992053
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
@@ -2008,6 +2062,24 @@ def copy(
20082062
# client.with_options(timeout=10).foo.create(...)
20092063
with_options = copy
20102064

2065+
def _get_account_id_path_param(self) -> str:
2066+
from_client = self.account_id
2067+
if from_client is not None:
2068+
return from_client
2069+
2070+
raise ValueError(
2071+
"Missing account_id argument; Please provide it at the client level, e.g. AsyncCloudflare(account_id='abcd') or per method."
2072+
)
2073+
2074+
def _get_zone_id_path_param(self) -> str:
2075+
from_client = self.zone_id
2076+
if from_client is not None:
2077+
return from_client
2078+
2079+
raise ValueError(
2080+
"Missing zone_id argument; Please provide it at the client level, e.g. AsyncCloudflare(zone_id='abcd') or per method."
2081+
)
2082+
20112083
@override
20122084
def _make_status_error(
20132085
self,

0 commit comments

Comments
 (0)