|
| 1 | +# !!! |
| 2 | +# WARNING: This file is autogenerated |
| 3 | +# Only modify code within MANUAL() sections |
| 4 | +# or your changes may be overwritten later! |
| 5 | +# !!! |
| 6 | + |
| 7 | +from __future__ import annotations |
| 8 | + |
| 9 | +from typing import Any, Dict, Optional, Union |
| 10 | + |
| 11 | +from stytch.b2b.models.rbac import OrgPolicy |
| 12 | +from stytch.b2b.models.rbac_organizations import ( |
| 13 | + GetOrgPolicyResponse, |
| 14 | + SetOrgPolicyResponse, |
| 15 | +) |
| 16 | +from stytch.core.api_base import ApiBase |
| 17 | +from stytch.core.http.client import AsyncClient, SyncClient |
| 18 | + |
| 19 | + |
| 20 | +class Organizations: |
| 21 | + def __init__( |
| 22 | + self, api_base: ApiBase, sync_client: SyncClient, async_client: AsyncClient |
| 23 | + ) -> None: |
| 24 | + self.api_base = api_base |
| 25 | + self.sync_client = sync_client |
| 26 | + self.async_client = async_client |
| 27 | + |
| 28 | + def get_org_policy( |
| 29 | + self, |
| 30 | + organization_id: str, |
| 31 | + ) -> GetOrgPolicyResponse: |
| 32 | + """Get the active RBAC Policy for a specific Organization within your Stytch Project. An Organization RBAC Policy contains the roles that have been defined specifically for that organization, allowing for organization-specific permissioning models. |
| 33 | +
|
| 34 | + This endpoint returns the organization-scoped roles that supplement the project-level RBAC policy. Organization policies allow you to define custom roles that are specific to individual organizations within your project. |
| 35 | +
|
| 36 | + When using the backend SDKs, the RBAC Policy will be cached to allow for local evaluations, eliminating the need for an extra request to Stytch. The policy will be refreshed if an authorization check is requested and the RBAC policy was last updated more than 5 minutes ago. |
| 37 | +
|
| 38 | + Organization-specific roles can be created and managed through this API endpoint, providing fine-grained control over permissions at the organization level. |
| 39 | +
|
| 40 | + Check out the [RBAC overview](https://stytch.com/docs/b2b/guides/rbac/overview) to learn more about Stytch's RBAC permissioning model and organization-scoped policies. |
| 41 | +
|
| 42 | + Fields: |
| 43 | + - organization_id: Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience. |
| 44 | + """ # noqa |
| 45 | + headers: Dict[str, str] = {} |
| 46 | + data: Dict[str, Any] = { |
| 47 | + "organization_id": organization_id, |
| 48 | + } |
| 49 | + |
| 50 | + url = self.api_base.url_for( |
| 51 | + "/v1/b2b/rbac/organizations/{organization_id}", data |
| 52 | + ) |
| 53 | + res = self.sync_client.get(url, data, headers) |
| 54 | + return GetOrgPolicyResponse.from_json(res.response.status_code, res.json) |
| 55 | + |
| 56 | + async def get_org_policy_async( |
| 57 | + self, |
| 58 | + organization_id: str, |
| 59 | + ) -> GetOrgPolicyResponse: |
| 60 | + """Get the active RBAC Policy for a specific Organization within your Stytch Project. An Organization RBAC Policy contains the roles that have been defined specifically for that organization, allowing for organization-specific permissioning models. |
| 61 | +
|
| 62 | + This endpoint returns the organization-scoped roles that supplement the project-level RBAC policy. Organization policies allow you to define custom roles that are specific to individual organizations within your project. |
| 63 | +
|
| 64 | + When using the backend SDKs, the RBAC Policy will be cached to allow for local evaluations, eliminating the need for an extra request to Stytch. The policy will be refreshed if an authorization check is requested and the RBAC policy was last updated more than 5 minutes ago. |
| 65 | +
|
| 66 | + Organization-specific roles can be created and managed through this API endpoint, providing fine-grained control over permissions at the organization level. |
| 67 | +
|
| 68 | + Check out the [RBAC overview](https://stytch.com/docs/b2b/guides/rbac/overview) to learn more about Stytch's RBAC permissioning model and organization-scoped policies. |
| 69 | +
|
| 70 | + Fields: |
| 71 | + - organization_id: Globally unique UUID that identifies a specific Organization. The `organization_id` is critical to perform operations on an Organization, so be sure to preserve this value. You may also use the organization_slug or organization_external_id here as a convenience. |
| 72 | + """ # noqa |
| 73 | + headers: Dict[str, str] = {} |
| 74 | + data: Dict[str, Any] = { |
| 75 | + "organization_id": organization_id, |
| 76 | + } |
| 77 | + |
| 78 | + url = self.api_base.url_for( |
| 79 | + "/v1/b2b/rbac/organizations/{organization_id}", data |
| 80 | + ) |
| 81 | + res = await self.async_client.get(url, data, headers) |
| 82 | + return GetOrgPolicyResponse.from_json(res.response.status, res.json) |
| 83 | + |
| 84 | + def set_org_policy( |
| 85 | + self, |
| 86 | + organization_id: str, |
| 87 | + org_policy: Optional[Union[OrgPolicy, Dict[str, Any]]] = None, |
| 88 | + ) -> SetOrgPolicyResponse: |
| 89 | + headers: Dict[str, str] = {} |
| 90 | + data: Dict[str, Any] = { |
| 91 | + "organization_id": organization_id, |
| 92 | + } |
| 93 | + if org_policy is not None: |
| 94 | + data["org_policy"] = ( |
| 95 | + org_policy if isinstance(org_policy, dict) else org_policy.dict() |
| 96 | + ) |
| 97 | + |
| 98 | + url = self.api_base.url_for( |
| 99 | + "/v1/b2b/rbac/organizations/{organization_id}", data |
| 100 | + ) |
| 101 | + res = self.sync_client.put(url, data, headers) |
| 102 | + return SetOrgPolicyResponse.from_json(res.response.status_code, res.json) |
| 103 | + |
| 104 | + async def set_org_policy_async( |
| 105 | + self, |
| 106 | + organization_id: str, |
| 107 | + org_policy: Optional[OrgPolicy] = None, |
| 108 | + ) -> SetOrgPolicyResponse: |
| 109 | + headers: Dict[str, str] = {} |
| 110 | + data: Dict[str, Any] = { |
| 111 | + "organization_id": organization_id, |
| 112 | + } |
| 113 | + if org_policy is not None: |
| 114 | + data["org_policy"] = ( |
| 115 | + org_policy if isinstance(org_policy, dict) else org_policy.dict() |
| 116 | + ) |
| 117 | + |
| 118 | + url = self.api_base.url_for( |
| 119 | + "/v1/b2b/rbac/organizations/{organization_id}", data |
| 120 | + ) |
| 121 | + res = await self.async_client.put(url, data, headers) |
| 122 | + return SetOrgPolicyResponse.from_json(res.response.status, res.json) |
0 commit comments