scim2-client 0.1.5__tar.gz → 0.1.6__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: scim2-client
3
- Version: 0.1.5
3
+ Version: 0.1.6
4
4
  Summary: Pythonically build SCIM requests and parse SCIM responses
5
5
  License: MIT
6
6
  Keywords: scim,scim2,provisioning,httpx,api
@@ -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.5"
7
+ version = "0.1.6"
8
8
  description = "Pythonically build SCIM requests and parse SCIM responses"
9
9
  authors = ["Yaal Coop <contact@yaal.coop>"]
10
10
  license = "MIT"
@@ -5,6 +5,7 @@ from .errors import ResponsePayloadValidationError
5
5
  from .errors import SCIMClientError
6
6
  from .errors import SCIMRequestError
7
7
  from .errors import SCIMResponseError
8
+ from .errors import SCIMResponseErrorObject
8
9
  from .errors import UnexpectedContentFormat
9
10
  from .errors import UnexpectedContentType
10
11
  from .errors import UnexpectedStatusCode
@@ -14,6 +15,7 @@ __all__ = [
14
15
  "SCIMClientError",
15
16
  "SCIMRequestError",
16
17
  "SCIMResponseError",
18
+ "SCIMResponseErrorObject",
17
19
  "UnexpectedContentFormat",
18
20
  "UnexpectedContentType",
19
21
  "UnexpectedStatusCode",
@@ -28,6 +28,7 @@ from .errors import ResponsePayloadValidationError
28
28
  from .errors import SCIMClientError
29
29
  from .errors import SCIMRequestError
30
30
  from .errors import SCIMResponseError
31
+ from .errors import SCIMResponseErrorObject
31
32
  from .errors import UnexpectedContentFormat
32
33
  from .errors import UnexpectedContentType
33
34
  from .errors import UnexpectedStatusCode
@@ -146,6 +147,7 @@ class SCIMClient:
146
147
  expected_status_codes: List[int],
147
148
  expected_types: Optional[Type] = None,
148
149
  check_response_payload: bool = True,
150
+ raise_scim_errors: bool = False,
149
151
  scim_ctx: Optional[Context] = None,
150
152
  ):
151
153
  if expected_status_codes and response.status_code not in expected_status_codes:
@@ -179,7 +181,10 @@ class SCIMClient:
179
181
  return response_payload
180
182
 
181
183
  try:
182
- return Error.model_validate(response_payload)
184
+ error = Error.model_validate(response_payload)
185
+ if raise_scim_errors:
186
+ raise SCIMResponseErrorObject(source=error)
187
+ return error
183
188
  except ValidationError:
184
189
  pass
185
190
 
@@ -216,6 +221,7 @@ class SCIMClient:
216
221
  check_request_payload: bool = True,
217
222
  check_response_payload: bool = True,
218
223
  check_status_code: bool = True,
224
+ raise_scim_errors: bool = False,
219
225
  **kwargs,
220
226
  ) -> Union[AnyResource, Error, Dict]:
221
227
  """Perform a POST request to create, as defined in :rfc:`RFC7644 §3.3
@@ -228,6 +234,9 @@ class SCIMClient:
228
234
  :param check_response_payload: Whether to validate that the response payload is valid.
229
235
  If set, the raw payload will be returned.
230
236
  :param check_status_code: Whether to validate that the response status code is valid.
237
+ :param raise_scim_errors: If :data:`True` and the server returned an
238
+ :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
239
+ exception will be raised. If :data:`False` the error object is returned.
231
240
  :param kwargs: Additional parameters passed to the underlying HTTP request
232
241
  library.
233
242
 
@@ -295,6 +304,7 @@ class SCIMClient:
295
304
  ),
296
305
  expected_types=([resource.__class__] if check_request_payload else None),
297
306
  check_response_payload=check_response_payload,
307
+ raise_scim_errors=raise_scim_errors,
298
308
  scim_ctx=Context.RESOURCE_CREATION_RESPONSE,
299
309
  )
300
310
 
@@ -306,6 +316,7 @@ class SCIMClient:
306
316
  check_request_payload: bool = True,
307
317
  check_response_payload: bool = True,
308
318
  check_status_code: bool = True,
319
+ raise_scim_errors: bool = False,
309
320
  **kwargs,
310
321
  ) -> Union[AnyResource, ListResponse[AnyResource], Error, Dict]:
311
322
  """Perform a GET request to read resources, as defined in :rfc:`RFC7644
@@ -322,6 +333,9 @@ class SCIMClient:
322
333
  :param check_response_payload: Whether to validate that the response payload is valid.
323
334
  If set, the raw payload will be returned.
324
335
  :param check_status_code: Whether to validate that the response status code is valid.
336
+ :param raise_scim_errors: If :data:`True` and the server returned an
337
+ :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
338
+ exception will be raised. If :data:`False` the error object is returned.
325
339
  :param kwargs: Additional parameters passed to the underlying HTTP request library.
326
340
 
327
341
  :return:
@@ -420,6 +434,7 @@ class SCIMClient:
420
434
  ),
421
435
  expected_types=expected_types,
422
436
  check_response_payload=check_response_payload,
437
+ raise_scim_errors=raise_scim_errors,
423
438
  scim_ctx=Context.RESOURCE_QUERY_RESPONSE,
424
439
  )
425
440
 
@@ -429,6 +444,7 @@ class SCIMClient:
429
444
  check_request_payload: bool = True,
430
445
  check_response_payload: bool = True,
431
446
  check_status_code: bool = True,
447
+ raise_scim_errors: bool = False,
432
448
  **kwargs,
433
449
  ) -> Union[AnyResource, ListResponse[AnyResource], Error, Dict]:
434
450
  """Perform a POST search request to read all available resources, as
@@ -442,6 +458,9 @@ class SCIMClient:
442
458
  :param check_response_payload: Whether to validate that the response payload is valid.
443
459
  If set, the raw payload will be returned.
444
460
  :param check_status_code: Whether to validate that the response status code is valid.
461
+ :param raise_scim_errors: If :data:`True` and the server returned an
462
+ :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
463
+ exception will be raised. If :data:`False` the error object is returned.
445
464
  :param kwargs: Additional parameters passed to the underlying
446
465
  HTTP request library.
447
466
 
@@ -497,6 +516,7 @@ class SCIMClient:
497
516
  ),
498
517
  expected_types=[ListResponse[Union[self.resource_types]]],
499
518
  check_response_payload=check_response_payload,
519
+ raise_scim_errors=raise_scim_errors,
500
520
  scim_ctx=Context.RESOURCE_QUERY_RESPONSE,
501
521
  )
502
522
 
@@ -506,6 +526,7 @@ class SCIMClient:
506
526
  id: str,
507
527
  check_response_payload: bool = True,
508
528
  check_status_code: bool = True,
529
+ raise_scim_errors: bool = False,
509
530
  **kwargs,
510
531
  ) -> Optional[Union[Error, Dict]]:
511
532
  """Perform a DELETE request to create, as defined in :rfc:`RFC7644 §3.6
