|
| 1 | +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import Type, Optional, cast |
| 6 | +from typing_extensions import Literal |
| 7 | + |
| 8 | +import httpx |
| 9 | + |
| 10 | +from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven |
| 11 | +from ...._utils import ( |
| 12 | + maybe_transform, |
| 13 | + async_maybe_transform, |
| 14 | +) |
| 15 | +from ...._compat import cached_property |
| 16 | +from ...._resource import SyncAPIResource, AsyncAPIResource |
| 17 | +from ...._response import ( |
| 18 | + to_raw_response_wrapper, |
| 19 | + to_streamed_response_wrapper, |
| 20 | + async_to_raw_response_wrapper, |
| 21 | + async_to_streamed_response_wrapper, |
| 22 | +) |
| 23 | +from ...._wrappers import ResultWrapper |
| 24 | +from ...._base_client import make_request_options |
| 25 | +from ....types.dns.settings import zone_edit_params |
| 26 | +from ....types.dns.settings.zone_get_response import ZoneGetResponse |
| 27 | +from ....types.dns.settings.zone_edit_response import ZoneEditResponse |
| 28 | + |
| 29 | +__all__ = ["ZoneResource", "AsyncZoneResource"] |
| 30 | + |
| 31 | + |
| 32 | +class ZoneResource(SyncAPIResource): |
| 33 | + @cached_property |
| 34 | + def with_raw_response(self) -> ZoneResourceWithRawResponse: |
| 35 | + """ |
| 36 | + This property can be used as a prefix for any HTTP method call to return |
| 37 | + the raw response object instead of the parsed content. |
| 38 | +
|
| 39 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 40 | + """ |
| 41 | + return ZoneResourceWithRawResponse(self) |
| 42 | + |
| 43 | + @cached_property |
| 44 | + def with_streaming_response(self) -> ZoneResourceWithStreamingResponse: |
| 45 | + """ |
| 46 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 47 | +
|
| 48 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 49 | + """ |
| 50 | + return ZoneResourceWithStreamingResponse(self) |
| 51 | + |
| 52 | + def edit( |
| 53 | + self, |
| 54 | + *, |
| 55 | + zone_id: str, |
| 56 | + flatten_all_cnames: bool | NotGiven = NOT_GIVEN, |
| 57 | + foundation_dns: bool | NotGiven = NOT_GIVEN, |
| 58 | + internal_dns: zone_edit_params.InternalDNS | NotGiven = NOT_GIVEN, |
| 59 | + multi_provider: bool | NotGiven = NOT_GIVEN, |
| 60 | + nameservers: zone_edit_params.Nameservers | NotGiven = NOT_GIVEN, |
| 61 | + ns_ttl: float | NotGiven = NOT_GIVEN, |
| 62 | + secondary_overrides: bool | NotGiven = NOT_GIVEN, |
| 63 | + soa: zone_edit_params.SOA | NotGiven = NOT_GIVEN, |
| 64 | + zone_mode: Literal["standard", "cdn_only", "dns_only"] | NotGiven = NOT_GIVEN, |
| 65 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 66 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 67 | + extra_headers: Headers | None = None, |
| 68 | + extra_query: Query | None = None, |
| 69 | + extra_body: Body | None = None, |
| 70 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 71 | + ) -> Optional[ZoneEditResponse]: |
| 72 | + """ |
| 73 | + Update DNS settings for a zone |
| 74 | +
|
| 75 | + Args: |
| 76 | + zone_id: Identifier |
| 77 | +
|
| 78 | + flatten_all_cnames: Whether to flatten all CNAME records in the zone. Note that, due to DNS |
| 79 | + limitations, a CNAME record at the zone apex will always be flattened. |
| 80 | +
|
| 81 | + foundation_dns: Whether to enable Foundation DNS Advanced Nameservers on the zone. |
| 82 | +
|
| 83 | + internal_dns: Settings for this internal zone. |
| 84 | +
|
| 85 | + multi_provider: Whether to enable multi-provider DNS, which causes Cloudflare to activate the |
| 86 | + zone even when non-Cloudflare NS records exist, and to respect NS records at the |
| 87 | + zone apex during outbound zone transfers. |
| 88 | +
|
| 89 | + nameservers: Settings determining the nameservers through which the zone should be available. |
| 90 | +
|
| 91 | + ns_ttl: The time to live (TTL) of the zone's nameserver (NS) records. |
| 92 | +
|
| 93 | + secondary_overrides: Allows a Secondary DNS zone to use (proxied) override records and CNAME |
| 94 | + flattening at the zone apex. |
| 95 | +
|
| 96 | + soa: Components of the zone's SOA record. |
| 97 | +
|
| 98 | + zone_mode: Whether the zone mode is a regular or CDN/DNS only zone. |
| 99 | +
|
| 100 | + extra_headers: Send extra headers |
| 101 | +
|
| 102 | + extra_query: Add additional query parameters to the request |
| 103 | +
|
| 104 | + extra_body: Add additional JSON properties to the request |
| 105 | +
|
| 106 | + timeout: Override the client-level default timeout for this request, in seconds |
| 107 | + """ |
| 108 | + if not zone_id: |
| 109 | + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") |
| 110 | + return self._patch( |
| 111 | + f"/zones/{zone_id}/dns_settings", |
| 112 | + body=maybe_transform( |
| 113 | + { |
| 114 | + "flatten_all_cnames": flatten_all_cnames, |
| 115 | + "foundation_dns": foundation_dns, |
| 116 | + "internal_dns": internal_dns, |
| 117 | + "multi_provider": multi_provider, |
| 118 | + "nameservers": nameservers, |
| 119 | + "ns_ttl": ns_ttl, |
| 120 | + "secondary_overrides": secondary_overrides, |
| 121 | + "soa": soa, |
| 122 | + "zone_mode": zone_mode, |
| 123 | + }, |
| 124 | + zone_edit_params.ZoneEditParams, |
| 125 | + ), |
| 126 | + options=make_request_options( |
| 127 | + extra_headers=extra_headers, |
| 128 | + extra_query=extra_query, |
| 129 | + extra_body=extra_body, |
| 130 | + timeout=timeout, |
| 131 | + post_parser=ResultWrapper[Optional[ZoneEditResponse]]._unwrapper, |
| 132 | + ), |
| 133 | + cast_to=cast(Type[Optional[ZoneEditResponse]], ResultWrapper[ZoneEditResponse]), |
| 134 | + ) |
| 135 | + |
| 136 | + def get( |
| 137 | + self, |
| 138 | + *, |
| 139 | + zone_id: str, |
| 140 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 141 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 142 | + extra_headers: Headers | None = None, |
| 143 | + extra_query: Query | None = None, |
| 144 | + extra_body: Body | None = None, |
| 145 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 146 | + ) -> Optional[ZoneGetResponse]: |
| 147 | + """ |
| 148 | + Show DNS settings for a zone |
| 149 | +
|
| 150 | + Args: |
| 151 | + zone_id: Identifier |
| 152 | +
|
| 153 | + extra_headers: Send extra headers |
| 154 | +
|
| 155 | + extra_query: Add additional query parameters to the request |
| 156 | +
|
| 157 | + extra_body: Add additional JSON properties to the request |
| 158 | +
|
| 159 | + timeout: Override the client-level default timeout for this request, in seconds |
| 160 | + """ |
| 161 | + if not zone_id: |
| 162 | + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") |
| 163 | + return self._get( |
| 164 | + f"/zones/{zone_id}/dns_settings", |
| 165 | + options=make_request_options( |
| 166 | + extra_headers=extra_headers, |
| 167 | + extra_query=extra_query, |
| 168 | + extra_body=extra_body, |
| 169 | + timeout=timeout, |
| 170 | + post_parser=ResultWrapper[Optional[ZoneGetResponse]]._unwrapper, |
| 171 | + ), |
| 172 | + cast_to=cast(Type[Optional[ZoneGetResponse]], ResultWrapper[ZoneGetResponse]), |
| 173 | + ) |
| 174 | + |
| 175 | + |
| 176 | +class AsyncZoneResource(AsyncAPIResource): |
| 177 | + @cached_property |
| 178 | + def with_raw_response(self) -> AsyncZoneResourceWithRawResponse: |
| 179 | + """ |
| 180 | + This property can be used as a prefix for any HTTP method call to return |
| 181 | + the raw response object instead of the parsed content. |
| 182 | +
|
| 183 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers |
| 184 | + """ |
| 185 | + return AsyncZoneResourceWithRawResponse(self) |
| 186 | + |
| 187 | + @cached_property |
| 188 | + def with_streaming_response(self) -> AsyncZoneResourceWithStreamingResponse: |
| 189 | + """ |
| 190 | + An alternative to `.with_raw_response` that doesn't eagerly read the response body. |
| 191 | +
|
| 192 | + For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response |
| 193 | + """ |
| 194 | + return AsyncZoneResourceWithStreamingResponse(self) |
| 195 | + |
| 196 | + async def edit( |
| 197 | + self, |
| 198 | + *, |
| 199 | + zone_id: str, |
| 200 | + flatten_all_cnames: bool | NotGiven = NOT_GIVEN, |
| 201 | + foundation_dns: bool | NotGiven = NOT_GIVEN, |
| 202 | + internal_dns: zone_edit_params.InternalDNS | NotGiven = NOT_GIVEN, |
| 203 | + multi_provider: bool | NotGiven = NOT_GIVEN, |
| 204 | + nameservers: zone_edit_params.Nameservers | NotGiven = NOT_GIVEN, |
| 205 | + ns_ttl: float | NotGiven = NOT_GIVEN, |
| 206 | + secondary_overrides: bool | NotGiven = NOT_GIVEN, |
| 207 | + soa: zone_edit_params.SOA | NotGiven = NOT_GIVEN, |
| 208 | + zone_mode: Literal["standard", "cdn_only", "dns_only"] | NotGiven = NOT_GIVEN, |
| 209 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 210 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 211 | + extra_headers: Headers | None = None, |
| 212 | + extra_query: Query | None = None, |
| 213 | + extra_body: Body | None = None, |
| 214 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 215 | + ) -> Optional[ZoneEditResponse]: |
| 216 | + """ |
| 217 | + Update DNS settings for a zone |
| 218 | +
|
| 219 | + Args: |
| 220 | + zone_id: Identifier |
| 221 | +
|
| 222 | + flatten_all_cnames: Whether to flatten all CNAME records in the zone. Note that, due to DNS |
| 223 | + limitations, a CNAME record at the zone apex will always be flattened. |
| 224 | +
|
| 225 | + foundation_dns: Whether to enable Foundation DNS Advanced Nameservers on the zone. |
| 226 | +
|
| 227 | + internal_dns: Settings for this internal zone. |
| 228 | +
|
| 229 | + multi_provider: Whether to enable multi-provider DNS, which causes Cloudflare to activate the |
| 230 | + zone even when non-Cloudflare NS records exist, and to respect NS records at the |
| 231 | + zone apex during outbound zone transfers. |
| 232 | +
|
| 233 | + nameservers: Settings determining the nameservers through which the zone should be available. |
| 234 | +
|
| 235 | + ns_ttl: The time to live (TTL) of the zone's nameserver (NS) records. |
| 236 | +
|
| 237 | + secondary_overrides: Allows a Secondary DNS zone to use (proxied) override records and CNAME |
| 238 | + flattening at the zone apex. |
| 239 | +
|
| 240 | + soa: Components of the zone's SOA record. |
| 241 | +
|
| 242 | + zone_mode: Whether the zone mode is a regular or CDN/DNS only zone. |
| 243 | +
|
| 244 | + extra_headers: Send extra headers |
| 245 | +
|
| 246 | + extra_query: Add additional query parameters to the request |
| 247 | +
|
| 248 | + extra_body: Add additional JSON properties to the request |
| 249 | +
|
| 250 | + timeout: Override the client-level default timeout for this request, in seconds |
| 251 | + """ |
| 252 | + if not zone_id: |
| 253 | + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") |
| 254 | + return await self._patch( |
| 255 | + f"/zones/{zone_id}/dns_settings", |
| 256 | + body=await async_maybe_transform( |
| 257 | + { |
| 258 | + "flatten_all_cnames": flatten_all_cnames, |
| 259 | + "foundation_dns": foundation_dns, |
| 260 | + "internal_dns": internal_dns, |
| 261 | + "multi_provider": multi_provider, |
| 262 | + "nameservers": nameservers, |
| 263 | + "ns_ttl": ns_ttl, |
| 264 | + "secondary_overrides": secondary_overrides, |
| 265 | + "soa": soa, |
| 266 | + "zone_mode": zone_mode, |
| 267 | + }, |
| 268 | + zone_edit_params.ZoneEditParams, |
| 269 | + ), |
| 270 | + options=make_request_options( |
| 271 | + extra_headers=extra_headers, |
| 272 | + extra_query=extra_query, |
| 273 | + extra_body=extra_body, |
| 274 | + timeout=timeout, |
| 275 | + post_parser=ResultWrapper[Optional[ZoneEditResponse]]._unwrapper, |
| 276 | + ), |
| 277 | + cast_to=cast(Type[Optional[ZoneEditResponse]], ResultWrapper[ZoneEditResponse]), |
| 278 | + ) |
| 279 | + |
| 280 | + async def get( |
| 281 | + self, |
| 282 | + *, |
| 283 | + zone_id: str, |
| 284 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 285 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 286 | + extra_headers: Headers | None = None, |
| 287 | + extra_query: Query | None = None, |
| 288 | + extra_body: Body | None = None, |
| 289 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 290 | + ) -> Optional[ZoneGetResponse]: |
| 291 | + """ |
| 292 | + Show DNS settings for a zone |
| 293 | +
|
| 294 | + Args: |
| 295 | + zone_id: Identifier |
| 296 | +
|
| 297 | + extra_headers: Send extra headers |
| 298 | +
|
| 299 | + extra_query: Add additional query parameters to the request |
| 300 | +
|
| 301 | + extra_body: Add additional JSON properties to the request |
| 302 | +
|
| 303 | + timeout: Override the client-level default timeout for this request, in seconds |
| 304 | + """ |
| 305 | + if not zone_id: |
| 306 | + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") |
| 307 | + return await self._get( |
| 308 | + f"/zones/{zone_id}/dns_settings", |
| 309 | + options=make_request_options( |
| 310 | + extra_headers=extra_headers, |
| 311 | + extra_query=extra_query, |
| 312 | + extra_body=extra_body, |
| 313 | + timeout=timeout, |
| 314 | + post_parser=ResultWrapper[Optional[ZoneGetResponse]]._unwrapper, |
| 315 | + ), |
| 316 | + cast_to=cast(Type[Optional[ZoneGetResponse]], ResultWrapper[ZoneGetResponse]), |
| 317 | + ) |
| 318 | + |
| 319 | + |
| 320 | +class ZoneResourceWithRawResponse: |
| 321 | + def __init__(self, zone: ZoneResource) -> None: |
| 322 | + self._zone = zone |
| 323 | + |
| 324 | + self.edit = to_raw_response_wrapper( |
| 325 | + zone.edit, |
| 326 | + ) |
| 327 | + self.get = to_raw_response_wrapper( |
| 328 | + zone.get, |
| 329 | + ) |
| 330 | + |
| 331 | + |
| 332 | +class AsyncZoneResourceWithRawResponse: |
| 333 | + def __init__(self, zone: AsyncZoneResource) -> None: |
| 334 | + self._zone = zone |
| 335 | + |
| 336 | + self.edit = async_to_raw_response_wrapper( |
| 337 | + zone.edit, |
| 338 | + ) |
| 339 | + self.get = async_to_raw_response_wrapper( |
| 340 | + zone.get, |
| 341 | + ) |
| 342 | + |
| 343 | + |
| 344 | +class ZoneResourceWithStreamingResponse: |
| 345 | + def __init__(self, zone: ZoneResource) -> None: |
| 346 | + self._zone = zone |
| 347 | + |
| 348 | + self.edit = to_streamed_response_wrapper( |
| 349 | + zone.edit, |
| 350 | + ) |
| 351 | + self.get = to_streamed_response_wrapper( |
| 352 | + zone.get, |
| 353 | + ) |
| 354 | + |
| 355 | + |
| 356 | +class AsyncZoneResourceWithStreamingResponse: |
| 357 | + def __init__(self, zone: AsyncZoneResource) -> None: |
| 358 | + self._zone = zone |
| 359 | + |
| 360 | + self.edit = async_to_streamed_response_wrapper( |
| 361 | + zone.edit, |
| 362 | + ) |
| 363 | + self.get = async_to_streamed_response_wrapper( |
| 364 | + zone.get, |
| 365 | + ) |
0 commit comments