workos 1.5.1__py3-none-any.whl → 5.38.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- workos/__about__.py +1 -1
- workos/__init__.py +3 -7
- workos/_base_client.py +138 -0
- workos/_client_configuration.py +10 -0
- workos/api_keys.py +53 -0
- workos/async_client.py +144 -0
- workos/audit_logs.py +125 -0
- workos/client.py +110 -18
- workos/directory_sync.py +379 -99
- workos/events.py +111 -0
- workos/exceptions.py +53 -26
- workos/fga.py +649 -0
- workos/mfa.py +205 -0
- workos/organization_domains.py +179 -0
- workos/organizations.py +403 -73
- workos/passwordless.py +67 -43
- workos/pipes.py +93 -0
- workos/portal.py +51 -28
- workos/session.py +337 -0
- workos/sso.py +311 -101
- workos/types/__init__.py +4 -0
- workos/types/api_keys/__init__.py +1 -0
- workos/types/api_keys/api_keys.py +20 -0
- workos/types/audit_logs/__init__.py +6 -0
- workos/types/audit_logs/audit_log_event.py +16 -0
- workos/types/audit_logs/audit_log_event_actor.py +12 -0
- workos/types/audit_logs/audit_log_event_context.py +8 -0
- workos/types/audit_logs/audit_log_event_target.py +12 -0
- workos/types/audit_logs/audit_log_export.py +18 -0
- workos/types/audit_logs/audit_log_metadata.py +4 -0
- workos/types/directory_sync/__init__.py +5 -0
- workos/types/directory_sync/directory.py +31 -0
- workos/types/directory_sync/directory_group.py +16 -0
- workos/types/directory_sync/directory_state.py +28 -0
- workos/types/directory_sync/directory_type.py +24 -0
- workos/types/directory_sync/directory_user.py +50 -0
- workos/types/directory_sync/list_filters.py +21 -0
- workos/types/events/__init__.py +13 -0
- workos/types/events/authentication_payload.py +70 -0
- workos/types/events/connection_payload_with_legacy_fields.py +5 -0
- workos/types/events/directory_group_membership_payload.py +9 -0
- workos/types/events/directory_group_with_previous_attributes.py +6 -0
- workos/types/events/directory_payload.py +16 -0
- workos/types/events/directory_payload_with_legacy_fields.py +29 -0
- workos/types/events/directory_user_with_previous_attributes.py +6 -0
- workos/types/events/event.py +324 -0
- workos/types/events/event_model.py +103 -0
- workos/types/events/event_type.py +59 -0
- workos/types/events/list_filters.py +10 -0
- workos/types/events/organization_domain_verification_failed_payload.py +14 -0
- workos/types/events/previous_attributes.py +3 -0
- workos/types/events/session_payload.py +27 -0
- workos/types/feature_flags/__init__.py +3 -0
- workos/types/feature_flags/feature_flag.py +12 -0
- workos/types/feature_flags/list_filters.py +5 -0
- workos/types/fga/__init__.py +5 -0
- workos/types/fga/authorization_resource_types.py +9 -0
- workos/types/fga/authorization_resources.py +10 -0
- workos/types/fga/check.py +51 -0
- workos/types/fga/list_filters.py +24 -0
- workos/types/fga/warnings.py +33 -0
- workos/types/fga/warrant.py +49 -0
- workos/types/list_resource.py +198 -0
- workos/types/metadata.py +4 -0
- workos/types/mfa/__init__.py +5 -0
- workos/types/mfa/authentication_challenge.py +14 -0
- workos/types/mfa/authentication_challenge_verification_response.py +9 -0
- workos/types/mfa/authentication_factor.py +70 -0
- workos/types/mfa/authentication_factor_totp_and_challenge_response.py +10 -0
- workos/types/mfa/enroll_authentication_factor_type.py +8 -0
- workos/types/organization_domains/__init__.py +1 -0
- workos/types/organization_domains/organization_domain.py +18 -0
- workos/types/organizations/__init__.py +6 -0
- workos/types/organizations/domain_data_input.py +7 -0
- workos/types/organizations/list_filters.py +6 -0
- workos/types/organizations/organization.py +13 -0
- workos/types/organizations/organization_common.py +12 -0
- workos/types/passwordless/__init__.py +2 -0
- workos/types/passwordless/passwordless_session.py +12 -0
- workos/types/passwordless/passwordless_session_type.py +3 -0
- workos/types/pipes/__init__.py +6 -0
- workos/types/pipes/pipes.py +34 -0
- workos/types/portal/__init__.py +2 -0
- workos/types/portal/portal_link.py +7 -0
- workos/types/portal/portal_link_intent.py +11 -0
- workos/types/portal/portal_link_intent_options.py +9 -0
- workos/types/roles/__init__.py +0 -0
- workos/types/roles/role.py +27 -0
- workos/types/sso/__init__.py +4 -0
- workos/types/sso/connection.py +70 -0
- workos/types/sso/connection_domain.py +8 -0
- workos/types/sso/profile.py +35 -0
- workos/types/sso/sso_provider_type.py +10 -0
- workos/types/user_management/__init__.py +12 -0
- workos/types/user_management/authenticate_with_common.py +66 -0
- workos/types/user_management/authentication_response.py +53 -0
- workos/types/user_management/email_verification.py +18 -0
- workos/types/user_management/impersonator.py +8 -0
- workos/types/user_management/invitation.py +26 -0
- workos/types/user_management/list_filters.py +29 -0
- workos/types/user_management/magic_auth.py +18 -0
- workos/types/user_management/oauth_tokens.py +21 -0
- workos/types/user_management/organization_membership.py +25 -0
- workos/types/user_management/password_hash_type.py +4 -0
- workos/types/user_management/password_reset.py +18 -0
- workos/types/user_management/screen_hint.py +3 -0
- workos/types/user_management/session.py +79 -0
- workos/types/user_management/user.py +22 -0
- workos/types/user_management/user_management_provider_type.py +11 -0
- workos/types/vault/__init__.py +2 -0
- workos/types/vault/key.py +25 -0
- workos/types/vault/object.py +38 -0
- workos/types/webhooks/__init__.py +0 -0
- workos/types/webhooks/webhook.py +330 -0
- workos/types/webhooks/webhook_model.py +14 -0
- workos/types/webhooks/webhook_payload.py +4 -0
- workos/types/widgets/__init__.py +2 -0
- workos/types/widgets/widget_scope.py +4 -0
- workos/types/widgets/widget_token_response.py +7 -0
- workos/types/workos_model.py +26 -0
- workos/typing/__init__.py +1 -0
- workos/typing/literals.py +32 -0
- workos/typing/sync_or_async.py +5 -0
- workos/typing/untyped_literal.py +37 -0
- workos/typing/webhooks.py +18 -0
- workos/user_management.py +2400 -0
- workos/utils/_base_http_client.py +252 -0
- workos/utils/crypto_provider.py +39 -0
- workos/utils/http_client.py +214 -0
- workos/utils/pagination_order.py +4 -0
- workos/utils/request_helper.py +27 -0
- workos/vault.py +544 -0
- workos/webhooks.py +96 -39
- workos/widgets.py +55 -0
- {workos-1.5.1.dist-info → workos-5.38.0.dist-info}/LICENSE +1 -1
- workos-5.38.0.dist-info/METADATA +107 -0
- workos-5.38.0.dist-info/RECORD +141 -0
- {workos-1.5.1.dist-info → workos-5.38.0.dist-info}/WHEEL +1 -1
- workos/audit_trail.py +0 -172
- workos/resources/base.py +0 -36
- workos/resources/event.py +0 -42
- workos/resources/event_action.py +0 -11
- workos/resources/sso.py +0 -53
- workos/utils/connection_types.py +0 -17
- workos/utils/request.py +0 -95
- workos/utils/validation.py +0 -45
- workos-1.5.1.dist-info/METADATA +0 -77
- workos-1.5.1.dist-info/RECORD +0 -25
- /workos/{resources/__init__.py → py.typed} +0 -0
- {workos-1.5.1.dist-info → workos-5.38.0.dist-info}/top_level.txt +0 -0
workos/fga.py
ADDED
|
@@ -0,0 +1,649 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from typing import Any, Mapping, Optional, Protocol, Sequence
|
|
3
|
+
from workos.types.fga import (
|
|
4
|
+
CheckOperation,
|
|
5
|
+
CheckResponse,
|
|
6
|
+
AuthorizationResource,
|
|
7
|
+
AuthorizationResourceType,
|
|
8
|
+
Warrant,
|
|
9
|
+
WarrantCheckInput,
|
|
10
|
+
WarrantWrite,
|
|
11
|
+
WarrantWriteOperation,
|
|
12
|
+
WriteWarrantResponse,
|
|
13
|
+
WarrantQueryResult,
|
|
14
|
+
FGAWarning,
|
|
15
|
+
)
|
|
16
|
+
from workos.types.fga.list_filters import (
|
|
17
|
+
AuthorizationResourceListFilters,
|
|
18
|
+
WarrantListFilters,
|
|
19
|
+
WarrantQueryListFilters,
|
|
20
|
+
)
|
|
21
|
+
from workos.types.list_resource import (
|
|
22
|
+
ListArgs,
|
|
23
|
+
ListMetadata,
|
|
24
|
+
ListPage,
|
|
25
|
+
WorkOSListResource,
|
|
26
|
+
)
|
|
27
|
+
from workos.utils.http_client import SyncHTTPClient
|
|
28
|
+
from workos.utils.pagination_order import PaginationOrder
|
|
29
|
+
from workos.utils.request_helper import (
|
|
30
|
+
REQUEST_METHOD_DELETE,
|
|
31
|
+
REQUEST_METHOD_GET,
|
|
32
|
+
REQUEST_METHOD_POST,
|
|
33
|
+
REQUEST_METHOD_PUT,
|
|
34
|
+
RequestHelper,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
DEFAULT_RESPONSE_LIMIT = 10
|
|
38
|
+
|
|
39
|
+
AuthorizationResourceListResource = WorkOSListResource[
|
|
40
|
+
AuthorizationResource, AuthorizationResourceListFilters, ListMetadata
|
|
41
|
+
]
|
|
42
|
+
|
|
43
|
+
AuthorizationResourceTypeListResource = WorkOSListResource[
|
|
44
|
+
AuthorizationResourceType, ListArgs, ListMetadata
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
WarrantListResource = WorkOSListResource[Warrant, WarrantListFilters, ListMetadata]
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class WarrantQueryListResource(
|
|
51
|
+
WorkOSListResource[WarrantQueryResult, WarrantQueryListFilters, ListMetadata]
|
|
52
|
+
):
|
|
53
|
+
warnings: Optional[Sequence[FGAWarning]] = None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class FGAModule(Protocol):
|
|
57
|
+
def get_resource(
|
|
58
|
+
self, *, resource_type: str, resource_id: str
|
|
59
|
+
) -> AuthorizationResource:
|
|
60
|
+
"""
|
|
61
|
+
Get a warrant resource by its type and ID.
|
|
62
|
+
|
|
63
|
+
Kwargs:
|
|
64
|
+
resource_type (str): The type of the resource.
|
|
65
|
+
resource_id (str): A unique identifier for the resource.
|
|
66
|
+
Returns:
|
|
67
|
+
Resource: A resource object.
|
|
68
|
+
"""
|
|
69
|
+
...
|
|
70
|
+
|
|
71
|
+
def list_resources(
|
|
72
|
+
self,
|
|
73
|
+
*,
|
|
74
|
+
resource_type: Optional[str] = None,
|
|
75
|
+
search: Optional[str] = None,
|
|
76
|
+
limit: int = DEFAULT_RESPONSE_LIMIT,
|
|
77
|
+
order: PaginationOrder = "desc",
|
|
78
|
+
before: Optional[str] = None,
|
|
79
|
+
after: Optional[str] = None,
|
|
80
|
+
) -> AuthorizationResourceListResource:
|
|
81
|
+
"""
|
|
82
|
+
Gets a list of FGA resources.
|
|
83
|
+
|
|
84
|
+
Kwargs:
|
|
85
|
+
resource_type (str): The type of the resource. (Optional)
|
|
86
|
+
search (str): Searchable text for a Resource. (Optional)
|
|
87
|
+
limit (int): The maximum number of resources to return. (Optional)
|
|
88
|
+
order (Literal["asc","desc"]): Sort warrant resources in either ascending or descending (default) order. (Optional)
|
|
89
|
+
before (str): A cursor to return resources before. (Optional)
|
|
90
|
+
after (str): A cursor to return resources after. (Optional)
|
|
91
|
+
Returns:
|
|
92
|
+
AuthorizationResourceListResource: A list of resources with built-in pagination iterator.
|
|
93
|
+
"""
|
|
94
|
+
...
|
|
95
|
+
|
|
96
|
+
def create_resource(
|
|
97
|
+
self,
|
|
98
|
+
*,
|
|
99
|
+
resource_type: str,
|
|
100
|
+
resource_id: str,
|
|
101
|
+
meta: Optional[Mapping[str, Any]] = None,
|
|
102
|
+
) -> AuthorizationResource:
|
|
103
|
+
"""
|
|
104
|
+
Create a new warrant resource.
|
|
105
|
+
|
|
106
|
+
Kwargs:
|
|
107
|
+
resource_type (str): The type of the resource.
|
|
108
|
+
resource_id (str): A unique identifier for the resource.
|
|
109
|
+
meta (Mapping): A dictionary containing additional information about this resource. (Optional)
|
|
110
|
+
Returns:
|
|
111
|
+
AuthorizationResource: A resource object.
|
|
112
|
+
"""
|
|
113
|
+
...
|
|
114
|
+
|
|
115
|
+
def update_resource(
|
|
116
|
+
self,
|
|
117
|
+
*,
|
|
118
|
+
resource_type: str,
|
|
119
|
+
resource_id: str,
|
|
120
|
+
meta: Optional[Mapping[str, Any]] = None,
|
|
121
|
+
) -> AuthorizationResource:
|
|
122
|
+
"""
|
|
123
|
+
Updates an existing warrant resource.
|
|
124
|
+
|
|
125
|
+
Kwargs:
|
|
126
|
+
resource_type (str): The type of the resource.
|
|
127
|
+
resource_id (str): A unique identifier for the resource.
|
|
128
|
+
meta (Mapping): A dictionary containing additional information about this resource. (Optional)
|
|
129
|
+
Returns:
|
|
130
|
+
AuthorizationResource: A resource object.
|
|
131
|
+
"""
|
|
132
|
+
...
|
|
133
|
+
|
|
134
|
+
def delete_resource(self, *, resource_type: str, resource_id: str) -> None:
|
|
135
|
+
"""
|
|
136
|
+
Deletes a resource by its type and ID.
|
|
137
|
+
|
|
138
|
+
Kwargs:
|
|
139
|
+
resource_type (str): The type of the resource.
|
|
140
|
+
resource_id (str): A unique identifier for the resource.
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
None
|
|
144
|
+
"""
|
|
145
|
+
...
|
|
146
|
+
|
|
147
|
+
def list_resource_types(
|
|
148
|
+
self,
|
|
149
|
+
*,
|
|
150
|
+
limit: int = DEFAULT_RESPONSE_LIMIT,
|
|
151
|
+
order: PaginationOrder = "desc",
|
|
152
|
+
before: Optional[str] = None,
|
|
153
|
+
after: Optional[str] = None,
|
|
154
|
+
) -> AuthorizationResourceTypeListResource:
|
|
155
|
+
"""
|
|
156
|
+
Gets a list of FGA resource types.
|
|
157
|
+
|
|
158
|
+
Kwargs:
|
|
159
|
+
limit (int): The maximum number of resources to return. (Optional)
|
|
160
|
+
order (Literal["asc","desc"]): Sort warrant resource types in either ascending or descending (default) order. (Optional)
|
|
161
|
+
before (str): A cursor to return resources before. (Optional)
|
|
162
|
+
after (str): A cursor to return resources after. (Optional)
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
AuthorizationResourceTypeListResource: A list of resource types with built-in pagination iterator.
|
|
166
|
+
"""
|
|
167
|
+
...
|
|
168
|
+
|
|
169
|
+
def list_warrants(
|
|
170
|
+
self,
|
|
171
|
+
*,
|
|
172
|
+
subject_type: Optional[str] = None,
|
|
173
|
+
subject_id: Optional[str] = None,
|
|
174
|
+
subject_relation: Optional[str] = None,
|
|
175
|
+
relation: Optional[str] = None,
|
|
176
|
+
resource_type: Optional[str] = None,
|
|
177
|
+
resource_id: Optional[str] = None,
|
|
178
|
+
limit: int = DEFAULT_RESPONSE_LIMIT,
|
|
179
|
+
order: PaginationOrder = "desc",
|
|
180
|
+
before: Optional[str] = None,
|
|
181
|
+
after: Optional[str] = None,
|
|
182
|
+
warrant_token: Optional[str] = None,
|
|
183
|
+
) -> WarrantListResource:
|
|
184
|
+
"""
|
|
185
|
+
Gets a list of warrants.
|
|
186
|
+
|
|
187
|
+
Kwargs:
|
|
188
|
+
subject_type (str): The type of the subject. (Optional)
|
|
189
|
+
subject_id (str): The ID of the subject. (Optional)
|
|
190
|
+
subject_relation (str): The relation of the subject. (Optional)
|
|
191
|
+
relation (str): The relation of the warrant. (Optional)
|
|
192
|
+
resource_type (str): The type of the resource. (Optional)
|
|
193
|
+
resource_id (str): The ID of the resource. (Optional)
|
|
194
|
+
limit (int): The maximum number of resources to return. (Optional)
|
|
195
|
+
order (Literal["asc","desc"]): Sort warrants in either ascending or descending (default) order. (Optional)
|
|
196
|
+
before (str): A cursor to return resources before. (Optional)
|
|
197
|
+
after (str): A cursor to return resources after. (Optional)
|
|
198
|
+
warrant_token (str): The warrant token. (Optional)
|
|
199
|
+
|
|
200
|
+
Returns:
|
|
201
|
+
WarrantListResource: A list of warrants with built-in pagination iterator.
|
|
202
|
+
"""
|
|
203
|
+
...
|
|
204
|
+
|
|
205
|
+
def write_warrant(
|
|
206
|
+
self,
|
|
207
|
+
*,
|
|
208
|
+
op: WarrantWriteOperation,
|
|
209
|
+
subject_type: str,
|
|
210
|
+
subject_id: str,
|
|
211
|
+
subject_relation: Optional[str] = None,
|
|
212
|
+
relation: str,
|
|
213
|
+
resource_type: str,
|
|
214
|
+
resource_id: str,
|
|
215
|
+
policy: Optional[str] = None,
|
|
216
|
+
) -> WriteWarrantResponse:
|
|
217
|
+
"""
|
|
218
|
+
Write a warrant.
|
|
219
|
+
|
|
220
|
+
Kwargs:
|
|
221
|
+
op (WarrantWriteOperation): The operation to perform.
|
|
222
|
+
subject_type (str): The type of the subject.
|
|
223
|
+
subject_id (str): The ID of the subject.
|
|
224
|
+
subject_relation (str): The relation of the subject. (Optional)
|
|
225
|
+
relation (str): The relation of the warrant.
|
|
226
|
+
resource_type (str): The type of the resource.
|
|
227
|
+
resource_id (str): The ID of the resource.
|
|
228
|
+
policy (str): The policy to apply. (Optional)
|
|
229
|
+
|
|
230
|
+
Returns:
|
|
231
|
+
WriteWarrantResponse: The warrant token.
|
|
232
|
+
"""
|
|
233
|
+
...
|
|
234
|
+
|
|
235
|
+
def batch_write_warrants(
|
|
236
|
+
self, *, batch: Sequence[WarrantWrite]
|
|
237
|
+
) -> WriteWarrantResponse:
|
|
238
|
+
"""
|
|
239
|
+
Write a batch of warrants.
|
|
240
|
+
|
|
241
|
+
Args:
|
|
242
|
+
batch (Sequence[WarrantWrite]): A list of WarrantWrite objects.
|
|
243
|
+
|
|
244
|
+
Returns:
|
|
245
|
+
WriteWarrantResponse: The warrant token.
|
|
246
|
+
"""
|
|
247
|
+
...
|
|
248
|
+
|
|
249
|
+
def check(
|
|
250
|
+
self,
|
|
251
|
+
*,
|
|
252
|
+
checks: Sequence[WarrantCheckInput],
|
|
253
|
+
op: Optional[CheckOperation] = None,
|
|
254
|
+
debug: bool = False,
|
|
255
|
+
warrant_token: Optional[str] = None,
|
|
256
|
+
) -> CheckResponse:
|
|
257
|
+
"""
|
|
258
|
+
Check a warrant.
|
|
259
|
+
|
|
260
|
+
Kwargs:
|
|
261
|
+
checks (Sequence[WarrantCheck]): A list of WarrantCheck objects.
|
|
262
|
+
op (CheckOperation): The operation to perform. (Optional)
|
|
263
|
+
debug (bool): Whether to return debug information including a decision tree. (Optional)
|
|
264
|
+
warrant_token (str): Optional token to specify desired read consistency. (Optional)
|
|
265
|
+
Returns:
|
|
266
|
+
CheckResponse: A check response.
|
|
267
|
+
"""
|
|
268
|
+
...
|
|
269
|
+
|
|
270
|
+
def check_batch(
|
|
271
|
+
self,
|
|
272
|
+
*,
|
|
273
|
+
checks: Sequence[WarrantCheckInput],
|
|
274
|
+
debug: bool = False,
|
|
275
|
+
warrant_token: Optional[str] = None,
|
|
276
|
+
) -> Sequence[CheckResponse]:
|
|
277
|
+
"""
|
|
278
|
+
Check a batch of warrants.
|
|
279
|
+
|
|
280
|
+
Kwargs:
|
|
281
|
+
checks (Sequence[WarrantCheck]): A list of WarrantCheck objects.
|
|
282
|
+
debug (bool): Whether to return debug information including a decision tree. (Optional)
|
|
283
|
+
warrant_token (str): Optional token to specify desired read consistency. (Optional)
|
|
284
|
+
Returns:
|
|
285
|
+
Sequence[CheckResponse]: A list of check responses
|
|
286
|
+
"""
|
|
287
|
+
...
|
|
288
|
+
|
|
289
|
+
def query(
|
|
290
|
+
self,
|
|
291
|
+
*,
|
|
292
|
+
q: str,
|
|
293
|
+
limit: int = DEFAULT_RESPONSE_LIMIT,
|
|
294
|
+
order: PaginationOrder = "desc",
|
|
295
|
+
before: Optional[str] = None,
|
|
296
|
+
after: Optional[str] = None,
|
|
297
|
+
context: Optional[Mapping[str, Any]] = None,
|
|
298
|
+
warrant_token: Optional[str] = None,
|
|
299
|
+
) -> WarrantQueryListResource:
|
|
300
|
+
"""
|
|
301
|
+
Query for warrants.
|
|
302
|
+
|
|
303
|
+
Kwargs:
|
|
304
|
+
q (str): The query string.
|
|
305
|
+
order (Literal["asc","desc"]): Sort warrant resources in either ascending or descending (default) order. (Optional)
|
|
306
|
+
order (str): The order in which to return resources.
|
|
307
|
+
before (str): A cursor to return resources before. (Optional)
|
|
308
|
+
after (str): A cursor to return resources after. (Optional)
|
|
309
|
+
context (Mapping): A dictionary containing additional context. (Optional)
|
|
310
|
+
warrant_token (str): Optional token to specify desired read consistency. (Optional)
|
|
311
|
+
Returns:
|
|
312
|
+
|
|
313
|
+
QueryListResource: A list of query results with built-in pagination iterator.
|
|
314
|
+
"""
|
|
315
|
+
...
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
class FGA(FGAModule):
|
|
319
|
+
_http_client: SyncHTTPClient
|
|
320
|
+
|
|
321
|
+
def __init__(self, http_client: SyncHTTPClient):
|
|
322
|
+
self._http_client = http_client
|
|
323
|
+
|
|
324
|
+
def get_resource(
|
|
325
|
+
self,
|
|
326
|
+
*,
|
|
327
|
+
resource_type: str,
|
|
328
|
+
resource_id: str,
|
|
329
|
+
) -> AuthorizationResource:
|
|
330
|
+
if not resource_type or not resource_id:
|
|
331
|
+
raise ValueError(
|
|
332
|
+
"Incomplete arguments: 'resource_type' and 'resource_id' are required arguments"
|
|
333
|
+
)
|
|
334
|
+
|
|
335
|
+
response = self._http_client.request(
|
|
336
|
+
RequestHelper.build_parameterized_url(
|
|
337
|
+
"fga/v1/resources/{resource_type}/{resource_id}",
|
|
338
|
+
resource_type=resource_type,
|
|
339
|
+
resource_id=resource_id,
|
|
340
|
+
),
|
|
341
|
+
method=REQUEST_METHOD_GET,
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
return AuthorizationResource.model_validate(response)
|
|
345
|
+
|
|
346
|
+
def list_resources(
|
|
347
|
+
self,
|
|
348
|
+
*,
|
|
349
|
+
resource_type: Optional[str] = None,
|
|
350
|
+
search: Optional[str] = None,
|
|
351
|
+
limit: int = DEFAULT_RESPONSE_LIMIT,
|
|
352
|
+
order: PaginationOrder = "desc",
|
|
353
|
+
before: Optional[str] = None,
|
|
354
|
+
after: Optional[str] = None,
|
|
355
|
+
) -> AuthorizationResourceListResource:
|
|
356
|
+
list_params: AuthorizationResourceListFilters = {
|
|
357
|
+
"resource_type": resource_type,
|
|
358
|
+
"search": search,
|
|
359
|
+
"limit": limit,
|
|
360
|
+
"order": order,
|
|
361
|
+
"before": before,
|
|
362
|
+
"after": after,
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
response = self._http_client.request(
|
|
366
|
+
"fga/v1/resources",
|
|
367
|
+
method=REQUEST_METHOD_GET,
|
|
368
|
+
params=list_params,
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
return AuthorizationResourceListResource(
|
|
372
|
+
list_method=self.list_resources,
|
|
373
|
+
list_args=list_params,
|
|
374
|
+
**ListPage[AuthorizationResource](**response).model_dump(),
|
|
375
|
+
)
|
|
376
|
+
|
|
377
|
+
def create_resource(
|
|
378
|
+
self,
|
|
379
|
+
*,
|
|
380
|
+
resource_type: str,
|
|
381
|
+
resource_id: str,
|
|
382
|
+
meta: Optional[Mapping[str, Any]] = None,
|
|
383
|
+
) -> AuthorizationResource:
|
|
384
|
+
if not resource_type or not resource_id:
|
|
385
|
+
raise ValueError(
|
|
386
|
+
"Incomplete arguments: 'resource_type' and 'resource_id' are required arguments"
|
|
387
|
+
)
|
|
388
|
+
|
|
389
|
+
response = self._http_client.request(
|
|
390
|
+
"fga/v1/resources",
|
|
391
|
+
method=REQUEST_METHOD_POST,
|
|
392
|
+
json={
|
|
393
|
+
"resource_type": resource_type,
|
|
394
|
+
"resource_id": resource_id,
|
|
395
|
+
"meta": meta,
|
|
396
|
+
},
|
|
397
|
+
)
|
|
398
|
+
|
|
399
|
+
return AuthorizationResource.model_validate(response)
|
|
400
|
+
|
|
401
|
+
def update_resource(
|
|
402
|
+
self,
|
|
403
|
+
*,
|
|
404
|
+
resource_type: str,
|
|
405
|
+
resource_id: str,
|
|
406
|
+
meta: Optional[Mapping[str, Any]] = None,
|
|
407
|
+
) -> AuthorizationResource:
|
|
408
|
+
if not resource_type or not resource_id:
|
|
409
|
+
raise ValueError(
|
|
410
|
+
"Incomplete arguments: 'resource_type' and 'resource_id' are required arguments"
|
|
411
|
+
)
|
|
412
|
+
|
|
413
|
+
response = self._http_client.request(
|
|
414
|
+
RequestHelper.build_parameterized_url(
|
|
415
|
+
"fga/v1/resources/{resource_type}/{resource_id}",
|
|
416
|
+
resource_type=resource_type,
|
|
417
|
+
resource_id=resource_id,
|
|
418
|
+
),
|
|
419
|
+
method=REQUEST_METHOD_PUT,
|
|
420
|
+
json={"meta": meta},
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
return AuthorizationResource.model_validate(response)
|
|
424
|
+
|
|
425
|
+
def delete_resource(self, *, resource_type: str, resource_id: str) -> None:
|
|
426
|
+
if not resource_type or not resource_id:
|
|
427
|
+
raise ValueError(
|
|
428
|
+
"Incomplete arguments: 'resource_type' and 'resource_id' are required arguments"
|
|
429
|
+
)
|
|
430
|
+
|
|
431
|
+
self._http_client.request(
|
|
432
|
+
RequestHelper.build_parameterized_url(
|
|
433
|
+
"fga/v1/resources/{resource_type}/{resource_id}",
|
|
434
|
+
resource_type=resource_type,
|
|
435
|
+
resource_id=resource_id,
|
|
436
|
+
),
|
|
437
|
+
method=REQUEST_METHOD_DELETE,
|
|
438
|
+
)
|
|
439
|
+
|
|
440
|
+
def list_resource_types(
|
|
441
|
+
self,
|
|
442
|
+
*,
|
|
443
|
+
limit: int = DEFAULT_RESPONSE_LIMIT,
|
|
444
|
+
order: PaginationOrder = "desc",
|
|
445
|
+
before: Optional[str] = None,
|
|
446
|
+
after: Optional[str] = None,
|
|
447
|
+
) -> AuthorizationResourceTypeListResource:
|
|
448
|
+
list_params: ListArgs = {
|
|
449
|
+
"limit": limit,
|
|
450
|
+
"order": order,
|
|
451
|
+
"before": before,
|
|
452
|
+
"after": after,
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
response = self._http_client.request(
|
|
456
|
+
"fga/v1/resource-types",
|
|
457
|
+
method=REQUEST_METHOD_GET,
|
|
458
|
+
params=list_params,
|
|
459
|
+
)
|
|
460
|
+
|
|
461
|
+
return AuthorizationResourceTypeListResource(
|
|
462
|
+
list_method=self.list_resource_types,
|
|
463
|
+
list_args=list_params,
|
|
464
|
+
**ListPage[AuthorizationResourceType](**response).model_dump(),
|
|
465
|
+
)
|
|
466
|
+
|
|
467
|
+
def list_warrants(
|
|
468
|
+
self,
|
|
469
|
+
*,
|
|
470
|
+
subject_type: Optional[str] = None,
|
|
471
|
+
subject_id: Optional[str] = None,
|
|
472
|
+
subject_relation: Optional[str] = None,
|
|
473
|
+
relation: Optional[str] = None,
|
|
474
|
+
resource_type: Optional[str] = None,
|
|
475
|
+
resource_id: Optional[str] = None,
|
|
476
|
+
limit: int = DEFAULT_RESPONSE_LIMIT,
|
|
477
|
+
order: PaginationOrder = "desc",
|
|
478
|
+
before: Optional[str] = None,
|
|
479
|
+
after: Optional[str] = None,
|
|
480
|
+
warrant_token: Optional[str] = None,
|
|
481
|
+
) -> WarrantListResource:
|
|
482
|
+
list_params: WarrantListFilters = {
|
|
483
|
+
"resource_type": resource_type,
|
|
484
|
+
"resource_id": resource_id,
|
|
485
|
+
"relation": relation,
|
|
486
|
+
"subject_type": subject_type,
|
|
487
|
+
"subject_id": subject_id,
|
|
488
|
+
"subject_relation": subject_relation,
|
|
489
|
+
"limit": limit,
|
|
490
|
+
"order": order,
|
|
491
|
+
"before": before,
|
|
492
|
+
"after": after,
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
response = self._http_client.request(
|
|
496
|
+
"fga/v1/warrants",
|
|
497
|
+
method=REQUEST_METHOD_GET,
|
|
498
|
+
params=list_params,
|
|
499
|
+
headers={"Warrant-Token": warrant_token} if warrant_token else None,
|
|
500
|
+
)
|
|
501
|
+
|
|
502
|
+
# A workaround to add warrant_token to the list_args for the ListResource iterator
|
|
503
|
+
list_params["warrant_token"] = warrant_token
|
|
504
|
+
|
|
505
|
+
return WarrantListResource(
|
|
506
|
+
list_method=self.list_warrants,
|
|
507
|
+
list_args=list_params,
|
|
508
|
+
**ListPage[Warrant](**response).model_dump(),
|
|
509
|
+
)
|
|
510
|
+
|
|
511
|
+
def write_warrant(
|
|
512
|
+
self,
|
|
513
|
+
*,
|
|
514
|
+
op: WarrantWriteOperation,
|
|
515
|
+
subject_type: str,
|
|
516
|
+
subject_id: str,
|
|
517
|
+
subject_relation: Optional[str] = None,
|
|
518
|
+
relation: str,
|
|
519
|
+
resource_type: str,
|
|
520
|
+
resource_id: str,
|
|
521
|
+
policy: Optional[str] = None,
|
|
522
|
+
) -> WriteWarrantResponse:
|
|
523
|
+
params = {
|
|
524
|
+
"op": op,
|
|
525
|
+
"resource_type": resource_type,
|
|
526
|
+
"resource_id": resource_id,
|
|
527
|
+
"relation": relation,
|
|
528
|
+
"subject": {
|
|
529
|
+
"resource_type": subject_type,
|
|
530
|
+
"resource_id": subject_id,
|
|
531
|
+
"relation": subject_relation,
|
|
532
|
+
},
|
|
533
|
+
"policy": policy,
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
response = self._http_client.request(
|
|
537
|
+
"fga/v1/warrants",
|
|
538
|
+
method=REQUEST_METHOD_POST,
|
|
539
|
+
json=params,
|
|
540
|
+
)
|
|
541
|
+
|
|
542
|
+
return WriteWarrantResponse.model_validate(response)
|
|
543
|
+
|
|
544
|
+
def batch_write_warrants(
|
|
545
|
+
self, *, batch: Sequence[WarrantWrite]
|
|
546
|
+
) -> WriteWarrantResponse:
|
|
547
|
+
if not batch:
|
|
548
|
+
raise ValueError("Incomplete arguments: No batch warrant writes provided")
|
|
549
|
+
|
|
550
|
+
response = self._http_client.request(
|
|
551
|
+
"fga/v1/warrants",
|
|
552
|
+
method=REQUEST_METHOD_POST,
|
|
553
|
+
json=batch,
|
|
554
|
+
)
|
|
555
|
+
|
|
556
|
+
return WriteWarrantResponse.model_validate(response)
|
|
557
|
+
|
|
558
|
+
def check(
|
|
559
|
+
self,
|
|
560
|
+
*,
|
|
561
|
+
checks: Sequence[WarrantCheckInput],
|
|
562
|
+
op: Optional[CheckOperation] = None,
|
|
563
|
+
debug: bool = False,
|
|
564
|
+
warrant_token: Optional[str] = None,
|
|
565
|
+
) -> CheckResponse:
|
|
566
|
+
if not checks:
|
|
567
|
+
raise ValueError("Incomplete arguments: No checks provided")
|
|
568
|
+
|
|
569
|
+
body = {
|
|
570
|
+
"checks": checks,
|
|
571
|
+
"op": op,
|
|
572
|
+
"debug": debug,
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
response = self._http_client.request(
|
|
576
|
+
"fga/v1/check",
|
|
577
|
+
method=REQUEST_METHOD_POST,
|
|
578
|
+
json=body,
|
|
579
|
+
headers={"Warrant-Token": warrant_token} if warrant_token else None,
|
|
580
|
+
)
|
|
581
|
+
|
|
582
|
+
return CheckResponse.model_validate(response)
|
|
583
|
+
|
|
584
|
+
def check_batch(
|
|
585
|
+
self,
|
|
586
|
+
*,
|
|
587
|
+
checks: Sequence[WarrantCheckInput],
|
|
588
|
+
debug: bool = False,
|
|
589
|
+
warrant_token: Optional[str] = None,
|
|
590
|
+
) -> Sequence[CheckResponse]:
|
|
591
|
+
if not checks:
|
|
592
|
+
raise ValueError("Incomplete arguments: No checks provided")
|
|
593
|
+
|
|
594
|
+
body = {
|
|
595
|
+
"checks": checks,
|
|
596
|
+
"op": "batch",
|
|
597
|
+
"debug": debug,
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
response = self._http_client.request(
|
|
601
|
+
"fga/v1/check",
|
|
602
|
+
method=REQUEST_METHOD_POST,
|
|
603
|
+
json=body,
|
|
604
|
+
headers={"Warrant-Token": warrant_token} if warrant_token else None,
|
|
605
|
+
)
|
|
606
|
+
|
|
607
|
+
return [CheckResponse.model_validate(check) for check in response]
|
|
608
|
+
|
|
609
|
+
def query(
|
|
610
|
+
self,
|
|
611
|
+
*,
|
|
612
|
+
q: str,
|
|
613
|
+
limit: int = DEFAULT_RESPONSE_LIMIT,
|
|
614
|
+
order: PaginationOrder = "desc",
|
|
615
|
+
before: Optional[str] = None,
|
|
616
|
+
after: Optional[str] = None,
|
|
617
|
+
context: Optional[Mapping[str, Any]] = None,
|
|
618
|
+
warrant_token: Optional[str] = None,
|
|
619
|
+
) -> WarrantQueryListResource:
|
|
620
|
+
list_params: WarrantQueryListFilters = {
|
|
621
|
+
"q": q,
|
|
622
|
+
"limit": limit,
|
|
623
|
+
"order": order,
|
|
624
|
+
"before": before,
|
|
625
|
+
"after": after,
|
|
626
|
+
"context": context,
|
|
627
|
+
}
|
|
628
|
+
parsed_list_params = {
|
|
629
|
+
key: json.dumps(value) if key == "context" and value is not None else value
|
|
630
|
+
for key, value in list_params.items()
|
|
631
|
+
if value is not None
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
response = self._http_client.request(
|
|
635
|
+
"fga/v1/query",
|
|
636
|
+
method=REQUEST_METHOD_GET,
|
|
637
|
+
params=parsed_list_params,
|
|
638
|
+
headers={"Warrant-Token": warrant_token} if warrant_token else None,
|
|
639
|
+
)
|
|
640
|
+
|
|
641
|
+
# A workaround to add warrant_token to the list_args for the ListResource iterator
|
|
642
|
+
list_params["warrant_token"] = warrant_token
|
|
643
|
+
|
|
644
|
+
return WarrantQueryListResource(
|
|
645
|
+
list_method=self.query,
|
|
646
|
+
list_args=list_params,
|
|
647
|
+
warnings=response.get("warnings"),
|
|
648
|
+
**ListPage[WarrantQueryResult](**response).model_dump(),
|
|
649
|
+
)
|