Skip to content

Commit

Permalink
feat(r2_bucket): add cors support (#2196)
Browse files Browse the repository at this point in the history
stainless-app[bot] authored and stainless-bot committed Nov 21, 2024
1 parent 2de0fb0 commit 8ed5f71
Showing 9 changed files with 1,029 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 1448
configured_endpoints: 1451
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/cloudflare%2Fcloudflare-4acaaed718bd08d16e3866d5ad032fbf2bbfeb978df2cf5164edb81fe41e4f89.yml
14 changes: 14 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
@@ -4586,6 +4586,20 @@ Methods:
- <code title="put /accounts/{account_id}/r2/buckets/{bucket_name}/lifecycle">client.r2.buckets.lifecycle.<a href="./src/cloudflare/resources/r2/buckets/lifecycle.py">update</a>(bucket_name, \*, account_id, \*\*<a href="src/cloudflare/types/r2/buckets/lifecycle_update_params.py">params</a>) -> <a href="./src/cloudflare/types/r2/buckets/lifecycle_update_response.py">object</a></code>
- <code title="get /accounts/{account_id}/r2/buckets/{bucket_name}/lifecycle">client.r2.buckets.lifecycle.<a href="./src/cloudflare/resources/r2/buckets/lifecycle.py">get</a>(bucket_name, \*, account_id) -> <a href="./src/cloudflare/types/r2/buckets/lifecycle_get_response.py">LifecycleGetResponse</a></code>

### CORS

Types:

```python
from cloudflare.types.r2.buckets import CORSUpdateResponse, CORSDeleteResponse, CORSGetResponse
```

Methods:

- <code title="put /accounts/{account_id}/r2/buckets/{bucket_name}/cors">client.r2.buckets.cors.<a href="./src/cloudflare/resources/r2/buckets/cors.py">update</a>(bucket_name, \*, account_id, \*\*<a href="src/cloudflare/types/r2/buckets/cors_update_params.py">params</a>) -> <a href="./src/cloudflare/types/r2/buckets/cors_update_response.py">object</a></code>
- <code title="delete /accounts/{account_id}/r2/buckets/{bucket_name}/cors">client.r2.buckets.cors.<a href="./src/cloudflare/resources/r2/buckets/cors.py">delete</a>(bucket_name, \*, account_id) -> <a href="./src/cloudflare/types/r2/buckets/cors_delete_response.py">object</a></code>
- <code title="get /accounts/{account_id}/r2/buckets/{bucket_name}/cors">client.r2.buckets.cors.<a href="./src/cloudflare/resources/r2/buckets/cors.py">get</a>(bucket_name, \*, account_id) -> <a href="./src/cloudflare/types/r2/buckets/cors_get_response.py">CORSGetResponse</a></code>

### Domains

#### Custom
14 changes: 14 additions & 0 deletions src/cloudflare/resources/r2/buckets/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from .cors import (
CORSResource,
AsyncCORSResource,
CORSResourceWithRawResponse,
AsyncCORSResourceWithRawResponse,
CORSResourceWithStreamingResponse,
AsyncCORSResourceWithStreamingResponse,
)
from .sippy import (
SippyResource,
AsyncSippyResource,
@@ -48,6 +56,12 @@
"AsyncLifecycleResourceWithRawResponse",
"LifecycleResourceWithStreamingResponse",
"AsyncLifecycleResourceWithStreamingResponse",
"CORSResource",
"AsyncCORSResource",
"CORSResourceWithRawResponse",
"AsyncCORSResourceWithRawResponse",
"CORSResourceWithStreamingResponse",
"AsyncCORSResourceWithStreamingResponse",
"DomainsResource",
"AsyncDomainsResource",
"DomainsResourceWithRawResponse",
32 changes: 32 additions & 0 deletions src/cloudflare/resources/r2/buckets/buckets.py
Original file line number Diff line number Diff line change
@@ -7,6 +7,14 @@

import httpx

from .cors import (
CORSResource,
AsyncCORSResource,
CORSResourceWithRawResponse,
AsyncCORSResourceWithRawResponse,
CORSResourceWithStreamingResponse,
AsyncCORSResourceWithStreamingResponse,
)
from .sippy import (
SippyResource,
AsyncSippyResource,
@@ -70,6 +78,10 @@ class BucketsResource(SyncAPIResource):
def lifecycle(self) -> LifecycleResource:
return LifecycleResource(self._client)

@cached_property
def cors(self) -> CORSResource:
return CORSResource(self._client)

@cached_property
def domains(self) -> DomainsResource:
return DomainsResource(self._client)
@@ -357,6 +369,10 @@ class AsyncBucketsResource(AsyncAPIResource):
def lifecycle(self) -> AsyncLifecycleResource:
return AsyncLifecycleResource(self._client)

@cached_property
def cors(self) -> AsyncCORSResource:
return AsyncCORSResource(self._client)

@cached_property
def domains(self) -> AsyncDomainsResource:
return AsyncDomainsResource(self._client)
@@ -660,6 +676,10 @@ def __init__(self, buckets: BucketsResource) -> None:
def lifecycle(self) -> LifecycleResourceWithRawResponse:
return LifecycleResourceWithRawResponse(self._buckets.lifecycle)

@cached_property
def cors(self) -> CORSResourceWithRawResponse:
return CORSResourceWithRawResponse(self._buckets.cors)

@cached_property
def domains(self) -> DomainsResourceWithRawResponse:
return DomainsResourceWithRawResponse(self._buckets.domains)
@@ -694,6 +714,10 @@ def __init__(self, buckets: AsyncBucketsResource) -> None:
def lifecycle(self) -> AsyncLifecycleResourceWithRawResponse:
return AsyncLifecycleResourceWithRawResponse(self._buckets.lifecycle)

@cached_property
def cors(self) -> AsyncCORSResourceWithRawResponse:
return AsyncCORSResourceWithRawResponse(self._buckets.cors)

@cached_property
def domains(self) -> AsyncDomainsResourceWithRawResponse:
return AsyncDomainsResourceWithRawResponse(self._buckets.domains)
@@ -728,6 +752,10 @@ def __init__(self, buckets: BucketsResource) -> None:
def lifecycle(self) -> LifecycleResourceWithStreamingResponse:
return LifecycleResourceWithStreamingResponse(self._buckets.lifecycle)

@cached_property
def cors(self) -> CORSResourceWithStreamingResponse:
return CORSResourceWithStreamingResponse(self._buckets.cors)

@cached_property
def domains(self) -> DomainsResourceWithStreamingResponse:
return DomainsResourceWithStreamingResponse(self._buckets.domains)
@@ -762,6 +790,10 @@ def __init__(self, buckets: AsyncBucketsResource) -> None:
def lifecycle(self) -> AsyncLifecycleResourceWithStreamingResponse:
return AsyncLifecycleResourceWithStreamingResponse(self._buckets.lifecycle)

@cached_property
def cors(self) -> AsyncCORSResourceWithStreamingResponse:
return AsyncCORSResourceWithStreamingResponse(self._buckets.cors)

@cached_property
def domains(self) -> AsyncDomainsResourceWithStreamingResponse:
return AsyncDomainsResourceWithStreamingResponse(self._buckets.domains)
454 changes: 454 additions & 0 deletions src/cloudflare/resources/r2/buckets/cors.py

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/cloudflare/types/r2/buckets/__init__.py
Original file line number Diff line number Diff line change
@@ -4,6 +4,8 @@

from .sippy import Sippy as Sippy
from .provider import Provider as Provider
from .cors_get_response import CORSGetResponse as CORSGetResponse
from .cors_update_params import CORSUpdateParams as CORSUpdateParams
from .sippy_update_params import SippyUpdateParams as SippyUpdateParams
from .sippy_delete_response import SippyDeleteResponse as SippyDeleteResponse
from .lifecycle_get_response import LifecycleGetResponse as LifecycleGetResponse
59 changes: 59 additions & 0 deletions src/cloudflare/types/r2/buckets/cors_get_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from typing import List, Optional
from typing_extensions import Literal

from pydantic import Field as FieldInfo

from ...._models import BaseModel

__all__ = ["CORSGetResponse", "Rule", "RuleAllowed"]


class RuleAllowed(BaseModel):
methods: List[Literal["GET", "PUT", "POST", "DELETE", "HEAD"]]
"""
Specifies the value for the Access-Control-Allow-Methods header R2 sets when
requesting objects in a bucket from a browser.
"""

origins: List[str]
"""
Specifies the value for the Access-Control-Allow-Origin header R2 sets when
requesting objects in a bucket from a browser.
"""

headers: Optional[List[str]] = None
"""
Specifies the value for the Access-Control-Allow-Headers header R2 sets when
requesting objects in this bucket from a browser. Cross-origin requests that
include custom headers (e.g. x-user-id) should specify these headers as
AllowedHeaders.
"""


class Rule(BaseModel):
allowed: RuleAllowed
"""Object specifying allowed origins, methods and headers for this CORS rule."""

id: Optional[str] = None
"""Identifier for this rule"""

expose_headers: Optional[List[str]] = FieldInfo(alias="exposeHeaders", default=None)
"""
Specifies the headers that can be exposed back, and accessed by, the JavaScript
making the cross-origin request. If you need to access headers beyond the
safelisted response headers, such as Content-Encoding or cf-cache-status, you
must specify it here.
"""

max_age_seconds: Optional[float] = FieldInfo(alias="maxAgeSeconds", default=None)
"""
Specifies the amount of time (in seconds) browsers are allowed to cache CORS
preflight responses. Browsers may limit this to 2 hours or less, even if the
maximum value (86400) is specified.
"""


class CORSGetResponse(BaseModel):
rules: Optional[List[Rule]] = None
65 changes: 65 additions & 0 deletions src/cloudflare/types/r2/buckets/cors_update_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing import List, Iterable
from typing_extensions import Literal, Required, Annotated, TypedDict

from ...._utils import PropertyInfo

__all__ = ["CORSUpdateParams", "Rule", "RuleAllowed"]


class CORSUpdateParams(TypedDict, total=False):
account_id: Required[str]
"""Account ID"""

rules: Iterable[Rule]

cf_r2_jurisdiction: Annotated[Literal["default", "eu", "fedramp"], PropertyInfo(alias="cf-r2-jurisdiction")]
"""The bucket jurisdiction"""


class RuleAllowed(TypedDict, total=False):
methods: Required[List[Literal["GET", "PUT", "POST", "DELETE", "HEAD"]]]
"""
Specifies the value for the Access-Control-Allow-Methods header R2 sets when
requesting objects in a bucket from a browser.
"""

origins: Required[List[str]]
"""
Specifies the value for the Access-Control-Allow-Origin header R2 sets when
requesting objects in a bucket from a browser.
"""

headers: List[str]
"""
Specifies the value for the Access-Control-Allow-Headers header R2 sets when
requesting objects in this bucket from a browser. Cross-origin requests that
include custom headers (e.g. x-user-id) should specify these headers as
AllowedHeaders.
"""


class Rule(TypedDict, total=False):
allowed: Required[RuleAllowed]
"""Object specifying allowed origins, methods and headers for this CORS rule."""

id: str
"""Identifier for this rule"""

expose_headers: Annotated[List[str], PropertyInfo(alias="exposeHeaders")]
"""
Specifies the headers that can be exposed back, and accessed by, the JavaScript
making the cross-origin request. If you need to access headers beyond the
safelisted response headers, such as Content-Encoding or cf-cache-status, you
must specify it here.
"""

max_age_seconds: Annotated[float, PropertyInfo(alias="maxAgeSeconds")]
"""
Specifies the amount of time (in seconds) browsers are allowed to cache CORS
preflight responses. Browsers may limit this to 2 hours or less, even if the
maximum value (86400) is specified.
"""
388 changes: 388 additions & 0 deletions tests/api_resources/r2/buckets/test_cors.py

Large diffs are not rendered by default.

0 comments on commit 8ed5f71

Please sign in to comment.