diff --git a/.stats.yml b/.stats.yml index ab5ab2be2f8..5b02944f435 100644 --- a/.stats.yml +++ b/.stats.yml @@ -1,2 +1,2 @@ -configured_endpoints: 1454 +configured_endpoints: 1460 openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-24f32ff8cc230aecb28b850e99ed99f6f66fba898e64194d21052c4c2b869a24.yml diff --git a/api.md b/api.md index ff85e76fa88..c4919ec3bca 100644 --- a/api.md +++ b/api.md @@ -8353,3 +8353,46 @@ Methods: - client.leaked_credential_checks.detections.update(detection_id, \*, zone_id, \*\*params) -> DetectionUpdateResponse - client.leaked_credential_checks.detections.list(\*, zone_id) -> SyncSinglePage[DetectionListResponse] - client.leaked_credential_checks.detections.delete(detection_id, \*, zone_id) -> object + +# ContentScanning + +Types: + +```python +from cloudflare.types import ContentScanningDisableResponse, ContentScanningEnableResponse +``` + +Methods: + +- client.content_scanning.disable(\*, zone_id) -> object +- client.content_scanning.enable(\*, zone_id) -> object + +## Payloads + +Types: + +```python +from cloudflare.types.content_scanning import ( + PayloadCreateResponse, + PayloadListResponse, + PayloadDeleteResponse, +) +``` + +Methods: + +- client.content_scanning.payloads.create(\*, zone_id, \*\*params) -> Optional[PayloadCreateResponse] +- client.content_scanning.payloads.list(\*, zone_id) -> SyncSinglePage[PayloadListResponse] +- client.content_scanning.payloads.delete(expression_id, \*, zone_id) -> Optional[PayloadDeleteResponse] + +## Settings + +Types: + +```python +from cloudflare.types.content_scanning import SettingGetResponse +``` + +Methods: + +- client.content_scanning.settings.get(\*, zone_id) -> SettingGetResponse diff --git a/src/cloudflare/_client.py b/src/cloudflare/_client.py index 37df5ff4515..8e6dd6070e4 100644 --- a/src/cloudflare/_client.py +++ b/src/cloudflare/_client.py @@ -103,6 +103,7 @@ durable_objects, request_tracers, brand_protection, + content_scanning, custom_hostnames, resource_sharing, mtls_certificates, @@ -704,6 +705,12 @@ def leaked_credential_checks(self) -> leaked_credential_checks.LeakedCredentialC return LeakedCredentialChecksResource(self) + @cached_property + def content_scanning(self) -> content_scanning.ContentScanningResource: + from .resources.content_scanning import ContentScanningResource + + return ContentScanningResource(self) + @cached_property def with_raw_response(self) -> CloudflareWithRawResponse: return CloudflareWithRawResponse(self) @@ -1457,6 +1464,12 @@ def leaked_credential_checks(self) -> leaked_credential_checks.AsyncLeakedCreden return AsyncLeakedCredentialChecksResource(self) + @cached_property + def content_scanning(self) -> content_scanning.AsyncContentScanningResource: + from .resources.content_scanning import AsyncContentScanningResource + + return AsyncContentScanningResource(self) + @cached_property def with_raw_response(self) -> AsyncCloudflareWithRawResponse: return AsyncCloudflareWithRawResponse(self) @@ -2145,6 +2158,12 @@ def leaked_credential_checks(self) -> leaked_credential_checks.LeakedCredentialC return LeakedCredentialChecksResourceWithRawResponse(self._client.leaked_credential_checks) + @cached_property + def content_scanning(self) -> content_scanning.ContentScanningResourceWithRawResponse: + from .resources.content_scanning import ContentScanningResourceWithRawResponse + + return ContentScanningResourceWithRawResponse(self._client.content_scanning) + class AsyncCloudflareWithRawResponse: _client: AsyncCloudflare @@ -2652,6 +2671,12 @@ def leaked_credential_checks(self) -> leaked_credential_checks.AsyncLeakedCreden return AsyncLeakedCredentialChecksResourceWithRawResponse(self._client.leaked_credential_checks) + @cached_property + def content_scanning(self) -> content_scanning.AsyncContentScanningResourceWithRawResponse: + from .resources.content_scanning import AsyncContentScanningResourceWithRawResponse + + return AsyncContentScanningResourceWithRawResponse(self._client.content_scanning) + class CloudflareWithStreamedResponse: _client: Cloudflare @@ -3159,6 +3184,12 @@ def leaked_credential_checks(self) -> leaked_credential_checks.LeakedCredentialC return LeakedCredentialChecksResourceWithStreamingResponse(self._client.leaked_credential_checks) + @cached_property + def content_scanning(self) -> content_scanning.ContentScanningResourceWithStreamingResponse: + from .resources.content_scanning import ContentScanningResourceWithStreamingResponse + + return ContentScanningResourceWithStreamingResponse(self._client.content_scanning) + class AsyncCloudflareWithStreamedResponse: _client: AsyncCloudflare @@ -3676,6 +3707,12 @@ def leaked_credential_checks( return AsyncLeakedCredentialChecksResourceWithStreamingResponse(self._client.leaked_credential_checks) + @cached_property + def content_scanning(self) -> content_scanning.AsyncContentScanningResourceWithStreamingResponse: + from .resources.content_scanning import AsyncContentScanningResourceWithStreamingResponse + + return AsyncContentScanningResourceWithStreamingResponse(self._client.content_scanning) + Client = Cloudflare diff --git a/src/cloudflare/resources/__init__.py b/src/cloudflare/resources/__init__.py index e8dc62443c5..6f8805dad21 100644 --- a/src/cloudflare/resources/__init__.py +++ b/src/cloudflare/resources/__init__.py @@ -1,5 +1,13 @@ # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. +from .content_scanning import ( + ContentScanningResource, + AsyncContentScanningResource, + ContentScanningResourceWithRawResponse, + AsyncContentScanningResourceWithRawResponse, + ContentScanningResourceWithStreamingResponse, + AsyncContentScanningResourceWithStreamingResponse, +) from .leaked_credential_checks import ( LeakedCredentialChecksResource, AsyncLeakedCredentialChecksResource, @@ -16,4 +24,10 @@ "AsyncLeakedCredentialChecksResourceWithRawResponse", "LeakedCredentialChecksResourceWithStreamingResponse", "AsyncLeakedCredentialChecksResourceWithStreamingResponse", + "ContentScanningResource", + "AsyncContentScanningResource", + "ContentScanningResourceWithRawResponse", + "AsyncContentScanningResourceWithRawResponse", + "ContentScanningResourceWithStreamingResponse", + "AsyncContentScanningResourceWithStreamingResponse", ] diff --git a/src/cloudflare/resources/content_scanning/__init__.py b/src/cloudflare/resources/content_scanning/__init__.py new file mode 100644 index 00000000000..d5da68aef92 --- /dev/null +++ b/src/cloudflare/resources/content_scanning/__init__.py @@ -0,0 +1,47 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from .payloads import ( + PayloadsResource, + AsyncPayloadsResource, + PayloadsResourceWithRawResponse, + AsyncPayloadsResourceWithRawResponse, + PayloadsResourceWithStreamingResponse, + AsyncPayloadsResourceWithStreamingResponse, +) +from .settings import ( + SettingsResource, + AsyncSettingsResource, + SettingsResourceWithRawResponse, + AsyncSettingsResourceWithRawResponse, + SettingsResourceWithStreamingResponse, + AsyncSettingsResourceWithStreamingResponse, +) +from .content_scanning import ( + ContentScanningResource, + AsyncContentScanningResource, + ContentScanningResourceWithRawResponse, + AsyncContentScanningResourceWithRawResponse, + ContentScanningResourceWithStreamingResponse, + AsyncContentScanningResourceWithStreamingResponse, +) + +__all__ = [ + "PayloadsResource", + "AsyncPayloadsResource", + "PayloadsResourceWithRawResponse", + "AsyncPayloadsResourceWithRawResponse", + "PayloadsResourceWithStreamingResponse", + "AsyncPayloadsResourceWithStreamingResponse", + "SettingsResource", + "AsyncSettingsResource", + "SettingsResourceWithRawResponse", + "AsyncSettingsResourceWithRawResponse", + "SettingsResourceWithStreamingResponse", + "AsyncSettingsResourceWithStreamingResponse", + "ContentScanningResource", + "AsyncContentScanningResource", + "ContentScanningResourceWithRawResponse", + "AsyncContentScanningResourceWithRawResponse", + "ContentScanningResourceWithStreamingResponse", + "AsyncContentScanningResourceWithStreamingResponse", +] diff --git a/src/cloudflare/resources/content_scanning/content_scanning.py b/src/cloudflare/resources/content_scanning/content_scanning.py new file mode 100644 index 00000000000..d649fca7142 --- /dev/null +++ b/src/cloudflare/resources/content_scanning/content_scanning.py @@ -0,0 +1,331 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Type, cast + +import httpx + +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven +from .payloads import ( + PayloadsResource, + AsyncPayloadsResource, + PayloadsResourceWithRawResponse, + AsyncPayloadsResourceWithRawResponse, + PayloadsResourceWithStreamingResponse, + AsyncPayloadsResourceWithStreamingResponse, +) +from .settings import ( + SettingsResource, + AsyncSettingsResource, + SettingsResourceWithRawResponse, + AsyncSettingsResourceWithRawResponse, + SettingsResourceWithStreamingResponse, + AsyncSettingsResourceWithStreamingResponse, +) +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 ..._base_client import make_request_options + +__all__ = ["ContentScanningResource", "AsyncContentScanningResource"] + + +class ContentScanningResource(SyncAPIResource): + @cached_property + def payloads(self) -> PayloadsResource: + return PayloadsResource(self._client) + + @cached_property + def settings(self) -> SettingsResource: + return SettingsResource(self._client) + + @cached_property + def with_raw_response(self) -> ContentScanningResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + 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 ContentScanningResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> ContentScanningResourceWithStreamingResponse: + """ + 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 ContentScanningResourceWithStreamingResponse(self) + + def disable( + self, + *, + zone_id: str, + # 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, + ) -> object: + """ + Disable Content Scanning + + Args: + zone_id: Identifier + + 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 + """ + if not zone_id: + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") + return self._post( + f"/zones/{zone_id}/content-upload-scan/disable", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[object]._unwrapper, + ), + cast_to=cast(Type[object], ResultWrapper[object]), + ) + + def enable( + self, + *, + zone_id: str, + # 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, + ) -> object: + """ + Enable Content Scanning + + Args: + zone_id: Identifier + + 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 + """ + if not zone_id: + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") + return self._post( + f"/zones/{zone_id}/content-upload-scan/enable", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[object]._unwrapper, + ), + cast_to=cast(Type[object], ResultWrapper[object]), + ) + + +class AsyncContentScanningResource(AsyncAPIResource): + @cached_property + def payloads(self) -> AsyncPayloadsResource: + return AsyncPayloadsResource(self._client) + + @cached_property + def settings(self) -> AsyncSettingsResource: + return AsyncSettingsResource(self._client) + + @cached_property + def with_raw_response(self) -> AsyncContentScanningResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + 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 AsyncContentScanningResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncContentScanningResourceWithStreamingResponse: + """ + 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 AsyncContentScanningResourceWithStreamingResponse(self) + + async def disable( + self, + *, + zone_id: str, + # 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, + ) -> object: + """ + Disable Content Scanning + + Args: + zone_id: Identifier + + 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 + """ + if not zone_id: + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") + return await self._post( + f"/zones/{zone_id}/content-upload-scan/disable", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[object]._unwrapper, + ), + cast_to=cast(Type[object], ResultWrapper[object]), + ) + + async def enable( + self, + *, + zone_id: str, + # 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, + ) -> object: + """ + Enable Content Scanning + + Args: + zone_id: Identifier + + 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 + """ + if not zone_id: + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") + return await self._post( + f"/zones/{zone_id}/content-upload-scan/enable", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[object]._unwrapper, + ), + cast_to=cast(Type[object], ResultWrapper[object]), + ) + + +class ContentScanningResourceWithRawResponse: + def __init__(self, content_scanning: ContentScanningResource) -> None: + self._content_scanning = content_scanning + + self.disable = to_raw_response_wrapper( + content_scanning.disable, + ) + self.enable = to_raw_response_wrapper( + content_scanning.enable, + ) + + @cached_property + def payloads(self) -> PayloadsResourceWithRawResponse: + return PayloadsResourceWithRawResponse(self._content_scanning.payloads) + + @cached_property + def settings(self) -> SettingsResourceWithRawResponse: + return SettingsResourceWithRawResponse(self._content_scanning.settings) + + +class AsyncContentScanningResourceWithRawResponse: + def __init__(self, content_scanning: AsyncContentScanningResource) -> None: + self._content_scanning = content_scanning + + self.disable = async_to_raw_response_wrapper( + content_scanning.disable, + ) + self.enable = async_to_raw_response_wrapper( + content_scanning.enable, + ) + + @cached_property + def payloads(self) -> AsyncPayloadsResourceWithRawResponse: + return AsyncPayloadsResourceWithRawResponse(self._content_scanning.payloads) + + @cached_property + def settings(self) -> AsyncSettingsResourceWithRawResponse: + return AsyncSettingsResourceWithRawResponse(self._content_scanning.settings) + + +class ContentScanningResourceWithStreamingResponse: + def __init__(self, content_scanning: ContentScanningResource) -> None: + self._content_scanning = content_scanning + + self.disable = to_streamed_response_wrapper( + content_scanning.disable, + ) + self.enable = to_streamed_response_wrapper( + content_scanning.enable, + ) + + @cached_property + def payloads(self) -> PayloadsResourceWithStreamingResponse: + return PayloadsResourceWithStreamingResponse(self._content_scanning.payloads) + + @cached_property + def settings(self) -> SettingsResourceWithStreamingResponse: + return SettingsResourceWithStreamingResponse(self._content_scanning.settings) + + +class AsyncContentScanningResourceWithStreamingResponse: + def __init__(self, content_scanning: AsyncContentScanningResource) -> None: + self._content_scanning = content_scanning + + self.disable = async_to_streamed_response_wrapper( + content_scanning.disable, + ) + self.enable = async_to_streamed_response_wrapper( + content_scanning.enable, + ) + + @cached_property + def payloads(self) -> AsyncPayloadsResourceWithStreamingResponse: + return AsyncPayloadsResourceWithStreamingResponse(self._content_scanning.payloads) + + @cached_property + def settings(self) -> AsyncSettingsResourceWithStreamingResponse: + return AsyncSettingsResourceWithStreamingResponse(self._content_scanning.settings) diff --git a/src/cloudflare/resources/content_scanning/payloads.py b/src/cloudflare/resources/content_scanning/payloads.py new file mode 100644 index 00000000000..535cee923bc --- /dev/null +++ b/src/cloudflare/resources/content_scanning/payloads.py @@ -0,0 +1,374 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Type, Iterable, 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 ...pagination import SyncSinglePage, AsyncSinglePage +from ..._base_client import AsyncPaginator, make_request_options +from ...types.content_scanning import payload_create_params +from ...types.content_scanning.payload_list_response import PayloadListResponse +from ...types.content_scanning.payload_create_response import PayloadCreateResponse +from ...types.content_scanning.payload_delete_response import PayloadDeleteResponse + +__all__ = ["PayloadsResource", "AsyncPayloadsResource"] + + +class PayloadsResource(SyncAPIResource): + @cached_property + def with_raw_response(self) -> PayloadsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + 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 PayloadsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> PayloadsResourceWithStreamingResponse: + """ + 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 PayloadsResourceWithStreamingResponse(self) + + def create( + self, + *, + zone_id: str, + body: Iterable[payload_create_params.Body], + # 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[PayloadCreateResponse]: + """ + Add custom scan expressions for Content Scanning + + Args: + zone_id: Identifier + + 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 + """ + if not zone_id: + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") + return self._post( + f"/zones/{zone_id}/content-upload-scan/payloads", + body=maybe_transform(body, Iterable[payload_create_params.Body]), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[Optional[PayloadCreateResponse]]._unwrapper, + ), + cast_to=cast(Type[Optional[PayloadCreateResponse]], ResultWrapper[PayloadCreateResponse]), + ) + + def list( + self, + *, + zone_id: str, + # 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, + ) -> SyncSinglePage[PayloadListResponse]: + """ + Get a list of existing custom scan expressions for Content Scanning + + Args: + zone_id: Identifier + + 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 + """ + if not zone_id: + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") + return self._get_api_list( + f"/zones/{zone_id}/content-upload-scan/payloads", + page=SyncSinglePage[PayloadListResponse], + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + model=PayloadListResponse, + ) + + def delete( + self, + expression_id: str, + *, + zone_id: str, + # 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[PayloadDeleteResponse]: + """ + Delete a Content Scan Custom Expression + + Args: + zone_id: Identifier + + expression_id: The unique ID for this custom scan expression + + 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 + """ + if not zone_id: + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") + if not expression_id: + raise ValueError(f"Expected a non-empty value for `expression_id` but received {expression_id!r}") + return self._delete( + f"/zones/{zone_id}/content-upload-scan/payloads/{expression_id}", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[Optional[PayloadDeleteResponse]]._unwrapper, + ), + cast_to=cast(Type[Optional[PayloadDeleteResponse]], ResultWrapper[PayloadDeleteResponse]), + ) + + +class AsyncPayloadsResource(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncPayloadsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + 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 AsyncPayloadsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncPayloadsResourceWithStreamingResponse: + """ + 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 AsyncPayloadsResourceWithStreamingResponse(self) + + async def create( + self, + *, + zone_id: str, + body: Iterable[payload_create_params.Body], + # 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[PayloadCreateResponse]: + """ + Add custom scan expressions for Content Scanning + + Args: + zone_id: Identifier + + 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 + """ + if not zone_id: + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") + return await self._post( + f"/zones/{zone_id}/content-upload-scan/payloads", + body=await async_maybe_transform(body, Iterable[payload_create_params.Body]), + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[Optional[PayloadCreateResponse]]._unwrapper, + ), + cast_to=cast(Type[Optional[PayloadCreateResponse]], ResultWrapper[PayloadCreateResponse]), + ) + + def list( + self, + *, + zone_id: str, + # 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, + ) -> AsyncPaginator[PayloadListResponse, AsyncSinglePage[PayloadListResponse]]: + """ + Get a list of existing custom scan expressions for Content Scanning + + Args: + zone_id: Identifier + + 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 + """ + if not zone_id: + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") + return self._get_api_list( + f"/zones/{zone_id}/content-upload-scan/payloads", + page=AsyncSinglePage[PayloadListResponse], + options=make_request_options( + extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + ), + model=PayloadListResponse, + ) + + async def delete( + self, + expression_id: str, + *, + zone_id: str, + # 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[PayloadDeleteResponse]: + """ + Delete a Content Scan Custom Expression + + Args: + zone_id: Identifier + + expression_id: The unique ID for this custom scan expression + + 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 + """ + if not zone_id: + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") + if not expression_id: + raise ValueError(f"Expected a non-empty value for `expression_id` but received {expression_id!r}") + return await self._delete( + f"/zones/{zone_id}/content-upload-scan/payloads/{expression_id}", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[Optional[PayloadDeleteResponse]]._unwrapper, + ), + cast_to=cast(Type[Optional[PayloadDeleteResponse]], ResultWrapper[PayloadDeleteResponse]), + ) + + +class PayloadsResourceWithRawResponse: + def __init__(self, payloads: PayloadsResource) -> None: + self._payloads = payloads + + self.create = to_raw_response_wrapper( + payloads.create, + ) + self.list = to_raw_response_wrapper( + payloads.list, + ) + self.delete = to_raw_response_wrapper( + payloads.delete, + ) + + +class AsyncPayloadsResourceWithRawResponse: + def __init__(self, payloads: AsyncPayloadsResource) -> None: + self._payloads = payloads + + self.create = async_to_raw_response_wrapper( + payloads.create, + ) + self.list = async_to_raw_response_wrapper( + payloads.list, + ) + self.delete = async_to_raw_response_wrapper( + payloads.delete, + ) + + +class PayloadsResourceWithStreamingResponse: + def __init__(self, payloads: PayloadsResource) -> None: + self._payloads = payloads + + self.create = to_streamed_response_wrapper( + payloads.create, + ) + self.list = to_streamed_response_wrapper( + payloads.list, + ) + self.delete = to_streamed_response_wrapper( + payloads.delete, + ) + + +class AsyncPayloadsResourceWithStreamingResponse: + def __init__(self, payloads: AsyncPayloadsResource) -> None: + self._payloads = payloads + + self.create = async_to_streamed_response_wrapper( + payloads.create, + ) + self.list = async_to_streamed_response_wrapper( + payloads.list, + ) + self.delete = async_to_streamed_response_wrapper( + payloads.delete, + ) diff --git a/src/cloudflare/resources/content_scanning/settings.py b/src/cloudflare/resources/content_scanning/settings.py new file mode 100644 index 00000000000..17cbe88d506 --- /dev/null +++ b/src/cloudflare/resources/content_scanning/settings.py @@ -0,0 +1,178 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Type, cast + +import httpx + +from ..._types import NOT_GIVEN, Body, Query, Headers, NotGiven +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 ..._base_client import make_request_options +from ...types.content_scanning.setting_get_response import SettingGetResponse + +__all__ = ["SettingsResource", "AsyncSettingsResource"] + + +class SettingsResource(SyncAPIResource): + @cached_property + def with_raw_response(self) -> SettingsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + 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 SettingsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> SettingsResourceWithStreamingResponse: + """ + 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 SettingsResourceWithStreamingResponse(self) + + def get( + self, + *, + zone_id: str, + # 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, + ) -> SettingGetResponse: + """ + Retrieve the current status of Content Scanning + + Args: + zone_id: Identifier + + 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 + """ + if not zone_id: + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") + return self._get( + f"/zones/{zone_id}/content-upload-scan/settings", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[SettingGetResponse]._unwrapper, + ), + cast_to=cast(Type[SettingGetResponse], ResultWrapper[SettingGetResponse]), + ) + + +class AsyncSettingsResource(AsyncAPIResource): + @cached_property + def with_raw_response(self) -> AsyncSettingsResourceWithRawResponse: + """ + This property can be used as a prefix for any HTTP method call to return the + 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 AsyncSettingsResourceWithRawResponse(self) + + @cached_property + def with_streaming_response(self) -> AsyncSettingsResourceWithStreamingResponse: + """ + 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 AsyncSettingsResourceWithStreamingResponse(self) + + async def get( + self, + *, + zone_id: str, + # 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, + ) -> SettingGetResponse: + """ + Retrieve the current status of Content Scanning + + Args: + zone_id: Identifier + + 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 + """ + if not zone_id: + raise ValueError(f"Expected a non-empty value for `zone_id` but received {zone_id!r}") + return await self._get( + f"/zones/{zone_id}/content-upload-scan/settings", + options=make_request_options( + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, + post_parser=ResultWrapper[SettingGetResponse]._unwrapper, + ), + cast_to=cast(Type[SettingGetResponse], ResultWrapper[SettingGetResponse]), + ) + + +class SettingsResourceWithRawResponse: + def __init__(self, settings: SettingsResource) -> None: + self._settings = settings + + self.get = to_raw_response_wrapper( + settings.get, + ) + + +class AsyncSettingsResourceWithRawResponse: + def __init__(self, settings: AsyncSettingsResource) -> None: + self._settings = settings + + self.get = async_to_raw_response_wrapper( + settings.get, + ) + + +class SettingsResourceWithStreamingResponse: + def __init__(self, settings: SettingsResource) -> None: + self._settings = settings + + self.get = to_streamed_response_wrapper( + settings.get, + ) + + +class AsyncSettingsResourceWithStreamingResponse: + def __init__(self, settings: AsyncSettingsResource) -> None: + self._settings = settings + + self.get = async_to_streamed_response_wrapper( + settings.get, + ) diff --git a/src/cloudflare/types/content_scanning/__init__.py b/src/cloudflare/types/content_scanning/__init__.py new file mode 100644 index 00000000000..ae3bfa8499c --- /dev/null +++ b/src/cloudflare/types/content_scanning/__init__.py @@ -0,0 +1,9 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from .setting_get_response import SettingGetResponse as SettingGetResponse +from .payload_create_params import PayloadCreateParams as PayloadCreateParams +from .payload_list_response import PayloadListResponse as PayloadListResponse +from .payload_create_response import PayloadCreateResponse as PayloadCreateResponse +from .payload_delete_response import PayloadDeleteResponse as PayloadDeleteResponse diff --git a/src/cloudflare/types/content_scanning/payload_create_params.py b/src/cloudflare/types/content_scanning/payload_create_params.py new file mode 100644 index 00000000000..6df6f0a4b75 --- /dev/null +++ b/src/cloudflare/types/content_scanning/payload_create_params.py @@ -0,0 +1,20 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +from typing import Iterable +from typing_extensions import Required, TypedDict + +__all__ = ["PayloadCreateParams", "Body"] + + +class PayloadCreateParams(TypedDict, total=False): + zone_id: Required[str] + """Identifier""" + + body: Required[Iterable[Body]] + + +class Body(TypedDict, total=False): + payload: Required[str] + """Ruleset expression to use in matching content objects""" diff --git a/src/cloudflare/types/content_scanning/payload_create_response.py b/src/cloudflare/types/content_scanning/payload_create_response.py new file mode 100644 index 00000000000..0faff0519e3 --- /dev/null +++ b/src/cloudflare/types/content_scanning/payload_create_response.py @@ -0,0 +1,19 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import List, Optional +from typing_extensions import TypeAlias + +from ..._models import BaseModel + +__all__ = ["PayloadCreateResponse", "PayloadCreateResponseItem"] + + +class PayloadCreateResponseItem(BaseModel): + id: Optional[str] = None + """The unique ID for this custom scan expression""" + + payload: Optional[str] = None + """Ruleset expression to use in matching content objects""" + + +PayloadCreateResponse: TypeAlias = List[PayloadCreateResponseItem] diff --git a/src/cloudflare/types/content_scanning/payload_delete_response.py b/src/cloudflare/types/content_scanning/payload_delete_response.py new file mode 100644 index 00000000000..f2e40df9962 --- /dev/null +++ b/src/cloudflare/types/content_scanning/payload_delete_response.py @@ -0,0 +1,19 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import List, Optional +from typing_extensions import TypeAlias + +from ..._models import BaseModel + +__all__ = ["PayloadDeleteResponse", "PayloadDeleteResponseItem"] + + +class PayloadDeleteResponseItem(BaseModel): + id: Optional[str] = None + """The unique ID for this custom scan expression""" + + payload: Optional[str] = None + """Ruleset expression to use in matching content objects""" + + +PayloadDeleteResponse: TypeAlias = List[PayloadDeleteResponseItem] diff --git a/src/cloudflare/types/content_scanning/payload_list_response.py b/src/cloudflare/types/content_scanning/payload_list_response.py new file mode 100644 index 00000000000..2ed0a8d1cf3 --- /dev/null +++ b/src/cloudflare/types/content_scanning/payload_list_response.py @@ -0,0 +1,15 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional + +from ..._models import BaseModel + +__all__ = ["PayloadListResponse"] + + +class PayloadListResponse(BaseModel): + id: Optional[str] = None + """The unique ID for this custom scan expression""" + + payload: Optional[str] = None + """Ruleset expression to use in matching content objects""" diff --git a/src/cloudflare/types/content_scanning/setting_get_response.py b/src/cloudflare/types/content_scanning/setting_get_response.py new file mode 100644 index 00000000000..7e9225e3d7a --- /dev/null +++ b/src/cloudflare/types/content_scanning/setting_get_response.py @@ -0,0 +1,15 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from typing import Optional + +from ..._models import BaseModel + +__all__ = ["SettingGetResponse"] + + +class SettingGetResponse(BaseModel): + modified: Optional[str] = None + """Last modification date (ISO 8601) of the Content Scanning status""" + + value: Optional[str] = None + """Status of Content Scanning""" diff --git a/tests/api_resources/content_scanning/__init__.py b/tests/api_resources/content_scanning/__init__.py new file mode 100644 index 00000000000..fd8019a9a1a --- /dev/null +++ b/tests/api_resources/content_scanning/__init__.py @@ -0,0 +1 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. diff --git a/tests/api_resources/content_scanning/test_payloads.py b/tests/api_resources/content_scanning/test_payloads.py new file mode 100644 index 00000000000..5dc0673978c --- /dev/null +++ b/tests/api_resources/content_scanning/test_payloads.py @@ -0,0 +1,283 @@ +# 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.pagination import SyncSinglePage, AsyncSinglePage +from cloudflare.types.content_scanning import ( + PayloadListResponse, + PayloadCreateResponse, + PayloadDeleteResponse, +) + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestPayloads: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + def test_method_create(self, client: Cloudflare) -> None: + payload = client.content_scanning.payloads.create( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + body=[{"payload": 'lookup_json_string(http.request.body.raw, "file")'}], + ) + assert_matches_type(Optional[PayloadCreateResponse], payload, path=["response"]) + + @parametrize + def test_raw_response_create(self, client: Cloudflare) -> None: + response = client.content_scanning.payloads.with_raw_response.create( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + body=[{"payload": 'lookup_json_string(http.request.body.raw, "file")'}], + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + payload = response.parse() + assert_matches_type(Optional[PayloadCreateResponse], payload, path=["response"]) + + @parametrize + def test_streaming_response_create(self, client: Cloudflare) -> None: + with client.content_scanning.payloads.with_streaming_response.create( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + body=[{"payload": 'lookup_json_string(http.request.body.raw, "file")'}], + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + payload = response.parse() + assert_matches_type(Optional[PayloadCreateResponse], payload, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + def test_path_params_create(self, client: Cloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `zone_id` but received ''"): + client.content_scanning.payloads.with_raw_response.create( + zone_id="", + body=[{"payload": 'lookup_json_string(http.request.body.raw, "file")'}], + ) + + @parametrize + def test_method_list(self, client: Cloudflare) -> None: + payload = client.content_scanning.payloads.list( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + assert_matches_type(SyncSinglePage[PayloadListResponse], payload, path=["response"]) + + @parametrize + def test_raw_response_list(self, client: Cloudflare) -> None: + response = client.content_scanning.payloads.with_raw_response.list( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + payload = response.parse() + assert_matches_type(SyncSinglePage[PayloadListResponse], payload, path=["response"]) + + @parametrize + def test_streaming_response_list(self, client: Cloudflare) -> None: + with client.content_scanning.payloads.with_streaming_response.list( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + payload = response.parse() + assert_matches_type(SyncSinglePage[PayloadListResponse], payload, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + def test_path_params_list(self, client: Cloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `zone_id` but received ''"): + client.content_scanning.payloads.with_raw_response.list( + zone_id="", + ) + + @parametrize + def test_method_delete(self, client: Cloudflare) -> None: + payload = client.content_scanning.payloads.delete( + expression_id="a350a054caa840c9becd89c3b4f0195b", + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + assert_matches_type(Optional[PayloadDeleteResponse], payload, path=["response"]) + + @parametrize + def test_raw_response_delete(self, client: Cloudflare) -> None: + response = client.content_scanning.payloads.with_raw_response.delete( + expression_id="a350a054caa840c9becd89c3b4f0195b", + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + payload = response.parse() + assert_matches_type(Optional[PayloadDeleteResponse], payload, path=["response"]) + + @parametrize + def test_streaming_response_delete(self, client: Cloudflare) -> None: + with client.content_scanning.payloads.with_streaming_response.delete( + expression_id="a350a054caa840c9becd89c3b4f0195b", + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + payload = response.parse() + assert_matches_type(Optional[PayloadDeleteResponse], payload, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + def test_path_params_delete(self, client: Cloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `zone_id` but received ''"): + client.content_scanning.payloads.with_raw_response.delete( + expression_id="a350a054caa840c9becd89c3b4f0195b", + zone_id="", + ) + + with pytest.raises(ValueError, match=r"Expected a non-empty value for `expression_id` but received ''"): + client.content_scanning.payloads.with_raw_response.delete( + expression_id="", + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + + +class TestAsyncPayloads: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + async def test_method_create(self, async_client: AsyncCloudflare) -> None: + payload = await async_client.content_scanning.payloads.create( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + body=[{"payload": 'lookup_json_string(http.request.body.raw, "file")'}], + ) + assert_matches_type(Optional[PayloadCreateResponse], payload, path=["response"]) + + @parametrize + async def test_raw_response_create(self, async_client: AsyncCloudflare) -> None: + response = await async_client.content_scanning.payloads.with_raw_response.create( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + body=[{"payload": 'lookup_json_string(http.request.body.raw, "file")'}], + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + payload = await response.parse() + assert_matches_type(Optional[PayloadCreateResponse], payload, path=["response"]) + + @parametrize + async def test_streaming_response_create(self, async_client: AsyncCloudflare) -> None: + async with async_client.content_scanning.payloads.with_streaming_response.create( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + body=[{"payload": 'lookup_json_string(http.request.body.raw, "file")'}], + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + payload = await response.parse() + assert_matches_type(Optional[PayloadCreateResponse], payload, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + async def test_path_params_create(self, async_client: AsyncCloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `zone_id` but received ''"): + await async_client.content_scanning.payloads.with_raw_response.create( + zone_id="", + body=[{"payload": 'lookup_json_string(http.request.body.raw, "file")'}], + ) + + @parametrize + async def test_method_list(self, async_client: AsyncCloudflare) -> None: + payload = await async_client.content_scanning.payloads.list( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + assert_matches_type(AsyncSinglePage[PayloadListResponse], payload, path=["response"]) + + @parametrize + async def test_raw_response_list(self, async_client: AsyncCloudflare) -> None: + response = await async_client.content_scanning.payloads.with_raw_response.list( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + payload = await response.parse() + assert_matches_type(AsyncSinglePage[PayloadListResponse], payload, path=["response"]) + + @parametrize + async def test_streaming_response_list(self, async_client: AsyncCloudflare) -> None: + async with async_client.content_scanning.payloads.with_streaming_response.list( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + payload = await response.parse() + assert_matches_type(AsyncSinglePage[PayloadListResponse], payload, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + async def test_path_params_list(self, async_client: AsyncCloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `zone_id` but received ''"): + await async_client.content_scanning.payloads.with_raw_response.list( + zone_id="", + ) + + @parametrize + async def test_method_delete(self, async_client: AsyncCloudflare) -> None: + payload = await async_client.content_scanning.payloads.delete( + expression_id="a350a054caa840c9becd89c3b4f0195b", + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + assert_matches_type(Optional[PayloadDeleteResponse], payload, path=["response"]) + + @parametrize + async def test_raw_response_delete(self, async_client: AsyncCloudflare) -> None: + response = await async_client.content_scanning.payloads.with_raw_response.delete( + expression_id="a350a054caa840c9becd89c3b4f0195b", + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + payload = await response.parse() + assert_matches_type(Optional[PayloadDeleteResponse], payload, path=["response"]) + + @parametrize + async def test_streaming_response_delete(self, async_client: AsyncCloudflare) -> None: + async with async_client.content_scanning.payloads.with_streaming_response.delete( + expression_id="a350a054caa840c9becd89c3b4f0195b", + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + payload = await response.parse() + assert_matches_type(Optional[PayloadDeleteResponse], payload, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + async def test_path_params_delete(self, async_client: AsyncCloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `zone_id` but received ''"): + await async_client.content_scanning.payloads.with_raw_response.delete( + expression_id="a350a054caa840c9becd89c3b4f0195b", + zone_id="", + ) + + with pytest.raises(ValueError, match=r"Expected a non-empty value for `expression_id` but received ''"): + await async_client.content_scanning.payloads.with_raw_response.delete( + expression_id="", + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) diff --git a/tests/api_resources/content_scanning/test_settings.py b/tests/api_resources/content_scanning/test_settings.py new file mode 100644 index 00000000000..f8f169b2766 --- /dev/null +++ b/tests/api_resources/content_scanning/test_settings.py @@ -0,0 +1,98 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from cloudflare import Cloudflare, AsyncCloudflare +from tests.utils import assert_matches_type +from cloudflare.types.content_scanning import SettingGetResponse + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestSettings: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + def test_method_get(self, client: Cloudflare) -> None: + setting = client.content_scanning.settings.get( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + assert_matches_type(SettingGetResponse, setting, path=["response"]) + + @parametrize + def test_raw_response_get(self, client: Cloudflare) -> None: + response = client.content_scanning.settings.with_raw_response.get( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + setting = response.parse() + assert_matches_type(SettingGetResponse, setting, path=["response"]) + + @parametrize + def test_streaming_response_get(self, client: Cloudflare) -> None: + with client.content_scanning.settings.with_streaming_response.get( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + setting = response.parse() + assert_matches_type(SettingGetResponse, setting, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + def test_path_params_get(self, client: Cloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `zone_id` but received ''"): + client.content_scanning.settings.with_raw_response.get( + zone_id="", + ) + + +class TestAsyncSettings: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + async def test_method_get(self, async_client: AsyncCloudflare) -> None: + setting = await async_client.content_scanning.settings.get( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + assert_matches_type(SettingGetResponse, setting, path=["response"]) + + @parametrize + async def test_raw_response_get(self, async_client: AsyncCloudflare) -> None: + response = await async_client.content_scanning.settings.with_raw_response.get( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + setting = await response.parse() + assert_matches_type(SettingGetResponse, setting, path=["response"]) + + @parametrize + async def test_streaming_response_get(self, async_client: AsyncCloudflare) -> None: + async with async_client.content_scanning.settings.with_streaming_response.get( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + setting = await response.parse() + assert_matches_type(SettingGetResponse, setting, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + async def test_path_params_get(self, async_client: AsyncCloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `zone_id` but received ''"): + await async_client.content_scanning.settings.with_raw_response.get( + zone_id="", + ) diff --git a/tests/api_resources/test_content_scanning.py b/tests/api_resources/test_content_scanning.py new file mode 100644 index 00000000000..a66910245a8 --- /dev/null +++ b/tests/api_resources/test_content_scanning.py @@ -0,0 +1,173 @@ +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. + +from __future__ import annotations + +import os +from typing import Any, cast + +import pytest + +from cloudflare import Cloudflare, AsyncCloudflare +from tests.utils import assert_matches_type + +base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") + + +class TestContentScanning: + parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + def test_method_disable(self, client: Cloudflare) -> None: + content_scanning = client.content_scanning.disable( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + assert_matches_type(object, content_scanning, path=["response"]) + + @parametrize + def test_raw_response_disable(self, client: Cloudflare) -> None: + response = client.content_scanning.with_raw_response.disable( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + content_scanning = response.parse() + assert_matches_type(object, content_scanning, path=["response"]) + + @parametrize + def test_streaming_response_disable(self, client: Cloudflare) -> None: + with client.content_scanning.with_streaming_response.disable( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + content_scanning = response.parse() + assert_matches_type(object, content_scanning, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + def test_path_params_disable(self, client: Cloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `zone_id` but received ''"): + client.content_scanning.with_raw_response.disable( + zone_id="", + ) + + @parametrize + def test_method_enable(self, client: Cloudflare) -> None: + content_scanning = client.content_scanning.enable( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + assert_matches_type(object, content_scanning, path=["response"]) + + @parametrize + def test_raw_response_enable(self, client: Cloudflare) -> None: + response = client.content_scanning.with_raw_response.enable( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + content_scanning = response.parse() + assert_matches_type(object, content_scanning, path=["response"]) + + @parametrize + def test_streaming_response_enable(self, client: Cloudflare) -> None: + with client.content_scanning.with_streaming_response.enable( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + content_scanning = response.parse() + assert_matches_type(object, content_scanning, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + def test_path_params_enable(self, client: Cloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `zone_id` but received ''"): + client.content_scanning.with_raw_response.enable( + zone_id="", + ) + + +class TestAsyncContentScanning: + parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) + + @parametrize + async def test_method_disable(self, async_client: AsyncCloudflare) -> None: + content_scanning = await async_client.content_scanning.disable( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + assert_matches_type(object, content_scanning, path=["response"]) + + @parametrize + async def test_raw_response_disable(self, async_client: AsyncCloudflare) -> None: + response = await async_client.content_scanning.with_raw_response.disable( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + content_scanning = await response.parse() + assert_matches_type(object, content_scanning, path=["response"]) + + @parametrize + async def test_streaming_response_disable(self, async_client: AsyncCloudflare) -> None: + async with async_client.content_scanning.with_streaming_response.disable( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + content_scanning = await response.parse() + assert_matches_type(object, content_scanning, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + async def test_path_params_disable(self, async_client: AsyncCloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `zone_id` but received ''"): + await async_client.content_scanning.with_raw_response.disable( + zone_id="", + ) + + @parametrize + async def test_method_enable(self, async_client: AsyncCloudflare) -> None: + content_scanning = await async_client.content_scanning.enable( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + assert_matches_type(object, content_scanning, path=["response"]) + + @parametrize + async def test_raw_response_enable(self, async_client: AsyncCloudflare) -> None: + response = await async_client.content_scanning.with_raw_response.enable( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) + + assert response.is_closed is True + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + content_scanning = await response.parse() + assert_matches_type(object, content_scanning, path=["response"]) + + @parametrize + async def test_streaming_response_enable(self, async_client: AsyncCloudflare) -> None: + async with async_client.content_scanning.with_streaming_response.enable( + zone_id="023e105f4ecef8ad9ca31a8372d0c353", + ) as response: + assert not response.is_closed + assert response.http_request.headers.get("X-Stainless-Lang") == "python" + + content_scanning = await response.parse() + assert_matches_type(object, content_scanning, path=["response"]) + + assert cast(Any, response.is_closed) is True + + @parametrize + async def test_path_params_enable(self, async_client: AsyncCloudflare) -> None: + with pytest.raises(ValueError, match=r"Expected a non-empty value for `zone_id` but received ''"): + await async_client.content_scanning.with_raw_response.enable( + zone_id="", + )