@@ -516,6 +537,9 @@ class SCIMClient:
516
537
  :param check_response_payload: Whether to validate that the response payload is valid.
517
538
  If set, the raw payload will be returned.
518
539
  :param check_status_code: Whether to validate that the response status code is valid.
540
+ :param raise_scim_errors: If :data:`True` and the server returned an
541
+ :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
542
+ exception will be raised. If :data:`False` the error object is returned.
519
543
  :param kwargs: Additional parameters passed to the underlying
520
544
  HTTP request library.
521
545
 
@@ -552,6 +576,7 @@ class SCIMClient:
552
576
  self.DELETION_RESPONSE_STATUS_CODES if check_status_code else None
553
577
  ),
554
578
  check_response_payload=check_response_payload,
579
+ raise_scim_errors=raise_scim_errors,
555
580
  )
556
581
 
557
582
  def replace(
@@ -560,6 +585,7 @@ class SCIMClient:
560
585
  check_request_payload: bool = True,
561
586
  check_response_payload: bool = True,
562
587
  check_status_code: bool = True,
588
+ raise_scim_errors: bool = False,
563
589
  **kwargs,
564
590
  ) -> Union[AnyResource, Error, Dict]:
565
591
  """Perform a PUT request to replace a resource, as defined in
@@ -572,6 +598,9 @@ class SCIMClient:
572
598
  :param check_response_payload: Whether to validate that the response payload is valid.
573
599
  If set, the raw payload will be returned.
574
600
  :param check_status_code: Whether to validate that the response status code is valid.
601
+ :param raise_scim_errors: If :data:`True` and the server returned an
602
+ :class:`~scim2_models.Error` object, a :class:`~scim2_client.SCIMResponseErrorObject`
603
+ exception will be raised. If :data:`False` the error object is returned.
575
604
  :param kwargs: Additional parameters passed to the underlying
576
605
  HTTP request library.
577
606
 
@@ -648,6 +677,7 @@ class SCIMClient:
648
677
  ),
649
678
  expected_types=([resource.__class__] if check_request_payload else None),
650
679
  check_response_payload=check_response_payload,
680
+ raise_scim_errors=raise_scim_errors,
651
681
  scim_ctx=Context.RESOURCE_REPLACEMENT_RESPONSE,
652
682
  )
653
683
 
@@ -60,6 +60,20 @@ class SCIMResponseError(SCIMClientError):
60
60
  validation."""
61
61
 
62
62
 
63
+ class SCIMResponseErrorObject(SCIMResponseError):
64
+ """The server response returned a :class:`scim2_models.Error` object.
65
+
66
+ Those errors are only raised when the :code:`raise_scim_errors` parameter is :data:`True`.
67
+ """
68
+
69
+ def __init__(self, *args, **kwargs):
70
+ message = kwargs.pop(
71
+ "message",
72
+ f"The server returned a SCIM Error object: {kwargs['source'].detail}",
73
+ )
74
+ super().__init__(message, *args, **kwargs)
75
+
76
+
63
77
  class UnexpectedStatusCode(SCIMResponseError):
64
78
  """Error raised when a server returned an unexpected status code for a
65
79
  given :class:`~scim2_models.Context`."""
File without changes