From 17db44d1b1a346c9e4fcb098a18133cc96a2b4de Mon Sep 17 00:00:00 2001 From: "stainless-app[bot]" <142633134+stainless-app[bot]@users.noreply.github.com> Date: Wed, 18 Dec 2024 18:22:58 +0000 Subject: [PATCH] feat(api): api update (#2294) --- .stats.yml | 2 +- api.md | 2 +- .../resources/zero_trust/devices/devices.py | 52 +++++------- .../types/zero_trust/device_get_response.py | 83 ++++++++++++++++++- .../api_resources/zero_trust/test_devices.py | 14 ++-- 5 files changed, 109 insertions(+), 44 deletions(-) diff --git a/.stats.yml b/.stats.yml index f64843a1f6b..0fd6947ad9f 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ configured_endpoints: 1480 -openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-64d4fa2d88511612fbb26659965c2b7b2d016b10e3a96a786e93066817865e4f.yml +openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-405af13ac696c25ab9d54a26786eab9bf02e2c2ff817a7ec01a454056dda053c.yml diff --git a/api.md b/api.md index 221b4fd89f9..71a8328721d 100644 --- a/api.md +++ b/api.md @@ -4811,7 +4811,7 @@ from cloudflare.types.zero_trust import Device, DeviceGetResponse Methods: - client.zero_trust.devices.list(\*, account_id) -> SyncSinglePage[Device] -- client.zero_trust.devices.get(device_id, \*, account_id) -> DeviceGetResponse +- client.zero_trust.devices.get(device_id, \*, account_id) -> Optional[DeviceGetResponse] ### DEXTests diff --git a/src/cloudflare/resources/zero_trust/devices/devices.py b/src/cloudflare/resources/zero_trust/devices/devices.py index 3b946277c22..cdb59f224e5 100644 --- a/src/cloudflare/resources/zero_trust/devices/devices.py +++ b/src/cloudflare/resources/zero_trust/devices/devices.py @@ -2,7 +2,7 @@ from __future__ import annotations -from typing import Any, cast +from typing import Type, Optional, cast import httpx @@ -197,7 +197,7 @@ def get( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> DeviceGetResponse: + ) -> Optional[DeviceGetResponse]: """ Fetches details for a single device. @@ -216,21 +216,16 @@ def get( raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") if not device_id: raise ValueError(f"Expected a non-empty value for `device_id` but received {device_id!r}") - return cast( - DeviceGetResponse, - self._get( - f"/accounts/{account_id}/devices/{device_id}", - options=make_request_options( - extra_headers=extra_headers, - extra_query=extra_query, - extra_body=extra_body, - timeout=timeout, - post_parser=ResultWrapper[DeviceGetResponse]._unwrapper, - ), - cast_to=cast( - Any, ResultWrapper[DeviceGetResponse] - ), # Union types cannot be passed in as arguments in the type system + return self._get( + f"/accounts/{account_id}/devices/{device_id}", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[Optional[DeviceGetResponse]]._unwrapper, ), + cast_to=cast(Type[Optional[DeviceGetResponse]], ResultWrapper[DeviceGetResponse]), ) @@ -335,7 +330,7 @@ async def get( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, - ) -> DeviceGetResponse: + ) -> Optional[DeviceGetResponse]: """ Fetches details for a single device. @@ -354,21 +349,16 @@ async def get( raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") if not device_id: raise ValueError(f"Expected a non-empty value for `device_id` but received {device_id!r}") - return cast( - DeviceGetResponse, - await self._get( - f"/accounts/{account_id}/devices/{device_id}", - options=make_request_options( - extra_headers=extra_headers, - extra_query=extra_query, - extra_body=extra_body, - timeout=timeout, - post_parser=ResultWrapper[DeviceGetResponse]._unwrapper, - ), - cast_to=cast( - Any, ResultWrapper[DeviceGetResponse] - ), # Union types cannot be passed in as arguments in the type system + return await self._get( + f"/accounts/{account_id}/devices/{device_id}", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[Optional[DeviceGetResponse]]._unwrapper, ), + cast_to=cast(Type[Optional[DeviceGetResponse]], ResultWrapper[DeviceGetResponse]), ) diff --git a/src/cloudflare/types/zero_trust/device_get_response.py b/src/cloudflare/types/zero_trust/device_get_response.py index 0b11c5ec1cc..12ecc5f039a 100644 --- a/src/cloudflare/types/zero_trust/device_get_response.py +++ b/src/cloudflare/types/zero_trust/device_get_response.py @@ -1,8 +1,83 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. -from typing import Union, Optional -from typing_extensions import TypeAlias +from typing import Optional +from datetime import datetime -__all__ = ["DeviceGetResponse"] +from ..._models import BaseModel -DeviceGetResponse: TypeAlias = Union[Optional[str], Optional[object]] +__all__ = ["DeviceGetResponse", "Account", "User"] + + +class Account(BaseModel): + id: Optional[str] = None + + account_type: Optional[str] = None + + name: Optional[str] = None + """The name of the enrolled account.""" + + +class User(BaseModel): + id: Optional[str] = None + """UUID""" + + email: Optional[str] = None + """The contact email address of the user.""" + + name: Optional[str] = None + """The enrolled device user's name.""" + + +class DeviceGetResponse(BaseModel): + id: Optional[str] = None + """Device ID.""" + + account: Optional[Account] = None + + created: Optional[datetime] = None + """When the device was created.""" + + deleted: Optional[bool] = None + """True if the device was deleted.""" + + device_type: Optional[str] = None + + gateway_device_id: Optional[str] = None + + ip: Optional[str] = None + """IPv4 or IPv6 address.""" + + key: Optional[str] = None + """The device's public key.""" + + key_type: Optional[str] = None + """Type of the key.""" + + last_seen: Optional[datetime] = None + """When the device last connected to Cloudflare services.""" + + mac_address: Optional[str] = None + """The device mac address.""" + + model: Optional[str] = None + """The device model name.""" + + name: Optional[str] = None + """The device name.""" + + os_version: Optional[str] = None + """The operating system version.""" + + serial_number: Optional[str] = None + """The device serial number.""" + + tunnel_type: Optional[str] = None + """Type of the tunnel connection used.""" + + updated: Optional[datetime] = None + """When the device was updated.""" + + user: Optional[User] = None + + version: Optional[str] = None + """The WARP client version.""" diff --git a/tests/api_resources/zero_trust/test_devices.py b/tests/api_resources/zero_trust/test_devices.py index f814c7c80bc..e806fd8d30e 100644 --- a/tests/api_resources/zero_trust/test_devices.py +++ b/tests/api_resources/zero_trust/test_devices.py @@ -3,7 +3,7 @@ from __future__ import annotations import os -from typing import Any, cast +from typing import Any, Optional, cast import pytest @@ -62,7 +62,7 @@ def test_method_get(self, client: Cloudflare) -> None: device_id="f174e90a-fafe-4643-bbbc-4a0ed4fc8415", account_id="699d98642c564d2e855e9661899b7252", ) - assert_matches_type(DeviceGetResponse, device, path=["response"]) + assert_matches_type(Optional[DeviceGetResponse], device, path=["response"]) @parametrize def test_raw_response_get(self, client: Cloudflare) -> None: @@ -74,7 +74,7 @@ def test_raw_response_get(self, client: Cloudflare) -> None: assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" device = response.parse() - assert_matches_type(DeviceGetResponse, device, path=["response"]) + assert_matches_type(Optional[DeviceGetResponse], device, path=["response"]) @parametrize def test_streaming_response_get(self, client: Cloudflare) -> None: @@ -86,7 +86,7 @@ def test_streaming_response_get(self, client: Cloudflare) -> None: assert response.http_request.headers.get("X-Stainless-Lang") == "python" device = response.parse() - assert_matches_type(DeviceGetResponse, device, path=["response"]) + assert_matches_type(Optional[DeviceGetResponse], device, path=["response"]) assert cast(Any, response.is_closed) is True @@ -152,7 +152,7 @@ async def test_method_get(self, async_client: AsyncCloudflare) -> None: device_id="f174e90a-fafe-4643-bbbc-4a0ed4fc8415", account_id="699d98642c564d2e855e9661899b7252", ) - assert_matches_type(DeviceGetResponse, device, path=["response"]) + assert_matches_type(Optional[DeviceGetResponse], device, path=["response"]) @parametrize async def test_raw_response_get(self, async_client: AsyncCloudflare) -> None: @@ -164,7 +164,7 @@ async def test_raw_response_get(self, async_client: AsyncCloudflare) -> None: assert response.is_closed is True assert response.http_request.headers.get("X-Stainless-Lang") == "python" device = await response.parse() - assert_matches_type(DeviceGetResponse, device, path=["response"]) + assert_matches_type(Optional[DeviceGetResponse], device, path=["response"]) @parametrize async def test_streaming_response_get(self, async_client: AsyncCloudflare) -> None: @@ -176,7 +176,7 @@ async def test_streaming_response_get(self, async_client: AsyncCloudflare) -> No assert response.http_request.headers.get("X-Stainless-Lang") == "python" device = await response.parse() - assert_matches_type(DeviceGetResponse, device, path=["response"]) + assert_matches_type(Optional[DeviceGetResponse], device, path=["response"]) assert cast(Any, response.is_closed) is True