Skip to content

Commit

Permalink
feat(tokens): move condition and policy to shared models (#2158)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Nov 15, 2024
1 parent 8c246c1 commit f92d492
Show file tree
Hide file tree
Showing 20 changed files with 82 additions and 73 deletions.
24 changes: 10 additions & 14 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ from cloudflare.types import (
Subscription,
SubscriptionComponent,
SubscriptionZone,
Token,
TokenConditionCIDRList,
TokenPolicy,
TokenValue,
)
```
Expand Down Expand Up @@ -96,10 +99,10 @@ from cloudflare.types.accounts import TokenCreateResponse, TokenDeleteResponse,
Methods:

- <code title="post /accounts/{account_id}/tokens">client.accounts.tokens.<a href="./src/cloudflare/resources/accounts/tokens/tokens.py">create</a>(\*, account_id, \*\*<a href="src/cloudflare/types/accounts/token_create_params.py">params</a>) -> <a href="./src/cloudflare/types/accounts/token_create_response.py">Optional</a></code>
- <code title="put /accounts/{account_id}/tokens/{token_id}">client.accounts.tokens.<a href="./src/cloudflare/resources/accounts/tokens/tokens.py">update</a>(token_id, \*, account_id, \*\*<a href="src/cloudflare/types/accounts/token_update_params.py">params</a>) -> <a href="./src/cloudflare/types/user/token.py">Optional</a></code>
- <code title="get /accounts/{account_id}/tokens">client.accounts.tokens.<a href="./src/cloudflare/resources/accounts/tokens/tokens.py">list</a>(\*, account_id, \*\*<a href="src/cloudflare/types/accounts/token_list_params.py">params</a>) -> <a href="./src/cloudflare/types/user/token.py">SyncV4PagePaginationArray[Token]</a></code>
- <code title="put /accounts/{account_id}/tokens/{token_id}">client.accounts.tokens.<a href="./src/cloudflare/resources/accounts/tokens/tokens.py">update</a>(token_id, \*, account_id, \*\*<a href="src/cloudflare/types/accounts/token_update_params.py">params</a>) -> <a href="./src/cloudflare/types/shared/token.py">Optional</a></code>
- <code title="get /accounts/{account_id}/tokens">client.accounts.tokens.<a href="./src/cloudflare/resources/accounts/tokens/tokens.py">list</a>(\*, account_id, \*\*<a href="src/cloudflare/types/accounts/token_list_params.py">params</a>) -> <a href="./src/cloudflare/types/shared/token.py">SyncV4PagePaginationArray[Token]</a></code>
- <code title="delete /accounts/{account_id}/tokens/{token_id}">client.accounts.tokens.<a href="./src/cloudflare/resources/accounts/tokens/tokens.py">delete</a>(token_id, \*, account_id) -> <a href="./src/cloudflare/types/accounts/token_delete_response.py">Optional</a></code>
- <code title="get /accounts/{account_id}/tokens/{token_id}">client.accounts.tokens.<a href="./src/cloudflare/resources/accounts/tokens/tokens.py">get</a>(token_id, \*, account_id) -> <a href="./src/cloudflare/types/user/token.py">Optional</a></code>
- <code title="get /accounts/{account_id}/tokens/{token_id}">client.accounts.tokens.<a href="./src/cloudflare/resources/accounts/tokens/tokens.py">get</a>(token_id, \*, account_id) -> <a href="./src/cloudflare/types/shared/token.py">Optional</a></code>
- <code title="get /accounts/{account_id}/tokens/verify">client.accounts.tokens.<a href="./src/cloudflare/resources/accounts/tokens/tokens.py">verify</a>(\*, account_id) -> <a href="./src/cloudflare/types/accounts/token_verify_response.py">Optional</a></code>

### PermissionGroups
Expand Down Expand Up @@ -266,23 +269,16 @@ Methods:
Types:

```python
from cloudflare.types.user import (
CIDRList,
Policy,
Token,
TokenCreateResponse,
TokenDeleteResponse,
TokenVerifyResponse,
)
from cloudflare.types.user import TokenCreateResponse, TokenDeleteResponse, TokenVerifyResponse
```

Methods:

- <code title="post /user/tokens">client.user.tokens.<a href="./src/cloudflare/resources/user/tokens/tokens.py">create</a>(\*\*<a href="src/cloudflare/types/user/token_create_params.py">params</a>) -> <a href="./src/cloudflare/types/user/token_create_response.py">Optional</a></code>
- <code title="put /user/tokens/{token_id}">client.user.tokens.<a href="./src/cloudflare/resources/user/tokens/tokens.py">update</a>(token_id, \*\*<a href="src/cloudflare/types/user/token_update_params.py">params</a>) -> <a href="./src/cloudflare/types/user/token.py">Optional</a></code>
- <code title="get /user/tokens">client.user.tokens.<a href="./src/cloudflare/resources/user/tokens/tokens.py">list</a>(\*\*<a href="src/cloudflare/types/user/token_list_params.py">params</a>) -> <a href="./src/cloudflare/types/user/token.py">SyncV4PagePaginationArray[Token]</a></code>
- <code title="put /user/tokens/{token_id}">client.user.tokens.<a href="./src/cloudflare/resources/user/tokens/tokens.py">update</a>(token_id, \*\*<a href="src/cloudflare/types/user/token_update_params.py">params</a>) -> <a href="./src/cloudflare/types/shared/token.py">Optional</a></code>
- <code title="get /user/tokens">client.user.tokens.<a href="./src/cloudflare/resources/user/tokens/tokens.py">list</a>(\*\*<a href="src/cloudflare/types/user/token_list_params.py">params</a>) -> <a href="./src/cloudflare/types/shared/token.py">SyncV4PagePaginationArray[Token]</a></code>
- <code title="delete /user/tokens/{token_id}">client.user.tokens.<a href="./src/cloudflare/resources/user/tokens/tokens.py">delete</a>(token_id) -> <a href="./src/cloudflare/types/user/token_delete_response.py">Optional</a></code>
- <code title="get /user/tokens/{token_id}">client.user.tokens.<a href="./src/cloudflare/resources/user/tokens/tokens.py">get</a>(token_id) -> <a href="./src/cloudflare/types/user/token.py">Optional</a></code>
- <code title="get /user/tokens/{token_id}">client.user.tokens.<a href="./src/cloudflare/resources/user/tokens/tokens.py">get</a>(token_id) -> <a href="./src/cloudflare/types/shared/token.py">Optional</a></code>
- <code title="get /user/tokens/verify">client.user.tokens.<a href="./src/cloudflare/resources/user/tokens/tokens.py">verify</a>() -> <a href="./src/cloudflare/types/user/token_verify_response.py">Optional</a></code>

### PermissionGroups
Expand Down
12 changes: 6 additions & 6 deletions src/cloudflare/resources/accounts/tokens/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
PermissionGroupsResourceWithStreamingResponse,
AsyncPermissionGroupsResourceWithStreamingResponse,
)
from ....types.user.token import Token
from ....types.user.policy_param import PolicyParam
from ....types.shared.token import Token
from ....types.shared_params.token_policy import TokenPolicy
from ....types.accounts.token_create_response import TokenCreateResponse
from ....types.accounts.token_delete_response import TokenDeleteResponse
from ....types.accounts.token_verify_response import TokenVerifyResponse
Expand Down Expand Up @@ -83,7 +83,7 @@ def create(
*,
account_id: str,
name: str,
policies: Iterable[PolicyParam],
policies: Iterable[TokenPolicy],
condition: token_create_params.Condition | NotGiven = NOT_GIVEN,
expires_on: Union[str, datetime] | NotGiven = NOT_GIVEN,
not_before: Union[str, datetime] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -147,7 +147,7 @@ def update(
*,
account_id: str,
name: str,
policies: Iterable[PolicyParam],
policies: Iterable[TokenPolicy],
status: Literal["active", "disabled", "expired"],
condition: token_update_params.Condition | NotGiven = NOT_GIVEN,
expires_on: Union[str, datetime] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -430,7 +430,7 @@ async def create(
*,
account_id: str,
name: str,
policies: Iterable[PolicyParam],
policies: Iterable[TokenPolicy],
condition: token_create_params.Condition | NotGiven = NOT_GIVEN,
expires_on: Union[str, datetime] | NotGiven = NOT_GIVEN,
not_before: Union[str, datetime] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -494,7 +494,7 @@ async def update(
*,
account_id: str,
name: str,
policies: Iterable[PolicyParam],
policies: Iterable[TokenPolicy],
status: Literal["active", "disabled", "expired"],
condition: token_update_params.Condition | NotGiven = NOT_GIVEN,
expires_on: Union[str, datetime] | NotGiven = NOT_GIVEN,
Expand Down
12 changes: 6 additions & 6 deletions src/cloudflare/resources/user/tokens/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
PermissionGroupsResourceWithStreamingResponse,
AsyncPermissionGroupsResourceWithStreamingResponse,
)
from ....types.user.token import Token
from ....types.user.policy_param import PolicyParam
from ....types.shared.token import Token
from ....types.shared_params.token_policy import TokenPolicy
from ....types.user.token_create_response import TokenCreateResponse
from ....types.user.token_delete_response import TokenDeleteResponse
from ....types.user.token_verify_response import TokenVerifyResponse
Expand Down Expand Up @@ -82,7 +82,7 @@ def create(
self,
*,
name: str,
policies: Iterable[PolicyParam],
policies: Iterable[TokenPolicy],
condition: token_create_params.Condition | NotGiven = NOT_GIVEN,
expires_on: Union[str, datetime] | NotGiven = NOT_GIVEN,
not_before: Union[str, datetime] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -141,7 +141,7 @@ def update(
token_id: str,
*,
name: str,
policies: Iterable[PolicyParam],
policies: Iterable[TokenPolicy],
status: Literal["active", "disabled", "expired"],
condition: token_update_params.Condition | NotGiven = NOT_GIVEN,
expires_on: Union[str, datetime] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -388,7 +388,7 @@ async def create(
self,
*,
name: str,
policies: Iterable[PolicyParam],
policies: Iterable[TokenPolicy],
condition: token_create_params.Condition | NotGiven = NOT_GIVEN,
expires_on: Union[str, datetime] | NotGiven = NOT_GIVEN,
not_before: Union[str, datetime] | NotGiven = NOT_GIVEN,
Expand Down Expand Up @@ -447,7 +447,7 @@ async def update(
token_id: str,
*,
name: str,
policies: Iterable[PolicyParam],
policies: Iterable[TokenPolicy],
status: Literal["active", "disabled", "expired"],
condition: token_update_params.Condition | NotGiven = NOT_GIVEN,
expires_on: Union[str, datetime] | NotGiven = NOT_GIVEN,
Expand Down
3 changes: 3 additions & 0 deletions src/cloudflare/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from .shared import (
ASN as ASN,
Role as Role,
Token as Token,
Member as Member,
Result as Result,
AuditLog as AuditLog,
Expand All @@ -13,6 +14,7 @@
Identifier as Identifier,
Permission as Permission,
TokenValue as TokenValue,
TokenPolicy as TokenPolicy,
ResponseInfo as ResponseInfo,
Subscription as Subscription,
CertificateCA as CertificateCA,
Expand All @@ -24,6 +26,7 @@
LoadBalancerPreview as LoadBalancerPreview,
SubscriptionComponent as SubscriptionComponent,
CertificateRequestType as CertificateRequestType,
TokenConditionCIDRList as TokenConditionCIDRList,
)
from .workflow_list_params import WorkflowListParams as WorkflowListParams
from .workflow_get_response import WorkflowGetResponse as WorkflowGetResponse
Expand Down
10 changes: 5 additions & 5 deletions src/cloudflare/types/accounts/token_create_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from typing_extensions import Required, Annotated, TypedDict

from ..._utils import PropertyInfo
from ..user.cidr_list import CIDRList
from ..user.policy_param import PolicyParam
from ..shared_params.token_policy import TokenPolicy
from ..shared.token_condition_cidr_list import TokenConditionCIDRList

__all__ = ["TokenCreateParams", "Condition", "ConditionRequestIP"]

Expand All @@ -20,7 +20,7 @@ class TokenCreateParams(TypedDict, total=False):
name: Required[str]
"""Token name."""

policies: Required[Iterable[PolicyParam]]
policies: Required[Iterable[TokenPolicy]]
"""List of access policies assigned to the token."""

condition: Condition
Expand All @@ -38,14 +38,14 @@ class TokenCreateParams(TypedDict, total=False):
_ConditionRequestIPReservedKeywords = TypedDict(
"_ConditionRequestIPReservedKeywords",
{
"in": List[CIDRList],
"in": List[TokenConditionCIDRList],
},
total=False,
)


class ConditionRequestIP(_ConditionRequestIPReservedKeywords, total=False):
not_in: List[CIDRList]
not_in: List[TokenConditionCIDRList]
"""List of IPv4/IPv6 CIDR addresses."""


Expand Down
10 changes: 5 additions & 5 deletions src/cloudflare/types/accounts/token_create_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
from pydantic import Field as FieldInfo

from ..._models import BaseModel
from ..user.policy import Policy
from ..user.cidr_list import CIDRList
from ..shared.token_value import TokenValue
from ..shared.token_policy import TokenPolicy
from ..shared.token_condition_cidr_list import TokenConditionCIDRList

__all__ = ["TokenCreateResponse", "Condition", "ConditionRequestIP"]


class ConditionRequestIP(BaseModel):
in_: Optional[List[CIDRList]] = FieldInfo(alias="in", default=None)
in_: Optional[List[TokenConditionCIDRList]] = FieldInfo(alias="in", default=None)
"""List of IPv4/IPv6 CIDR addresses."""

not_in: Optional[List[CIDRList]] = None
not_in: Optional[List[TokenConditionCIDRList]] = None
"""List of IPv4/IPv6 CIDR addresses."""


Expand Down Expand Up @@ -54,7 +54,7 @@ class TokenCreateResponse(BaseModel):
not_before: Optional[datetime] = None
"""The time before which the token MUST NOT be accepted for processing."""

policies: Optional[List[Policy]] = None
policies: Optional[List[TokenPolicy]] = None
"""List of access policies assigned to the token."""

status: Optional[Literal["active", "disabled", "expired"]] = None
Expand Down
10 changes: 5 additions & 5 deletions src/cloudflare/types/accounts/token_update_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from typing_extensions import Literal, Required, Annotated, TypedDict

from ..._utils import PropertyInfo
from ..user.cidr_list import CIDRList
from ..user.policy_param import PolicyParam
from ..shared_params.token_policy import TokenPolicy
from ..shared.token_condition_cidr_list import TokenConditionCIDRList

__all__ = ["TokenUpdateParams", "Condition", "ConditionRequestIP"]

Expand All @@ -20,7 +20,7 @@ class TokenUpdateParams(TypedDict, total=False):
name: Required[str]
"""Token name."""

policies: Required[Iterable[PolicyParam]]
policies: Required[Iterable[TokenPolicy]]
"""List of access policies assigned to the token."""

status: Required[Literal["active", "disabled", "expired"]]
Expand All @@ -41,14 +41,14 @@ class TokenUpdateParams(TypedDict, total=False):
_ConditionRequestIPReservedKeywords = TypedDict(
"_ConditionRequestIPReservedKeywords",
{
"in": List[CIDRList],
"in": List[TokenConditionCIDRList],
},
total=False,
)


class ConditionRequestIP(_ConditionRequestIPReservedKeywords, total=False):
not_in: List[CIDRList]
not_in: List[TokenConditionCIDRList]
"""List of IPv4/IPv6 CIDR addresses."""


Expand Down
3 changes: 3 additions & 0 deletions src/cloudflare/types/shared/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .asn import ASN as ASN
from .role import Role as Role
from .token import Token as Token
from .member import Member as Member
from .result import Result as Result
from .audit_log import AuditLog as AuditLog
Expand All @@ -11,6 +12,7 @@
from .permission import Permission as Permission
from .token_value import TokenValue as TokenValue
from .subscription import Subscription as Subscription
from .token_policy import TokenPolicy as TokenPolicy
from .response_info import ResponseInfo as ResponseInfo
from .certificate_ca import CertificateCA as CertificateCA
from .sort_direction import SortDirection as SortDirection
Expand All @@ -21,3 +23,4 @@
from .load_balancer_preview import LoadBalancerPreview as LoadBalancerPreview
from .subscription_component import SubscriptionComponent as SubscriptionComponent
from .certificate_request_type import CertificateRequestType as CertificateRequestType
from .token_condition_cidr_list import TokenConditionCIDRList as TokenConditionCIDRList
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@

from pydantic import Field as FieldInfo

from .policy import Policy
from ..._models import BaseModel
from .cidr_list import CIDRList
from .token_policy import TokenPolicy
from .token_condition_cidr_list import TokenConditionCIDRList

__all__ = ["Token", "Condition", "ConditionRequestIP"]


class ConditionRequestIP(BaseModel):
in_: Optional[List[CIDRList]] = FieldInfo(alias="in", default=None)
in_: Optional[List[TokenConditionCIDRList]] = FieldInfo(alias="in", default=None)
"""List of IPv4/IPv6 CIDR addresses."""

not_in: Optional[List[CIDRList]] = None
not_in: Optional[List[TokenConditionCIDRList]] = None
"""List of IPv4/IPv6 CIDR addresses."""


Expand Down Expand Up @@ -53,7 +53,7 @@ class Token(BaseModel):
not_before: Optional[datetime] = None
"""The time before which the token MUST NOT be accepted for processing."""

policies: Optional[List[Policy]] = None
policies: Optional[List[TokenPolicy]] = None
"""List of access policies assigned to the token."""

status: Optional[Literal["active", "disabled", "expired"]] = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

from typing_extensions import TypeAlias

__all__ = ["CIDRList"]
__all__ = ["TokenConditionCIDRList"]

CIDRList: TypeAlias = str
TokenConditionCIDRList: TypeAlias = str
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from ..._models import BaseModel

__all__ = ["Policy", "PermissionGroup", "PermissionGroupMeta", "Resources"]
__all__ = ["TokenPolicy", "PermissionGroup", "PermissionGroupMeta", "Resources"]


class PermissionGroupMeta(BaseModel):
Expand All @@ -31,7 +31,7 @@ class Resources(BaseModel):
scope: Optional[str] = None


class Policy(BaseModel):
class TokenPolicy(BaseModel):
id: str
"""Policy identifier."""

Expand Down
2 changes: 2 additions & 0 deletions src/cloudflare/types/shared_params/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from .asn import ASN as ASN
from .role import Role as Role
from .rate_plan import RatePlan as RatePlan
from .token_policy import TokenPolicy as TokenPolicy
from .certificate_ca import CertificateCA as CertificateCA
from .sort_direction import SortDirection as SortDirection
from .permission_grant import PermissionGrant as PermissionGrant
from .certificate_request_type import CertificateRequestType as CertificateRequestType
from .token_condition_cidr_list import TokenConditionCIDRList as TokenConditionCIDRList
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

from __future__ import annotations

from typing_extensions import TypeAlias

__all__ = ["TokenConditionCIDRList"]

TokenConditionCIDRList: TypeAlias = str
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from typing import Iterable
from typing_extensions import Literal, Required, TypedDict

__all__ = ["PolicyParam", "PermissionGroup", "PermissionGroupMeta", "Resources"]
__all__ = ["TokenPolicy", "PermissionGroup", "PermissionGroupMeta", "Resources"]


class PermissionGroupMeta(TypedDict, total=False):
Expand All @@ -25,7 +25,7 @@ class Resources(TypedDict, total=False):
scope: str


class PolicyParam(TypedDict, total=False):
class TokenPolicy(TypedDict, total=False):
effect: Required[Literal["allow", "deny"]]
"""Allow or deny operations against the resources."""

Expand Down
Loading

0 comments on commit f92d492

Please sign in to comment.