Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6522,7 +6522,7 @@ from cloudflare.types.url_scanner import (

Methods:

- <code title="post /accounts/{accountId}/urlscanner/scan">client.url_scanner.scans.<a href="./src/cloudflare/resources/url_scanner/scans.py">create</a>(account_id, \*\*<a href="src/cloudflare/types/url_scanner/scan_create_params.py">params</a>) -> <a href="./src/cloudflare/types/url_scanner/scan_create_response.py">ScanCreateResponse</a></code>
- <code title="post /accounts/{accountId}/urlscanner/v2/scan">client.url_scanner.scans.<a href="./src/cloudflare/resources/url_scanner/scans.py">create</a>(account_id, \*\*<a href="src/cloudflare/types/url_scanner/scan_create_params.py">params</a>) -> <a href="./src/cloudflare/types/url_scanner/scan_create_response.py">str</a></code>
- <code title="get /accounts/{accountId}/urlscanner/scan">client.url_scanner.scans.<a href="./src/cloudflare/resources/url_scanner/scans.py">list</a>(account_id, \*\*<a href="src/cloudflare/types/url_scanner/scan_list_params.py">params</a>) -> <a href="./src/cloudflare/types/url_scanner/scan_list_response.py">ScanListResponse</a></code>
- <code title="get /accounts/{accountId}/urlscanner/scan/{scanId}">client.url_scanner.scans.<a href="./src/cloudflare/resources/url_scanner/scans.py">get</a>(scan_id, \*, account_id, \*\*<a href="src/cloudflare/types/url_scanner/scan_get_params.py">params</a>) -> <a href="./src/cloudflare/types/url_scanner/scan_get_response.py">ScanGetResponse</a></code>
- <code title="get /accounts/{accountId}/urlscanner/scan/{scanId}/har">client.url_scanner.scans.<a href="./src/cloudflare/resources/url_scanner/scans.py">har</a>(scan_id, \*, account_id) -> <a href="./src/cloudflare/types/url_scanner/scan_har_response.py">ScanHARResponse</a></code>
Expand Down
26 changes: 16 additions & 10 deletions src/cloudflare/resources/url_scanner/scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def create(
account_id: str,
*,
url: str,
customagent: str | NotGiven = NOT_GIVEN,
custom_headers: Dict[str, str] | NotGiven = NOT_GIVEN,
referer: str | NotGiven = NOT_GIVEN,
screenshots_resolutions: List[Literal["desktop", "mobile", "tablet"]] | NotGiven = NOT_GIVEN,
visibility: Literal["Public", "Unlisted"] | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
Expand All @@ -74,11 +76,10 @@ def create(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> ScanCreateResponse:
) -> str:
"""Submit a URL to scan.

You can also set some options, like the visibility level
and custom headers. Check limits at
Check limits at
https://developers.cloudflare.com/security-center/investigate/scan-limits/.

Args:
Expand All @@ -105,11 +106,13 @@ def create(
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
return self._post(
f"/accounts/{account_id}/urlscanner/scan",
f"/accounts/{account_id}/urlscanner/v2/scan",
body=maybe_transform(
{
"url": url,
"customagent": customagent,
"custom_headers": custom_headers,
"referer": referer,
"screenshots_resolutions": screenshots_resolutions,
"visibility": visibility,
},
Expand All @@ -122,7 +125,7 @@ def create(
timeout=timeout,
post_parser=ResultWrapper[ScanCreateResponse]._unwrapper,
),
cast_to=cast(Type[ScanCreateResponse], ResultWrapper[ScanCreateResponse]),
cast_to=cast(Type[str], ResultWrapper[str]),
)

def list(
Expand Down Expand Up @@ -415,7 +418,9 @@ async def create(
account_id: str,
*,
url: str,
customagent: str | NotGiven = NOT_GIVEN,
custom_headers: Dict[str, str] | NotGiven = NOT_GIVEN,
referer: str | NotGiven = NOT_GIVEN,
screenshots_resolutions: List[Literal["desktop", "mobile", "tablet"]] | NotGiven = NOT_GIVEN,
visibility: Literal["Public", "Unlisted"] | NotGiven = NOT_GIVEN,
# Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs.
Expand All @@ -424,11 +429,10 @@ async def create(
extra_query: Query | None = None,
extra_body: Body | None = None,
timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN,
) -> ScanCreateResponse:
) -> str:
"""Submit a URL to scan.

You can also set some options, like the visibility level
and custom headers. Check limits at
Check limits at
https://developers.cloudflare.com/security-center/investigate/scan-limits/.

Args:
Expand All @@ -455,11 +459,13 @@ async def create(
if not account_id:
raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}")
return await self._post(
f"/accounts/{account_id}/urlscanner/scan",
f"/accounts/{account_id}/urlscanner/v2/scan",
body=await async_maybe_transform(
{
"url": url,
"customagent": customagent,
"custom_headers": custom_headers,
"referer": referer,
"screenshots_resolutions": screenshots_resolutions,
"visibility": visibility,
},
Expand All @@ -472,7 +478,7 @@ async def create(
timeout=timeout,
post_parser=ResultWrapper[ScanCreateResponse]._unwrapper,
),
cast_to=cast(Type[ScanCreateResponse], ResultWrapper[ScanCreateResponse]),
cast_to=cast(Type[str], ResultWrapper[str]),
)

async def list(
Expand Down
4 changes: 4 additions & 0 deletions src/cloudflare/types/url_scanner/scan_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@
class ScanCreateParams(TypedDict, total=False):
url: Required[str]

customagent: str

custom_headers: Annotated[Dict[str, str], PropertyInfo(alias="customHeaders")]
"""Set custom headers."""

referer: str

screenshots_resolutions: Annotated[
List[Literal["desktop", "mobile", "tablet"]], PropertyInfo(alias="screenshotsResolutions")
]
Expand Down
18 changes: 2 additions & 16 deletions src/cloudflare/types/url_scanner/scan_create_response.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from datetime import datetime

from ..._models import BaseModel
from typing_extensions import TypeAlias

__all__ = ["ScanCreateResponse"]


class ScanCreateResponse(BaseModel):
time: datetime
"""Time when url was submitted for scanning."""

url: str
"""Canonical form of submitted URL. Use this if you want to later search by URL."""

uuid: str
"""Scan ID."""

visibility: str
"""Submitted visibility status."""
ScanCreateResponse: TypeAlias = str
21 changes: 12 additions & 9 deletions tests/api_resources/url_scanner/test_scans.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
ScanGetResponse,
ScanHARResponse,
ScanListResponse,
ScanCreateResponse,
)

base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
Expand All @@ -37,18 +36,20 @@ def test_method_create(self, client: Cloudflare) -> None:
account_id="accountId",
url="https://www.example.com",
)
assert_matches_type(ScanCreateResponse, scan, path=["response"])
assert_matches_type(str, scan, path=["response"])

@parametrize
def test_method_create_with_all_params(self, client: Cloudflare) -> None:
scan = client.url_scanner.scans.create(
account_id="accountId",
url="https://www.example.com",
customagent="customagent",
custom_headers={"foo": "string"},
referer="referer",
screenshots_resolutions=["desktop"],
visibility="Public",
)
assert_matches_type(ScanCreateResponse, scan, path=["response"])
assert_matches_type(str, scan, path=["response"])

@parametrize
def test_raw_response_create(self, client: Cloudflare) -> None:
Expand All @@ -60,7 +61,7 @@ def test_raw_response_create(self, client: Cloudflare) -> None:
assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
scan = response.parse()
assert_matches_type(ScanCreateResponse, scan, path=["response"])
assert_matches_type(str, scan, path=["response"])

@parametrize
def test_streaming_response_create(self, client: Cloudflare) -> None:
Expand All @@ -72,7 +73,7 @@ def test_streaming_response_create(self, client: Cloudflare) -> None:
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

scan = response.parse()
assert_matches_type(ScanCreateResponse, scan, path=["response"])
assert_matches_type(str, scan, path=["response"])

assert cast(Any, response.is_closed) is True

Expand Down Expand Up @@ -344,18 +345,20 @@ async def test_method_create(self, async_client: AsyncCloudflare) -> None:
account_id="accountId",
url="https://www.example.com",
)
assert_matches_type(ScanCreateResponse, scan, path=["response"])
assert_matches_type(str, scan, path=["response"])

@parametrize
async def test_method_create_with_all_params(self, async_client: AsyncCloudflare) -> None:
scan = await async_client.url_scanner.scans.create(
account_id="accountId",
url="https://www.example.com",
customagent="customagent",
custom_headers={"foo": "string"},
referer="referer",
screenshots_resolutions=["desktop"],
visibility="Public",
)
assert_matches_type(ScanCreateResponse, scan, path=["response"])
assert_matches_type(str, scan, path=["response"])

@parametrize
async def test_raw_response_create(self, async_client: AsyncCloudflare) -> None:
Expand All @@ -367,7 +370,7 @@ async def test_raw_response_create(self, async_client: AsyncCloudflare) -> None:
assert response.is_closed is True
assert response.http_request.headers.get("X-Stainless-Lang") == "python"
scan = await response.parse()
assert_matches_type(ScanCreateResponse, scan, path=["response"])
assert_matches_type(str, scan, path=["response"])

@parametrize
async def test_streaming_response_create(self, async_client: AsyncCloudflare) -> None:
Expand All @@ -379,7 +382,7 @@ async def test_streaming_response_create(self, async_client: AsyncCloudflare) ->
assert response.http_request.headers.get("X-Stainless-Lang") == "python"

scan = await response.parse()
assert_matches_type(ScanCreateResponse, scan, path=["response"])
assert_matches_type(str, scan, path=["response"])

assert cast(Any, response.is_closed) is True

Expand Down