mirror of
https://github.com/cloudflare/cloudflare-python.git
synced 2026-01-16 23:01:03 +00:00
feat(api): api update
This commit is contained in:
parent
1cc4487501
commit
c73f7da0b9
8 changed files with 376 additions and 4 deletions
|
|
@ -1,4 +1,4 @@
|
|||
configured_endpoints: 1750
|
||||
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-6773492e97af018fae5cac5460979be509a3bb6c4d14ce80d805cb9e1328aa4f.yml
|
||||
openapi_spec_hash: de4f43cb837ae9de82f97c42520bd63d
|
||||
configured_endpoints: 1751
|
||||
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-efc58a88a6028fef3d08457bbffc331b54e2b8153dd5e3f4c693517d0c3d073e.yml
|
||||
openapi_spec_hash: bfc60ab47d6b393226b7c5c2014fed18
|
||||
config_hash: 34d27311917dcf9fa18b91afc137e504
|
||||
|
|
|
|||
6
api.md
6
api.md
|
|
@ -160,9 +160,13 @@ Methods:
|
|||
Types:
|
||||
|
||||
```python
|
||||
from cloudflare.types.ips import IPs
|
||||
from cloudflare.types.ips import IPs, IPListResponse
|
||||
```
|
||||
|
||||
Methods:
|
||||
|
||||
- <code title="get /ips">client.ips.<a href="./src/cloudflare/resources/ips.py">list</a>(\*\*<a href="src/cloudflare/types/ips/ip_list_params.py">params</a>) -> <a href="./src/cloudflare/types/ips/ip_list_response.py">Optional[IPListResponse]</a></code>
|
||||
|
||||
# Memberships
|
||||
|
||||
Types:
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ if TYPE_CHECKING:
|
|||
acm,
|
||||
dns,
|
||||
iam,
|
||||
ips,
|
||||
rum,
|
||||
ssl,
|
||||
argo,
|
||||
|
|
@ -129,6 +130,7 @@ if TYPE_CHECKING:
|
|||
magic_network_monitoring,
|
||||
origin_post_quantum_encryption,
|
||||
)
|
||||
from .resources.ips import IPsResource, AsyncIPsResource
|
||||
from .resources.ai.ai import AIResource, AsyncAIResource
|
||||
from .resources.d1.d1 import D1Resource, AsyncD1Resource
|
||||
from .resources.kv.kv import KVResource, AsyncKVResource
|
||||
|
|
@ -353,6 +355,12 @@ class Cloudflare(SyncAPIClient):
|
|||
|
||||
return OriginCACertificatesResource(self)
|
||||
|
||||
@cached_property
|
||||
def ips(self) -> IPsResource:
|
||||
from .resources.ips import IPsResource
|
||||
|
||||
return IPsResource(self)
|
||||
|
||||
@cached_property
|
||||
def memberships(self) -> MembershipsResource:
|
||||
from .resources.memberships import MembershipsResource
|
||||
|
|
@ -1179,6 +1187,12 @@ class AsyncCloudflare(AsyncAPIClient):
|
|||
|
||||
return AsyncOriginCACertificatesResource(self)
|
||||
|
||||
@cached_property
|
||||
def ips(self) -> AsyncIPsResource:
|
||||
from .resources.ips import AsyncIPsResource
|
||||
|
||||
return AsyncIPsResource(self)
|
||||
|
||||
@cached_property
|
||||
def memberships(self) -> AsyncMembershipsResource:
|
||||
from .resources.memberships import AsyncMembershipsResource
|
||||
|
|
@ -1933,6 +1947,12 @@ class CloudflareWithRawResponse:
|
|||
|
||||
return OriginCACertificatesResourceWithRawResponse(self._client.origin_ca_certificates)
|
||||
|
||||
@cached_property
|
||||
def ips(self) -> ips.IPsResourceWithRawResponse:
|
||||
from .resources.ips import IPsResourceWithRawResponse
|
||||
|
||||
return IPsResourceWithRawResponse(self._client.ips)
|
||||
|
||||
@cached_property
|
||||
def memberships(self) -> memberships.MembershipsResourceWithRawResponse:
|
||||
from .resources.memberships import MembershipsResourceWithRawResponse
|
||||
|
|
@ -2506,6 +2526,12 @@ class AsyncCloudflareWithRawResponse:
|
|||
|
||||
return AsyncOriginCACertificatesResourceWithRawResponse(self._client.origin_ca_certificates)
|
||||
|
||||
@cached_property
|
||||
def ips(self) -> ips.AsyncIPsResourceWithRawResponse:
|
||||
from .resources.ips import AsyncIPsResourceWithRawResponse
|
||||
|
||||
return AsyncIPsResourceWithRawResponse(self._client.ips)
|
||||
|
||||
@cached_property
|
||||
def memberships(self) -> memberships.AsyncMembershipsResourceWithRawResponse:
|
||||
from .resources.memberships import AsyncMembershipsResourceWithRawResponse
|
||||
|
|
@ -3079,6 +3105,12 @@ class CloudflareWithStreamedResponse:
|
|||
|
||||
return OriginCACertificatesResourceWithStreamingResponse(self._client.origin_ca_certificates)
|
||||
|
||||
@cached_property
|
||||
def ips(self) -> ips.IPsResourceWithStreamingResponse:
|
||||
from .resources.ips import IPsResourceWithStreamingResponse
|
||||
|
||||
return IPsResourceWithStreamingResponse(self._client.ips)
|
||||
|
||||
@cached_property
|
||||
def memberships(self) -> memberships.MembershipsResourceWithStreamingResponse:
|
||||
from .resources.memberships import MembershipsResourceWithStreamingResponse
|
||||
|
|
@ -3652,6 +3684,12 @@ class AsyncCloudflareWithStreamedResponse:
|
|||
|
||||
return AsyncOriginCACertificatesResourceWithStreamingResponse(self._client.origin_ca_certificates)
|
||||
|
||||
@cached_property
|
||||
def ips(self) -> ips.AsyncIPsResourceWithStreamingResponse:
|
||||
from .resources.ips import AsyncIPsResourceWithStreamingResponse
|
||||
|
||||
return AsyncIPsResourceWithStreamingResponse(self._client.ips)
|
||||
|
||||
@cached_property
|
||||
def memberships(self) -> memberships.AsyncMembershipsResourceWithStreamingResponse:
|
||||
from .resources.memberships import AsyncMembershipsResourceWithStreamingResponse
|
||||
|
|
|
|||
194
src/cloudflare/resources/ips.py
Normal file
194
src/cloudflare/resources/ips.py
Normal file
|
|
@ -0,0 +1,194 @@
|
|||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Any, Optional, cast
|
||||
|
||||
import httpx
|
||||
|
||||
from .._types import NOT_GIVEN, Body, Query, Headers, NotGiven
|
||||
from .._utils import maybe_transform, async_maybe_transform
|
||||
from .._compat import cached_property
|
||||
from .._resource import SyncAPIResource, AsyncAPIResource
|
||||
from .._response import (
|
||||
to_raw_response_wrapper,
|
||||
to_streamed_response_wrapper,
|
||||
async_to_raw_response_wrapper,
|
||||
async_to_streamed_response_wrapper,
|
||||
)
|
||||
from .._wrappers import ResultWrapper
|
||||
from ..types.ips import ip_list_params
|
||||
from .._base_client import make_request_options
|
||||
from ..types.ips.ip_list_response import IPListResponse
|
||||
|
||||
__all__ = ["IPsResource", "AsyncIPsResource"]
|
||||
|
||||
|
||||
class IPsResource(SyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> IPsResourceWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return IPsResourceWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> IPsResourceWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response
|
||||
"""
|
||||
return IPsResourceWithStreamingResponse(self)
|
||||
|
||||
def list(
|
||||
self,
|
||||
*,
|
||||
networks: str | NotGiven = NOT_GIVEN,
|
||||
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
||||
# The extra values given here take precedence over values defined on the client or passed to this method.
|
||||
extra_headers: Headers | None = None,
|
||||
extra_query: Query | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> Optional[IPListResponse]:
|
||||
"""
|
||||
Get IPs used on the Cloudflare/JD Cloud network, see
|
||||
https://www.cloudflare.com/ips for Cloudflare IPs or
|
||||
https://developers.cloudflare.com/china-network/reference/infrastructure/ for JD
|
||||
Cloud IPs.
|
||||
|
||||
Args:
|
||||
networks: Specified as `jdcloud` to list IPs used by JD Cloud data centers.
|
||||
|
||||
extra_headers: Send extra headers
|
||||
|
||||
extra_query: Add additional query parameters to the request
|
||||
|
||||
extra_body: Add additional JSON properties to the request
|
||||
|
||||
timeout: Override the client-level default timeout for this request, in seconds
|
||||
"""
|
||||
return cast(
|
||||
Optional[IPListResponse],
|
||||
self._get(
|
||||
"/ips",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=maybe_transform({"networks": networks}, ip_list_params.IPListParams),
|
||||
post_parser=ResultWrapper[Optional[IPListResponse]]._unwrapper,
|
||||
),
|
||||
cast_to=cast(
|
||||
Any, ResultWrapper[IPListResponse]
|
||||
), # Union types cannot be passed in as arguments in the type system
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class AsyncIPsResource(AsyncAPIResource):
|
||||
@cached_property
|
||||
def with_raw_response(self) -> AsyncIPsResourceWithRawResponse:
|
||||
"""
|
||||
This property can be used as a prefix for any HTTP method call to return
|
||||
the raw response object instead of the parsed content.
|
||||
|
||||
For more information, see https://www.github.com/cloudflare/cloudflare-python#accessing-raw-response-data-eg-headers
|
||||
"""
|
||||
return AsyncIPsResourceWithRawResponse(self)
|
||||
|
||||
@cached_property
|
||||
def with_streaming_response(self) -> AsyncIPsResourceWithStreamingResponse:
|
||||
"""
|
||||
An alternative to `.with_raw_response` that doesn't eagerly read the response body.
|
||||
|
||||
For more information, see https://www.github.com/cloudflare/cloudflare-python#with_streaming_response
|
||||
"""
|
||||
return AsyncIPsResourceWithStreamingResponse(self)
|
||||
|
||||
async def list(
|
||||
self,
|
||||
*,
|
||||
networks: str | NotGiven = NOT_GIVEN,
|
||||
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
|
||||
# The extra values given here take precedence over values defined on the client or passed to this method.
|
||||
extra_headers: Headers | None = None,
|
||||
extra_query: Query | None = None,
|
||||
extra_body: Body | None = None,
|
||||
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
|
||||
) -> Optional[IPListResponse]:
|
||||
"""
|
||||
Get IPs used on the Cloudflare/JD Cloud network, see
|
||||
https://www.cloudflare.com/ips for Cloudflare IPs or
|
||||
https://developers.cloudflare.com/china-network/reference/infrastructure/ for JD
|
||||
Cloud IPs.
|
||||
|
||||
Args:
|
||||
networks: Specified as `jdcloud` to list IPs used by JD Cloud data centers.
|
||||
|
||||
extra_headers: Send extra headers
|
||||
|
||||
extra_query: Add additional query parameters to the request
|
||||
|
||||
extra_body: Add additional JSON properties to the request
|
||||
|
||||
timeout: Override the client-level default timeout for this request, in seconds
|
||||
"""
|
||||
return cast(
|
||||
Optional[IPListResponse],
|
||||
await self._get(
|
||||
"/ips",
|
||||
options=make_request_options(
|
||||
extra_headers=extra_headers,
|
||||
extra_query=extra_query,
|
||||
extra_body=extra_body,
|
||||
timeout=timeout,
|
||||
query=await async_maybe_transform({"networks": networks}, ip_list_params.IPListParams),
|
||||
post_parser=ResultWrapper[Optional[IPListResponse]]._unwrapper,
|
||||
),
|
||||
cast_to=cast(
|
||||
Any, ResultWrapper[IPListResponse]
|
||||
), # Union types cannot be passed in as arguments in the type system
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class IPsResourceWithRawResponse:
|
||||
def __init__(self, ips: IPsResource) -> None:
|
||||
self._ips = ips
|
||||
|
||||
self.list = to_raw_response_wrapper(
|
||||
ips.list,
|
||||
)
|
||||
|
||||
|
||||
class AsyncIPsResourceWithRawResponse:
|
||||
def __init__(self, ips: AsyncIPsResource) -> None:
|
||||
self._ips = ips
|
||||
|
||||
self.list = async_to_raw_response_wrapper(
|
||||
ips.list,
|
||||
)
|
||||
|
||||
|
||||
class IPsResourceWithStreamingResponse:
|
||||
def __init__(self, ips: IPsResource) -> None:
|
||||
self._ips = ips
|
||||
|
||||
self.list = to_streamed_response_wrapper(
|
||||
ips.list,
|
||||
)
|
||||
|
||||
|
||||
class AsyncIPsResourceWithStreamingResponse:
|
||||
def __init__(self, ips: AsyncIPsResource) -> None:
|
||||
self._ips = ips
|
||||
|
||||
self.list = async_to_streamed_response_wrapper(
|
||||
ips.list,
|
||||
)
|
||||
|
|
@ -3,3 +3,5 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from .ips import IPs as IPs
|
||||
from .ip_list_params import IPListParams as IPListParams
|
||||
from .ip_list_response import IPListResponse as IPListResponse
|
||||
|
|
|
|||
12
src/cloudflare/types/ips/ip_list_params.py
Normal file
12
src/cloudflare/types/ips/ip_list_params.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
__all__ = ["IPListParams"]
|
||||
|
||||
|
||||
class IPListParams(TypedDict, total=False):
|
||||
networks: str
|
||||
"""Specified as `jdcloud` to list IPs used by JD Cloud data centers."""
|
||||
36
src/cloudflare/types/ips/ip_list_response.py
Normal file
36
src/cloudflare/types/ips/ip_list_response.py
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from typing import List, Union, Optional
|
||||
from typing_extensions import TypeAlias
|
||||
|
||||
from ..._models import BaseModel
|
||||
|
||||
__all__ = ["IPListResponse", "PublicIPIPs", "PublicIPIPsJDCloud"]
|
||||
|
||||
|
||||
class PublicIPIPs(BaseModel):
|
||||
etag: Optional[str] = None
|
||||
"""A digest of the IP data. Useful for determining if the data has changed."""
|
||||
|
||||
ipv4_cidrs: Optional[List[str]] = None
|
||||
"""List of Cloudflare IPv4 CIDR addresses."""
|
||||
|
||||
ipv6_cidrs: Optional[List[str]] = None
|
||||
"""List of Cloudflare IPv6 CIDR addresses."""
|
||||
|
||||
|
||||
class PublicIPIPsJDCloud(BaseModel):
|
||||
etag: Optional[str] = None
|
||||
"""A digest of the IP data. Useful for determining if the data has changed."""
|
||||
|
||||
ipv4_cidrs: Optional[List[str]] = None
|
||||
"""List of Cloudflare IPv4 CIDR addresses."""
|
||||
|
||||
ipv6_cidrs: Optional[List[str]] = None
|
||||
"""List of Cloudflare IPv6 CIDR addresses."""
|
||||
|
||||
jdcloud_cidrs: Optional[List[str]] = None
|
||||
"""List IPv4 and IPv6 CIDRs, only populated if `?networks=jdcloud` is used."""
|
||||
|
||||
|
||||
IPListResponse: TypeAlias = Union[PublicIPIPs, PublicIPIPsJDCloud]
|
||||
86
tests/api_resources/test_ips.py
Normal file
86
tests/api_resources/test_ips.py
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from typing import Any, Optional, cast
|
||||
|
||||
import pytest
|
||||
|
||||
from cloudflare import Cloudflare, AsyncCloudflare
|
||||
from tests.utils import assert_matches_type
|
||||
from cloudflare.types.ips import IPListResponse
|
||||
|
||||
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
|
||||
|
||||
|
||||
class TestIPs:
|
||||
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
|
||||
|
||||
@parametrize
|
||||
def test_method_list(self, client: Cloudflare) -> None:
|
||||
ip = client.ips.list()
|
||||
assert_matches_type(Optional[IPListResponse], ip, path=["response"])
|
||||
|
||||
@parametrize
|
||||
def test_method_list_with_all_params(self, client: Cloudflare) -> None:
|
||||
ip = client.ips.list(
|
||||
networks="networks",
|
||||
)
|
||||
assert_matches_type(Optional[IPListResponse], ip, path=["response"])
|
||||
|
||||
@parametrize
|
||||
def test_raw_response_list(self, client: Cloudflare) -> None:
|
||||
response = client.ips.with_raw_response.list()
|
||||
|
||||
assert response.is_closed is True
|
||||
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
||||
ip = response.parse()
|
||||
assert_matches_type(Optional[IPListResponse], ip, path=["response"])
|
||||
|
||||
@parametrize
|
||||
def test_streaming_response_list(self, client: Cloudflare) -> None:
|
||||
with client.ips.with_streaming_response.list() as response:
|
||||
assert not response.is_closed
|
||||
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
||||
|
||||
ip = response.parse()
|
||||
assert_matches_type(Optional[IPListResponse], ip, path=["response"])
|
||||
|
||||
assert cast(Any, response.is_closed) is True
|
||||
|
||||
|
||||
class TestAsyncIPs:
|
||||
parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
|
||||
|
||||
@parametrize
|
||||
async def test_method_list(self, async_client: AsyncCloudflare) -> None:
|
||||
ip = await async_client.ips.list()
|
||||
assert_matches_type(Optional[IPListResponse], ip, path=["response"])
|
||||
|
||||
@parametrize
|
||||
async def test_method_list_with_all_params(self, async_client: AsyncCloudflare) -> None:
|
||||
ip = await async_client.ips.list(
|
||||
networks="networks",
|
||||
)
|
||||
assert_matches_type(Optional[IPListResponse], ip, path=["response"])
|
||||
|
||||
@parametrize
|
||||
async def test_raw_response_list(self, async_client: AsyncCloudflare) -> None:
|
||||
response = await async_client.ips.with_raw_response.list()
|
||||
|
||||
assert response.is_closed is True
|
||||
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
||||
ip = await response.parse()
|
||||
assert_matches_type(Optional[IPListResponse], ip, path=["response"])
|
||||
|
||||
@parametrize
|
||||
async def test_streaming_response_list(self, async_client: AsyncCloudflare) -> None:
|
||||
async with async_client.ips.with_streaming_response.list() as response:
|
||||
assert not response.is_closed
|
||||
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
|
||||
|
||||
ip = await response.parse()
|
||||
assert_matches_type(Optional[IPListResponse], ip, path=["response"])
|
||||
|
||||
assert cast(Any, response.is_closed) is True
|
||||
Loading…
Add table
Reference in a new issue