Skip to content

Commit ab35617

Browse files
adding base types and module registraiton
1 parent 716622c commit ab35617

File tree

8 files changed

+114
-3
lines changed

8 files changed

+114
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1+
from workos.types.authorization.access_evaluation import AccessEvaluation
12
from workos.types.authorization.environment_role import (
23
EnvironmentRole,
34
EnvironmentRoleList,
45
)
6+
from workos.types.authorization.organization_membership import (
7+
AuthorizationOrganizationMembership,
8+
)
59
from workos.types.authorization.organization_role import (
610
OrganizationRole,
711
OrganizationRoleEvent,
812
OrganizationRoleList,
913
)
1014
from workos.types.authorization.permission import Permission
15+
from workos.types.authorization.resource import Resource
1116
from workos.types.authorization.role import (
1217
Role,
1318
RoleList,
1419
)
20+
from workos.types.authorization.role_assignment import RoleAssignment
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from workos.types.workos_model import WorkOSModel
2+
3+
4+
class AccessEvaluation(WorkOSModel):
5+
"""Representation of a WorkOS Authorization access check result."""
6+
7+
authorized: bool
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from typing import Any, Literal, Mapping, Optional
2+
3+
from workos.types.workos_model import WorkOSModel
4+
from workos.typing.literals import LiteralOrUntyped
5+
6+
OrganizationMembershipStatus = Literal["active", "inactive", "pending"]
7+
8+
9+
class AuthorizationOrganizationMembership(WorkOSModel):
10+
"""Representation of an Organization Membership returned by Authorization endpoints.
11+
12+
This is a separate type from the user_management OrganizationMembership because
13+
authorization endpoints return memberships without `role` and `organization_name` fields.
14+
"""
15+
16+
object: Literal["organization_membership"]
17+
id: str
18+
user_id: str
19+
organization_id: str
20+
status: LiteralOrUntyped[OrganizationMembershipStatus]
21+
custom_attributes: Optional[Mapping[str, Any]] = None
22+
created_at: str
23+
updated_at: str
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from typing import Any, Literal, Mapping, Optional
2+
3+
from workos.types.workos_model import WorkOSModel
4+
5+
6+
class Resource(WorkOSModel):
7+
"""Representation of a WorkOS Authorization Resource."""
8+
9+
object: Literal["authorization_resource"]
10+
id: str
11+
resource_type: str
12+
resource_id: str
13+
organization_id: str
14+
external_id: Optional[str] = None
15+
meta: Optional[Mapping[str, Any]] = None
16+
environment_id: str
17+
created_at: str
18+
updated_at: str
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import Literal
2+
3+
from workos.types.workos_model import WorkOSModel
4+
5+
6+
class RoleAssignment(WorkOSModel):
7+
"""Representation of a WorkOS Authorization Role Assignment."""
8+
9+
object: Literal["role_assignment"]
10+
id: str
11+
role_slug: str
12+
role_name: str
13+
role_id: str

src/workos/types/list_resource.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@
1919
from typing_extensions import Required, TypedDict
2020
from workos.types.api_keys import ApiKey
2121
from workos.types.audit_logs import AuditLogAction, AuditLogSchema
22+
from workos.types.authorization.organization_membership import (
23+
AuthorizationOrganizationMembership,
24+
)
2225
from workos.types.authorization.permission import Permission
26+
from workos.types.authorization.resource import Resource
27+
from workos.types.authorization.role_assignment import RoleAssignment
2328
from workos.types.directory_sync import (
2429
Directory,
2530
DirectoryGroup,
@@ -59,6 +64,9 @@
5964
Organization,
6065
OrganizationMembership,
6166
Permission,
67+
Resource,
68+
RoleAssignment,
69+
AuthorizationOrganizationMembership,
6270
AuthorizationResource,
6371
AuthorizationResourceType,
6472
User,

src/workos/utils/_base_http_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def _prepare_request(
123123
json: JsonType = None,
124124
headers: HeadersType = None,
125125
exclude_default_auth_headers: bool = False,
126+
force_include_body: bool = False,
126127
) -> PreparedRequest:
127128
"""Executes a request against the WorkOS API.
128129
@@ -134,6 +135,7 @@ def _prepare_request(
134135
params Optional[dict]: Query params or body payload to be added to the request
135136
headers Optional[dict]: Custom headers to be added to the request
136137
token Optional[str]: Bearer token
138+
force_include_body (bool): If True, allows sending a body with DELETE requests
137139
138140
Returns:
139141
dict: Response from WorkOS
@@ -149,7 +151,7 @@ def _prepare_request(
149151
REQUEST_METHOD_GET,
150152
]
151153

152-
if bodyless_http_method and json is not None:
154+
if bodyless_http_method and json is not None and not force_include_body:
153155
raise ValueError(f"Cannot send a body with a {parsed_method} request")
154156

155157
# Remove any parameters that are None
@@ -161,7 +163,7 @@ def _prepare_request(
161163
json = {k: v for k, v in json.items() if v is not None}
162164

163165
# We'll spread these return values onto the HTTP client request method
164-
if bodyless_http_method:
166+
if bodyless_http_method and not force_include_body:
165167
return {
166168
"method": parsed_method,
167169
"url": url,

src/workos/utils/http_client.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
ParamsType,
1515
ResponseJson,
1616
)
17-
from workos.utils.request_helper import REQUEST_METHOD_GET
17+
from workos.utils.request_helper import REQUEST_METHOD_DELETE, REQUEST_METHOD_GET
1818

1919

2020
class SyncHttpxClientWrapper(httpx.Client):
@@ -113,6 +113,23 @@ def request(
113113
response = self._client.request(**prepared_request_parameters)
114114
return self._handle_response(response)
115115

116+
def delete_with_body(
117+
self,
118+
path: str,
119+
json: JsonType = None,
120+
headers: HeadersType = None,
121+
) -> ResponseJson:
122+
"""Executes a DELETE request with a JSON body against the WorkOS API."""
123+
prepared_request_parameters = self._prepare_request(
124+
path=path,
125+
method=REQUEST_METHOD_DELETE,
126+
json=json,
127+
headers=headers,
128+
force_include_body=True,
129+
)
130+
response = self._client.request(**prepared_request_parameters)
131+
return self._handle_response(response)
132+
116133

117134
class AsyncHttpxClientWrapper(httpx.AsyncClient):
118135
def __del__(self) -> None:
@@ -210,5 +227,22 @@ async def request(
210227
response = await self._client.request(**prepared_request_parameters)
211228
return self._handle_response(response)
212229

230+
async def delete_with_body(
231+
self,
232+
path: str,
233+
json: JsonType = None,
234+
headers: HeadersType = None,
235+
) -> ResponseJson:
236+
"""Executes a DELETE request with a JSON body against the WorkOS API."""
237+
prepared_request_parameters = self._prepare_request(
238+
path=path,
239+
method=REQUEST_METHOD_DELETE,
240+
json=json,
241+
headers=headers,
242+
force_include_body=True,
243+
)
244+
response = await self._client.request(**prepared_request_parameters)
245+
return self._handle_response(response)
246+
213247

214248
HTTPClient = Union[AsyncHTTPClient, SyncHTTPClient]

0 commit comments

Comments
 (0)