diff --git a/src/cloudflare/resources/waiting_rooms/rules.py b/src/cloudflare/resources/waiting_rooms/rules.py index f0066f6d28a..70c25bb8a91 100644 --- a/src/cloudflare/resources/waiting_rooms/rules.py +++ b/src/cloudflare/resources/waiting_rooms/rules.py @@ -57,10 +57,7 @@ def create( waiting_room_id: str, *, zone_id: str, - action: Literal["bypass_waiting_room"], - expression: str, - description: str | NotGiven = NOT_GIVEN, - enabled: bool | NotGiven = NOT_GIVEN, + rules: rule_create_params.Rules, # 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, @@ -76,14 +73,6 @@ def create( Args: zone_id: Identifier - action: The action to take when the expression matches. - - expression: Criteria defining when there is a match for the current rule. - - description: The description of the rule. - - enabled: When set to true, the rule is enabled. - extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -98,15 +87,7 @@ def create( raise ValueError(f"Expected a non-empty value for `waiting_room_id` but received {waiting_room_id!r}") return self._post( f"/zones/{zone_id}/waiting_rooms/{waiting_room_id}/rules", - body=maybe_transform( - { - "action": action, - "expression": expression, - "description": description, - "enabled": enabled, - }, - rule_create_params.RuleCreateParams, - ), + body=maybe_transform(rules, rule_create_params.RuleCreateParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -122,7 +103,7 @@ def update( waiting_room_id: str, *, zone_id: str, - body: Iterable[rule_update_params.Body], + rules: Iterable[rule_update_params.Rule], # 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, @@ -152,7 +133,7 @@ def update( raise ValueError(f"Expected a non-empty value for `waiting_room_id` but received {waiting_room_id!r}") return self._put( f"/zones/{zone_id}/waiting_rooms/{waiting_room_id}/rules", - body=maybe_transform(body, Iterable[rule_update_params.Body]), + body=maybe_transform(rules, Iterable[rule_update_params.Rule]), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -350,10 +331,7 @@ async def create( waiting_room_id: str, *, zone_id: str, - action: Literal["bypass_waiting_room"], - expression: str, - description: str | NotGiven = NOT_GIVEN, - enabled: bool | NotGiven = NOT_GIVEN, + rules: rule_create_params.Rules, # 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, @@ -369,14 +347,6 @@ async def create( Args: zone_id: Identifier - action: The action to take when the expression matches. - - expression: Criteria defining when there is a match for the current rule. - - description: The description of the rule. - - enabled: When set to true, the rule is enabled. - extra_headers: Send extra headers extra_query: Add additional query parameters to the request @@ -391,15 +361,7 @@ async def create( raise ValueError(f"Expected a non-empty value for `waiting_room_id` but received {waiting_room_id!r}") return await self._post( f"/zones/{zone_id}/waiting_rooms/{waiting_room_id}/rules", - body=await async_maybe_transform( - { - "action": action, - "expression": expression, - "description": description, - "enabled": enabled, - }, - rule_create_params.RuleCreateParams, - ), + body=await async_maybe_transform(rules, rule_create_params.RuleCreateParams), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -415,7 +377,7 @@ async def update( waiting_room_id: str, *, zone_id: str, - body: Iterable[rule_update_params.Body], + rules: Iterable[rule_update_params.Rule], # 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, @@ -445,7 +407,7 @@ async def update( raise ValueError(f"Expected a non-empty value for `waiting_room_id` but received {waiting_room_id!r}") return await self._put( f"/zones/{zone_id}/waiting_rooms/{waiting_room_id}/rules", - body=await async_maybe_transform(body, Iterable[rule_update_params.Body]), + body=await async_maybe_transform(rules, Iterable[rule_update_params.Rule]), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, diff --git a/src/cloudflare/types/waiting_rooms/rule_create_params.py b/src/cloudflare/types/waiting_rooms/rule_create_params.py index d86f7db2a61..be70f6c047b 100644 --- a/src/cloudflare/types/waiting_rooms/rule_create_params.py +++ b/src/cloudflare/types/waiting_rooms/rule_create_params.py @@ -4,13 +4,17 @@ from typing_extensions import Literal, Required, TypedDict -__all__ = ["RuleCreateParams"] +__all__ = ["RuleCreateParams", "Rules"] class RuleCreateParams(TypedDict, total=False): zone_id: Required[str] """Identifier""" + rules: Required[Rules] + + +class Rules(TypedDict, total=False): action: Required[Literal["bypass_waiting_room"]] """The action to take when the expression matches.""" diff --git a/src/cloudflare/types/waiting_rooms/rule_update_params.py b/src/cloudflare/types/waiting_rooms/rule_update_params.py index 57a22f8d87b..8c2811d1a99 100644 --- a/src/cloudflare/types/waiting_rooms/rule_update_params.py +++ b/src/cloudflare/types/waiting_rooms/rule_update_params.py @@ -5,17 +5,17 @@ from typing import Iterable from typing_extensions import Literal, Required, TypedDict -__all__ = ["RuleUpdateParams", "Body"] +__all__ = ["RuleUpdateParams", "Rule"] class RuleUpdateParams(TypedDict, total=False): zone_id: Required[str] """Identifier""" - body: Required[Iterable[Body]] + rules: Required[Iterable[Rule]] -class Body(TypedDict, total=False): +class Rule(TypedDict, total=False): action: Required[Literal["bypass_waiting_room"]] """The action to take when the expression matches.""" diff --git a/tests/api_resources/waiting_rooms/test_rules.py b/tests/api_resources/waiting_rooms/test_rules.py index 872d11a81fd..da354510ae9 100644 --- a/tests/api_resources/waiting_rooms/test_rules.py +++ b/tests/api_resources/waiting_rooms/test_rules.py @@ -28,8 +28,10 @@ def test_method_create(self, client: Cloudflare) -> None: rule = client.waiting_rooms.rules.create( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - action="bypass_waiting_room", - expression="ip.src in {10.20.30.40}", + rules={ + "action": "bypass_waiting_room", + "expression": "ip.src in {10.20.30.40}", + }, ) assert_matches_type(Optional[RuleCreateResponse], rule, path=["response"]) @@ -38,10 +40,12 @@ def test_method_create_with_all_params(self, client: Cloudflare) -> None: rule = client.waiting_rooms.rules.create( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - action="bypass_waiting_room", - expression="ip.src in {10.20.30.40}", - description="allow all traffic from 10.20.30.40", - enabled=True, + rules={ + "action": "bypass_waiting_room", + "expression": "ip.src in {10.20.30.40}", + "description": "allow all traffic from 10.20.30.40", + "enabled": True, + }, ) assert_matches_type(Optional[RuleCreateResponse], rule, path=["response"]) @@ -50,8 +54,10 @@ def test_raw_response_create(self, client: Cloudflare) -> None: response = client.waiting_rooms.rules.with_raw_response.create( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - action="bypass_waiting_room", - expression="ip.src in {10.20.30.40}", + rules={ + "action": "bypass_waiting_room", + "expression": "ip.src in {10.20.30.40}", + }, ) assert response.is_closed is True @@ -64,8 +70,10 @@ def test_streaming_response_create(self, client: Cloudflare) -> None: with client.waiting_rooms.rules.with_streaming_response.create( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - action="bypass_waiting_room", - expression="ip.src in {10.20.30.40}", + rules={ + "action": "bypass_waiting_room", + "expression": "ip.src in {10.20.30.40}", + }, ) as response: assert not response.is_closed assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -81,16 +89,20 @@ def test_path_params_create(self, client: Cloudflare) -> None: client.waiting_rooms.rules.with_raw_response.create( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="", - action="bypass_waiting_room", - expression="ip.src in {10.20.30.40}", + rules={ + "action": "bypass_waiting_room", + "expression": "ip.src in {10.20.30.40}", + }, ) with pytest.raises(ValueError, match=r"Expected a non-empty value for `waiting_room_id` but received ''"): client.waiting_rooms.rules.with_raw_response.create( waiting_room_id="", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - action="bypass_waiting_room", - expression="ip.src in {10.20.30.40}", + rules={ + "action": "bypass_waiting_room", + "expression": "ip.src in {10.20.30.40}", + }, ) @parametrize @@ -98,7 +110,7 @@ def test_method_update(self, client: Cloudflare) -> None: rule = client.waiting_rooms.rules.update( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - body=[ + rules=[ { "action": "bypass_waiting_room", "expression": "ip.src in {10.20.30.40}", @@ -120,7 +132,7 @@ def test_raw_response_update(self, client: Cloudflare) -> None: response = client.waiting_rooms.rules.with_raw_response.update( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - body=[ + rules=[ { "action": "bypass_waiting_room", "expression": "ip.src in {10.20.30.40}", @@ -146,7 +158,7 @@ def test_streaming_response_update(self, client: Cloudflare) -> None: with client.waiting_rooms.rules.with_streaming_response.update( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - body=[ + rules=[ { "action": "bypass_waiting_room", "expression": "ip.src in {10.20.30.40}", @@ -175,7 +187,7 @@ def test_path_params_update(self, client: Cloudflare) -> None: client.waiting_rooms.rules.with_raw_response.update( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="", - body=[ + rules=[ { "action": "bypass_waiting_room", "expression": "ip.src in {10.20.30.40}", @@ -195,7 +207,7 @@ def test_path_params_update(self, client: Cloudflare) -> None: client.waiting_rooms.rules.with_raw_response.update( waiting_room_id="", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - body=[ + rules=[ { "action": "bypass_waiting_room", "expression": "ip.src in {10.20.30.40}", @@ -414,8 +426,10 @@ async def test_method_create(self, async_client: AsyncCloudflare) -> None: rule = await async_client.waiting_rooms.rules.create( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - action="bypass_waiting_room", - expression="ip.src in {10.20.30.40}", + rules={ + "action": "bypass_waiting_room", + "expression": "ip.src in {10.20.30.40}", + }, ) assert_matches_type(Optional[RuleCreateResponse], rule, path=["response"]) @@ -424,10 +438,12 @@ async def test_method_create_with_all_params(self, async_client: AsyncCloudflare rule = await async_client.waiting_rooms.rules.create( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - action="bypass_waiting_room", - expression="ip.src in {10.20.30.40}", - description="allow all traffic from 10.20.30.40", - enabled=True, + rules={ + "action": "bypass_waiting_room", + "expression": "ip.src in {10.20.30.40}", + "description": "allow all traffic from 10.20.30.40", + "enabled": True, + }, ) assert_matches_type(Optional[RuleCreateResponse], rule, path=["response"]) @@ -436,8 +452,10 @@ async def test_raw_response_create(self, async_client: AsyncCloudflare) -> None: response = await async_client.waiting_rooms.rules.with_raw_response.create( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - action="bypass_waiting_room", - expression="ip.src in {10.20.30.40}", + rules={ + "action": "bypass_waiting_room", + "expression": "ip.src in {10.20.30.40}", + }, ) assert response.is_closed is True @@ -450,8 +468,10 @@ async def test_streaming_response_create(self, async_client: AsyncCloudflare) -> async with async_client.waiting_rooms.rules.with_streaming_response.create( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - action="bypass_waiting_room", - expression="ip.src in {10.20.30.40}", + rules={ + "action": "bypass_waiting_room", + "expression": "ip.src in {10.20.30.40}", + }, ) as response: assert not response.is_closed assert response.http_request.headers.get("X-Stainless-Lang") == "python" @@ -467,16 +487,20 @@ async def test_path_params_create(self, async_client: AsyncCloudflare) -> None: await async_client.waiting_rooms.rules.with_raw_response.create( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="", - action="bypass_waiting_room", - expression="ip.src in {10.20.30.40}", + rules={ + "action": "bypass_waiting_room", + "expression": "ip.src in {10.20.30.40}", + }, ) with pytest.raises(ValueError, match=r"Expected a non-empty value for `waiting_room_id` but received ''"): await async_client.waiting_rooms.rules.with_raw_response.create( waiting_room_id="", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - action="bypass_waiting_room", - expression="ip.src in {10.20.30.40}", + rules={ + "action": "bypass_waiting_room", + "expression": "ip.src in {10.20.30.40}", + }, ) @parametrize @@ -484,7 +508,7 @@ async def test_method_update(self, async_client: AsyncCloudflare) -> None: rule = await async_client.waiting_rooms.rules.update( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - body=[ + rules=[ { "action": "bypass_waiting_room", "expression": "ip.src in {10.20.30.40}", @@ -506,7 +530,7 @@ async def test_raw_response_update(self, async_client: AsyncCloudflare) -> None: response = await async_client.waiting_rooms.rules.with_raw_response.update( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - body=[ + rules=[ { "action": "bypass_waiting_room", "expression": "ip.src in {10.20.30.40}", @@ -532,7 +556,7 @@ async def test_streaming_response_update(self, async_client: AsyncCloudflare) -> async with async_client.waiting_rooms.rules.with_streaming_response.update( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - body=[ + rules=[ { "action": "bypass_waiting_room", "expression": "ip.src in {10.20.30.40}", @@ -561,7 +585,7 @@ async def test_path_params_update(self, async_client: AsyncCloudflare) -> None: await async_client.waiting_rooms.rules.with_raw_response.update( waiting_room_id="699d98642c564d2e855e9661899b7252", zone_id="", - body=[ + rules=[ { "action": "bypass_waiting_room", "expression": "ip.src in {10.20.30.40}", @@ -581,7 +605,7 @@ async def test_path_params_update(self, async_client: AsyncCloudflare) -> None: await async_client.waiting_rooms.rules.with_raw_response.update( waiting_room_id="", zone_id="023e105f4ecef8ad9ca31a8372d0c353", - body=[ + rules=[ { "action": "bypass_waiting_room", "expression": "ip.src in {10.20.30.40}",