|
8 | 8 | EnvironmentRoleList, |
9 | 9 | ) |
10 | 10 | from workos.types.authorization.organization_role import OrganizationRole |
| 11 | +from workos.types.authorization.organization_membership import ( |
| 12 | + AuthorizationOrganizationMembership, |
| 13 | +) |
11 | 14 | from workos.types.authorization.permission import Permission |
12 | 15 | from workos.types.authorization.resource import Resource |
13 | 16 | from workos.types.authorization.role import Role, RoleList |
@@ -56,6 +59,34 @@ class PermissionListFilters(ListArgs, total=False): |
56 | 59 | ] |
57 | 60 |
|
58 | 61 |
|
| 62 | +class ResourcesForMembershipListFilters(ListArgs, total=False): |
| 63 | + organization_membership_id: str |
| 64 | + resource_type: Optional[str] |
| 65 | + parent_resource_id: Optional[str] |
| 66 | + parent_organization_id: Optional[str] |
| 67 | + parent_resource_type: Optional[str] |
| 68 | + parent_external_id: Optional[str] |
| 69 | + |
| 70 | + |
| 71 | +ResourcesForMembershipListResource = WorkOSListResource[ |
| 72 | + Resource, ResourcesForMembershipListFilters, ListMetadata |
| 73 | +] |
| 74 | + |
| 75 | + |
| 76 | +class MembershipsForResourceListFilters(ListArgs, total=False): |
| 77 | + resource_id: str |
| 78 | + organization_id: str |
| 79 | + resource_type: str |
| 80 | + external_id: str |
| 81 | + |
| 82 | + |
| 83 | +MembershipsForResourceListResource = WorkOSListResource[ |
| 84 | + AuthorizationOrganizationMembership, |
| 85 | + MembershipsForResourceListFilters, |
| 86 | + ListMetadata, |
| 87 | +] |
| 88 | + |
| 89 | + |
59 | 90 | class AuthorizationModule(Protocol): |
60 | 91 | """Offers methods through the WorkOS Authorization service.""" |
61 | 92 |
|
@@ -206,6 +237,45 @@ def delete_resource( |
206 | 237 | cascade_delete: Optional[bool] = None, |
207 | 238 | ) -> SyncOrAsync[None]: ... |
208 | 239 |
|
| 240 | + # Resource-Membership Relationships |
| 241 | + |
| 242 | + def list_resources_for_membership( |
| 243 | + self, |
| 244 | + organization_membership_id: str, |
| 245 | + *, |
| 246 | + resource_type: Optional[str] = None, |
| 247 | + parent_resource_id: Optional[str] = None, |
| 248 | + parent_organization_id: Optional[str] = None, |
| 249 | + parent_resource_type: Optional[str] = None, |
| 250 | + parent_external_id: Optional[str] = None, |
| 251 | + limit: int = DEFAULT_LIST_RESPONSE_LIMIT, |
| 252 | + order: PaginationOrder = "desc", |
| 253 | + before: Optional[str] = None, |
| 254 | + after: Optional[str] = None, |
| 255 | + ) -> SyncOrAsync[ResourcesForMembershipListResource]: ... |
| 256 | + |
| 257 | + def list_memberships_for_resource( |
| 258 | + self, |
| 259 | + resource_id: str, |
| 260 | + *, |
| 261 | + limit: int = DEFAULT_LIST_RESPONSE_LIMIT, |
| 262 | + order: PaginationOrder = "desc", |
| 263 | + before: Optional[str] = None, |
| 264 | + after: Optional[str] = None, |
| 265 | + ) -> SyncOrAsync[MembershipsForResourceListResource]: ... |
| 266 | + |
| 267 | + def list_memberships_for_resource_by_external_id( |
| 268 | + self, |
| 269 | + organization_id: str, |
| 270 | + resource_type: str, |
| 271 | + external_id: str, |
| 272 | + *, |
| 273 | + limit: int = DEFAULT_LIST_RESPONSE_LIMIT, |
| 274 | + order: PaginationOrder = "desc", |
| 275 | + before: Optional[str] = None, |
| 276 | + after: Optional[str] = None, |
| 277 | + ) -> SyncOrAsync[MembershipsForResourceListResource]: ... |
| 278 | + |
209 | 279 |
|
210 | 280 | class Authorization(AuthorizationModule): |
211 | 281 | _http_client: SyncHTTPClient |
@@ -558,6 +628,128 @@ def delete_resource( |
558 | 628 | method=REQUEST_METHOD_DELETE, |
559 | 629 | ) |
560 | 630 |
|
| 631 | + # Resource-Membership Relationships |
| 632 | + |
| 633 | + def list_resources_for_membership( |
| 634 | + self, |
| 635 | + organization_membership_id: str, |
| 636 | + *, |
| 637 | + resource_type: Optional[str] = None, |
| 638 | + parent_resource_id: Optional[str] = None, |
| 639 | + parent_organization_id: Optional[str] = None, |
| 640 | + parent_resource_type: Optional[str] = None, |
| 641 | + parent_external_id: Optional[str] = None, |
| 642 | + limit: int = DEFAULT_LIST_RESPONSE_LIMIT, |
| 643 | + order: PaginationOrder = "desc", |
| 644 | + before: Optional[str] = None, |
| 645 | + after: Optional[str] = None, |
| 646 | + ) -> ResourcesForMembershipListResource: |
| 647 | + list_params: ResourcesForMembershipListFilters = { |
| 648 | + "limit": limit, |
| 649 | + "order": order, |
| 650 | + "before": before, |
| 651 | + "after": after, |
| 652 | + } |
| 653 | + |
| 654 | + if resource_type is not None: |
| 655 | + list_params["resource_type"] = resource_type |
| 656 | + |
| 657 | + # Parent by internal ID and by external ID are mutually exclusive |
| 658 | + if parent_resource_id is not None and parent_organization_id is not None: |
| 659 | + raise ValueError( |
| 660 | + "parent_resource_id and parent_organization_id are mutually exclusive" |
| 661 | + ) |
| 662 | + |
| 663 | + if parent_resource_id is not None: |
| 664 | + list_params["parent_resource_id"] = parent_resource_id |
| 665 | + elif parent_organization_id is not None: |
| 666 | + list_params["parent_organization_id"] = parent_organization_id |
| 667 | + if parent_resource_type is not None: |
| 668 | + list_params["parent_resource_type"] = parent_resource_type |
| 669 | + if parent_external_id is not None: |
| 670 | + list_params["parent_external_id"] = parent_external_id |
| 671 | + |
| 672 | + response = self._http_client.request( |
| 673 | + f"authorization/organization_memberships/{organization_membership_id}/resources", |
| 674 | + method=REQUEST_METHOD_GET, |
| 675 | + params=list_params, |
| 676 | + ) |
| 677 | + |
| 678 | + # Add path param to list_args for pagination iterator |
| 679 | + list_params["organization_membership_id"] = organization_membership_id |
| 680 | + |
| 681 | + return ResourcesForMembershipListResource( |
| 682 | + list_method=self.list_resources_for_membership, |
| 683 | + list_args=list_params, |
| 684 | + **ListPage[Resource](**response).model_dump(), |
| 685 | + ) |
| 686 | + |
| 687 | + def list_memberships_for_resource( |
| 688 | + self, |
| 689 | + resource_id: str, |
| 690 | + *, |
| 691 | + limit: int = DEFAULT_LIST_RESPONSE_LIMIT, |
| 692 | + order: PaginationOrder = "desc", |
| 693 | + before: Optional[str] = None, |
| 694 | + after: Optional[str] = None, |
| 695 | + ) -> MembershipsForResourceListResource: |
| 696 | + list_params: MembershipsForResourceListFilters = { |
| 697 | + "limit": limit, |
| 698 | + "order": order, |
| 699 | + "before": before, |
| 700 | + "after": after, |
| 701 | + } |
| 702 | + |
| 703 | + response = self._http_client.request( |
| 704 | + f"authorization/resources/{resource_id}/organization_memberships", |
| 705 | + method=REQUEST_METHOD_GET, |
| 706 | + params=list_params, |
| 707 | + ) |
| 708 | + |
| 709 | + # Add path param to list_args for pagination iterator |
| 710 | + list_params["resource_id"] = resource_id |
| 711 | + |
| 712 | + return MembershipsForResourceListResource( |
| 713 | + list_method=self.list_memberships_for_resource, |
| 714 | + list_args=list_params, |
| 715 | + **ListPage[AuthorizationOrganizationMembership](**response).model_dump(), |
| 716 | + ) |
| 717 | + |
| 718 | + def list_memberships_for_resource_by_external_id( |
| 719 | + self, |
| 720 | + organization_id: str, |
| 721 | + resource_type: str, |
| 722 | + external_id: str, |
| 723 | + *, |
| 724 | + limit: int = DEFAULT_LIST_RESPONSE_LIMIT, |
| 725 | + order: PaginationOrder = "desc", |
| 726 | + before: Optional[str] = None, |
| 727 | + after: Optional[str] = None, |
| 728 | + ) -> MembershipsForResourceListResource: |
| 729 | + list_params: MembershipsForResourceListFilters = { |
| 730 | + "limit": limit, |
| 731 | + "order": order, |
| 732 | + "before": before, |
| 733 | + "after": after, |
| 734 | + } |
| 735 | + |
| 736 | + response = self._http_client.request( |
| 737 | + f"authorization/organizations/{organization_id}/resources/{resource_type}/{external_id}/organization_memberships", |
| 738 | + method=REQUEST_METHOD_GET, |
| 739 | + params=list_params, |
| 740 | + ) |
| 741 | + |
| 742 | + # Add path params to list_args for pagination iterator |
| 743 | + list_params["organization_id"] = organization_id |
| 744 | + list_params["resource_type"] = resource_type |
| 745 | + list_params["external_id"] = external_id |
| 746 | + |
| 747 | + return MembershipsForResourceListResource( |
| 748 | + list_method=self.list_memberships_for_resource_by_external_id, |
| 749 | + list_args=list_params, |
| 750 | + **ListPage[AuthorizationOrganizationMembership](**response).model_dump(), |
| 751 | + ) |
| 752 | + |
561 | 753 |
|
562 | 754 | class AsyncAuthorization(AuthorizationModule): |
563 | 755 | _http_client: AsyncHTTPClient |
@@ -909,3 +1101,125 @@ async def delete_resource( |
909 | 1101 | f"{AUTHORIZATION_RESOURCES_PATH}/{resource_id}", |
910 | 1102 | method=REQUEST_METHOD_DELETE, |
911 | 1103 | ) |
| 1104 | + |
| 1105 | + # Resource-Membership Relationships |
| 1106 | + |
| 1107 | + async def list_resources_for_membership( |
| 1108 | + self, |
| 1109 | + organization_membership_id: str, |
| 1110 | + *, |
| 1111 | + resource_type: Optional[str] = None, |
| 1112 | + parent_resource_id: Optional[str] = None, |
| 1113 | + parent_organization_id: Optional[str] = None, |
| 1114 | + parent_resource_type: Optional[str] = None, |
| 1115 | + parent_external_id: Optional[str] = None, |
| 1116 | + limit: int = DEFAULT_LIST_RESPONSE_LIMIT, |
| 1117 | + order: PaginationOrder = "desc", |
| 1118 | + before: Optional[str] = None, |
| 1119 | + after: Optional[str] = None, |
| 1120 | + ) -> ResourcesForMembershipListResource: |
| 1121 | + list_params: ResourcesForMembershipListFilters = { |
| 1122 | + "limit": limit, |
| 1123 | + "order": order, |
| 1124 | + "before": before, |
| 1125 | + "after": after, |
| 1126 | + } |
| 1127 | + |
| 1128 | + if resource_type is not None: |
| 1129 | + list_params["resource_type"] = resource_type |
| 1130 | + |
| 1131 | + # Parent by internal ID and by external ID are mutually exclusive |
| 1132 | + if parent_resource_id is not None and parent_organization_id is not None: |
| 1133 | + raise ValueError( |
| 1134 | + "parent_resource_id and parent_organization_id are mutually exclusive" |
| 1135 | + ) |
| 1136 | + |
| 1137 | + if parent_resource_id is not None: |
| 1138 | + list_params["parent_resource_id"] = parent_resource_id |
| 1139 | + elif parent_organization_id is not None: |
| 1140 | + list_params["parent_organization_id"] = parent_organization_id |
| 1141 | + if parent_resource_type is not None: |
| 1142 | + list_params["parent_resource_type"] = parent_resource_type |
| 1143 | + if parent_external_id is not None: |
| 1144 | + list_params["parent_external_id"] = parent_external_id |
| 1145 | + |
| 1146 | + response = await self._http_client.request( |
| 1147 | + f"authorization/organization_memberships/{organization_membership_id}/resources", |
| 1148 | + method=REQUEST_METHOD_GET, |
| 1149 | + params=list_params, |
| 1150 | + ) |
| 1151 | + |
| 1152 | + # Add path param to list_args for pagination iterator |
| 1153 | + list_params["organization_membership_id"] = organization_membership_id |
| 1154 | + |
| 1155 | + return ResourcesForMembershipListResource( |
| 1156 | + list_method=self.list_resources_for_membership, |
| 1157 | + list_args=list_params, |
| 1158 | + **ListPage[Resource](**response).model_dump(), |
| 1159 | + ) |
| 1160 | + |
| 1161 | + async def list_memberships_for_resource( |
| 1162 | + self, |
| 1163 | + resource_id: str, |
| 1164 | + *, |
| 1165 | + limit: int = DEFAULT_LIST_RESPONSE_LIMIT, |
| 1166 | + order: PaginationOrder = "desc", |
| 1167 | + before: Optional[str] = None, |
| 1168 | + after: Optional[str] = None, |
| 1169 | + ) -> MembershipsForResourceListResource: |
| 1170 | + list_params: MembershipsForResourceListFilters = { |
| 1171 | + "limit": limit, |
| 1172 | + "order": order, |
| 1173 | + "before": before, |
| 1174 | + "after": after, |
| 1175 | + } |
| 1176 | + |
| 1177 | + response = await self._http_client.request( |
| 1178 | + f"authorization/resources/{resource_id}/organization_memberships", |
| 1179 | + method=REQUEST_METHOD_GET, |
| 1180 | + params=list_params, |
| 1181 | + ) |
| 1182 | + |
| 1183 | + # Add path param to list_args for pagination iterator |
| 1184 | + list_params["resource_id"] = resource_id |
| 1185 | + |
| 1186 | + return MembershipsForResourceListResource( |
| 1187 | + list_method=self.list_memberships_for_resource, |
| 1188 | + list_args=list_params, |
| 1189 | + **ListPage[AuthorizationOrganizationMembership](**response).model_dump(), |
| 1190 | + ) |
| 1191 | + |
| 1192 | + async def list_memberships_for_resource_by_external_id( |
| 1193 | + self, |
| 1194 | + organization_id: str, |
| 1195 | + resource_type: str, |
| 1196 | + external_id: str, |
| 1197 | + *, |
| 1198 | + limit: int = DEFAULT_LIST_RESPONSE_LIMIT, |
| 1199 | + order: PaginationOrder = "desc", |
| 1200 | + before: Optional[str] = None, |
| 1201 | + after: Optional[str] = None, |
| 1202 | + ) -> MembershipsForResourceListResource: |
| 1203 | + list_params: MembershipsForResourceListFilters = { |
| 1204 | + "limit": limit, |
| 1205 | + "order": order, |
| 1206 | + "before": before, |
| 1207 | + "after": after, |
| 1208 | + } |
| 1209 | + |
| 1210 | + response = await self._http_client.request( |
| 1211 | + f"authorization/organizations/{organization_id}/resources/{resource_type}/{external_id}/organization_memberships", |
| 1212 | + method=REQUEST_METHOD_GET, |
| 1213 | + params=list_params, |
| 1214 | + ) |
| 1215 | + |
| 1216 | + # Add path params to list_args for pagination iterator |
| 1217 | + list_params["organization_id"] = organization_id |
| 1218 | + list_params["resource_type"] = resource_type |
| 1219 | + list_params["external_id"] = external_id |
| 1220 | + |
| 1221 | + return MembershipsForResourceListResource( |
| 1222 | + list_method=self.list_memberships_for_resource_by_external_id, |
| 1223 | + list_args=list_params, |
| 1224 | + **ListPage[AuthorizationOrganizationMembership](**response).model_dump(), |
| 1225 | + ) |
0 commit comments