scim2-client 0.1.2__tar.gz → 0.1.3__tar.gz
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.
- {scim2_client-0.1.2 → scim2_client-0.1.3}/PKG-INFO +2 -2
- {scim2_client-0.1.2 → scim2_client-0.1.3}/pyproject.toml +2 -2
- {scim2_client-0.1.2 → scim2_client-0.1.3}/scim2_client/client.py +36 -7
- {scim2_client-0.1.2 → scim2_client-0.1.3}/README.md +0 -0
- {scim2_client-0.1.2 → scim2_client-0.1.3}/scim2_client/__init__.py +0 -0
- {scim2_client-0.1.2 → scim2_client-0.1.3}/scim2_client/errors.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: scim2-client
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Summary: Pythonically build SCIM requests and parse SCIM responses
|
|
5
5
|
License: MIT
|
|
6
6
|
Keywords: scim,scim2,provisioning,httpx,api
|
|
@@ -20,7 +20,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.12
|
|
21
21
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
22
22
|
Requires-Dist: httpx (>=0.27.0,<0.28.0)
|
|
23
|
-
Requires-Dist: scim2-models (>=0.1.
|
|
23
|
+
Requires-Dist: scim2-models (>=0.1.2,<0.2.0)
|
|
24
24
|
Description-Content-Type: text/markdown
|
|
25
25
|
|
|
26
26
|
# scim2-client
|
|
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
|
|
|
4
4
|
|
|
5
5
|
[tool.poetry]
|
|
6
6
|
name = "scim2-client"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.3"
|
|
8
8
|
description = "Pythonically build SCIM requests and parse SCIM responses"
|
|
9
9
|
authors = ["Yaal Coop <contact@yaal.coop>"]
|
|
10
10
|
license = "MIT"
|
|
@@ -27,7 +27,7 @@ classifiers = [
|
|
|
27
27
|
[tool.poetry.dependencies]
|
|
28
28
|
python = "^3.9"
|
|
29
29
|
httpx = "^0.27.0"
|
|
30
|
-
scim2-models = "^0.1.
|
|
30
|
+
scim2-models = "^0.1.2"
|
|
31
31
|
|
|
32
32
|
[tool.poetry.group.doc]
|
|
33
33
|
optional = true
|
|
@@ -15,8 +15,10 @@ from scim2_models import Context
|
|
|
15
15
|
from scim2_models import Error
|
|
16
16
|
from scim2_models import ListResponse
|
|
17
17
|
from scim2_models import PatchOp
|
|
18
|
+
from scim2_models import Resource
|
|
18
19
|
from scim2_models import SearchRequest
|
|
19
20
|
|
|
21
|
+
from .errors import SCIMClientError
|
|
20
22
|
from .errors import UnexpectedContentFormat
|
|
21
23
|
from .errors import UnexpectedContentType
|
|
22
24
|
from .errors import UnexpectedStatusCode
|
|
@@ -166,6 +168,7 @@ class SCIMClient:
|
|
|
166
168
|
<7644#section-3.3>`.
|
|
167
169
|
|
|
168
170
|
:param resource: The resource to create
|
|
171
|
+
If is a :data:`dict`, the resource type will be guessed from the schema.
|
|
169
172
|
:param check_request_payload: If :data:`False`,
|
|
170
173
|
:code:`resource` is expected to be a dict that will be passed as-is in the request.
|
|
171
174
|
:param check_response_payload: Whether to validate that the response payload is valid.
|
|
@@ -184,8 +187,20 @@ class SCIMClient:
|
|
|
184
187
|
url = kwargs.pop("url", None)
|
|
185
188
|
|
|
186
189
|
else:
|
|
187
|
-
|
|
188
|
-
|
|
190
|
+
if isinstance(resource, Resource):
|
|
191
|
+
resource_type = resource.__class__
|
|
192
|
+
|
|
193
|
+
else:
|
|
194
|
+
resource_type = Resource.get_by_payload(self.resource_types, resource)
|
|
195
|
+
if not resource_type:
|
|
196
|
+
raise SCIMClientError(
|
|
197
|
+
None, "Cannot guess resource type from the payload"
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
resource = resource_type.model_validate(resource)
|
|
201
|
+
|
|
202
|
+
self.check_resource_type(resource_type)
|
|
203
|
+
url = kwargs.pop("url", self.resource_endpoint(resource_type))
|
|
189
204
|
payload = resource.model_dump(scim_ctx=Context.RESOURCE_CREATION_REQUEST)
|
|
190
205
|
|
|
191
206
|
response = self.client.post(url, json=payload, **kwargs)
|
|
@@ -352,7 +367,7 @@ class SCIMClient:
|
|
|
352
367
|
else None
|
|
353
368
|
)
|
|
354
369
|
|
|
355
|
-
response = self.client.post("/.search",
|
|
370
|
+
response = self.client.post("/.search", json=payload)
|
|
356
371
|
|
|
357
372
|
return self.check_response(
|
|
358
373
|
response,
|
|
@@ -397,7 +412,8 @@ class SCIMClient:
|
|
|
397
412
|
"""Perform a PUT request to replace a resource, as defined in
|
|
398
413
|
:rfc:`RFC7644 §3.5.1 <7644#section-3.5.1>`.
|
|
399
414
|
|
|
400
|
-
:param resource: The new
|
|
415
|
+
:param resource: The new resource to replace.
|
|
416
|
+
If is a :data:`dict`, the resource type will be guessed from the schema.
|
|
401
417
|
:param check_request_payload: If :data:`False`,
|
|
402
418
|
:code:`resource` is expected to be a dict that will be passed as-is in the request.
|
|
403
419
|
:param check_response_payload: Whether to validate that the response payload is valid.
|
|
@@ -413,12 +429,25 @@ class SCIMClient:
|
|
|
413
429
|
|
|
414
430
|
if not check_request_payload:
|
|
415
431
|
payload = resource
|
|
416
|
-
url = kwargs.pop("url")
|
|
432
|
+
url = kwargs.pop("url", None)
|
|
417
433
|
|
|
418
434
|
else:
|
|
419
|
-
|
|
435
|
+
if isinstance(resource, Resource):
|
|
436
|
+
resource_type = resource.__class__
|
|
437
|
+
|
|
438
|
+
else:
|
|
439
|
+
resource_type = Resource.get_by_payload(self.resource_types, resource)
|
|
440
|
+
if not resource_type:
|
|
441
|
+
raise SCIMClientError(
|
|
442
|
+
None, "Cannot guess resource type from the payload"
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
resource = resource_type.model_validate(resource)
|
|
446
|
+
|
|
447
|
+
self.check_resource_type(resource_type)
|
|
448
|
+
|
|
420
449
|
if not resource.id:
|
|
421
|
-
raise
|
|
450
|
+
raise SCIMClientError(None, "Resource must have an id")
|
|
422
451
|
|
|
423
452
|
payload = resource.model_dump(scim_ctx=Context.RESOURCE_REPLACEMENT_REQUEST)
|
|
424
453
|
url = kwargs.pop(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|