scim2-client 0.1.2__py3-none-any.whl → 0.1.3__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.
scim2_client/client.py CHANGED
@@ -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
- self.check_resource_type(resource.__class__)
188
- url = kwargs.pop("url", self.resource_endpoint(resource.__class__))
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", params=payload)
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 state of the resource to replace.
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
- self.check_resource_type(resource.__class__)
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 Exception("Resource must have an id")
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(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: scim2-client
3
- Version: 0.1.2
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.1,<0.2.0)
23
+ Requires-Dist: scim2-models (>=0.1.2,<0.2.0)
24
24
  Description-Content-Type: text/markdown
25
25
 
26
26
  # scim2-client
@@ -0,0 +1,6 @@
1
+ scim2_client/__init__.py,sha256=2UNsl6HNtVUv5LVcnmLaCHyT4SqAUUFOIWW2r5XGv6A,338
2
+ scim2_client/client.py,sha256=1l7vb_OUPNzs-LP_yCmPEBafx3iwo1kgUNmWiucUDMc,17669
3
+ scim2_client/errors.py,sha256=uOOAwsD8rDrC8BQbwPid051YyWtexTcS8b7i6QC6-CM,1175
4
+ scim2_client-0.1.3.dist-info/METADATA,sha256=JxLH05nejwpIVxPOWwdsnujJed-D3ZwFPHwP9an-qc4,2654
5
+ scim2_client-0.1.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
6
+ scim2_client-0.1.3.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- scim2_client/__init__.py,sha256=2UNsl6HNtVUv5LVcnmLaCHyT4SqAUUFOIWW2r5XGv6A,338
2
- scim2_client/client.py,sha256=_ZjMd6_Kh5SYEcstm5OkMIu0z-N93R4SWdG0lGd4u7s,16538
3
- scim2_client/errors.py,sha256=uOOAwsD8rDrC8BQbwPid051YyWtexTcS8b7i6QC6-CM,1175
4
- scim2_client-0.1.2.dist-info/METADATA,sha256=4h7QD3jpYRhSQCBmLX9AFhHJ9R68_ObP45V9_kV51LI,2654
5
- scim2_client-0.1.2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
6
- scim2_client-0.1.2.dist-info/RECORD,,