scim2-client 0.4.1__py3-none-any.whl → 0.4.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
@@ -60,6 +60,8 @@ class SCIMClient:
60
60
  This value can be overwritten in methods.
61
61
  :param check_response_payload: Whether to validate that the response payloads are valid.
62
62
  If set, the raw payload will be returned. This value can be overwritten in methods.
63
+ :param check_response_content_type: Whether to validate that the response content types are valid.
64
+ :param check_response_status_codes: Whether to validate that the response status codes are valid.
63
65
  :param raise_scim_errors: If :data:`True` and the server returned an
64
66
  :class:`~scim2_models.Error` object during a request, a :class:`~scim2_client.SCIMResponseErrorObject`
65
67
  exception will be raised. If :data:`False` the error object is returned. This value can be overwritten in methods.
@@ -156,6 +158,8 @@ class SCIMClient:
156
158
  service_provider_config: Optional[ServiceProviderConfig] = None,
157
159
  check_request_payload: bool = True,
158
160
  check_response_payload: bool = True,
161
+ check_response_content_type: bool = True,
162
+ check_response_status_codes: bool = True,
159
163
  raise_scim_errors: bool = True,
160
164
  ):
161
165
  self.resource_models = tuple(resource_models or [])
@@ -163,6 +167,8 @@ class SCIMClient:
163
167
  self.service_provider_config = service_provider_config
164
168
  self.check_request_payload = check_request_payload
165
169
  self.check_response_payload = check_response_payload
170
+ self.check_response_content_type = check_response_content_type
171
+ self.check_response_status_codes = check_response_status_codes
166
172
  self.raise_scim_errors = raise_scim_errors
167
173
 
168
174
  def get_resource_model(self, name: str) -> Optional[type[Resource]]:
@@ -220,6 +226,31 @@ class SCIMClient:
220
226
  if model not in CONFIG_RESOURCES
221
227
  ]
222
228
 
229
+ def _check_status_codes(
230
+ self, status_code: int, expected_status_codes: Optional[list[int]]
231
+ ):
232
+ if (
233
+ self.check_response_status_codes
234
+ and expected_status_codes
235
+ and status_code not in expected_status_codes
236
+ ):
237
+ raise UnexpectedStatusCode(status_code)
238
+
239
+ def _check_content_types(self, headers: dict):
240
+ # Interoperability considerations: The "application/scim+json" media
241
+ # type is intended to identify JSON structure data that conforms to
242
+ # the SCIM protocol and schema specifications. Older versions of
243
+ # SCIM are known to informally use "application/json".
244
+ # https://datatracker.ietf.org/doc/html/rfc7644.html#section-8.1
245
+
246
+ actual_content_type = headers.get("content-type", "").split(";").pop(0)
247
+ expected_response_content_types = ("application/scim+json", "application/json")
248
+ if (
249
+ self.check_response_content_type
250
+ and actual_content_type not in expected_response_content_types
251
+ ):
252
+ raise UnexpectedContentType(content_type=actual_content_type)
253
+
223
254
  def check_response(
224
255
  self,
225
256
  payload: Optional[dict],
@@ -234,19 +265,8 @@ class SCIMClient:
234
265
  if raise_scim_errors is None:
235
266
  raise_scim_errors = self.raise_scim_errors
236
267
 
237
- if expected_status_codes and status_code not in expected_status_codes:
238
- raise UnexpectedStatusCode(status_code)
239
-
240
- # Interoperability considerations: The "application/scim+json" media
241
- # type is intended to identify JSON structure data that conforms to
242
- # the SCIM protocol and schema specifications. Older versions of
243
- # SCIM are known to informally use "application/json".
244
- # https://datatracker.ietf.org/doc/html/rfc7644.html#section-8.1
245
-
246
- actual_content_type = headers.get("content-type", "").split(";").pop(0)
247
- expected_response_content_types = ("application/scim+json", "application/json")
248
- if actual_content_type not in expected_response_content_types:
249
- raise UnexpectedContentType(content_type=actual_content_type)
268
+ self._check_status_codes(status_code, expected_status_codes)
269
+ self._check_content_types(headers)
250
270
 
251
271
  # In addition to returning an HTTP response code, implementers MUST return
252
272
  # the errors in the body of the response in a JSON format
@@ -560,11 +580,11 @@ class BaseSyncSCIMClient(SCIMClient):
560
580
 
561
581
  :param resource: The resource to create
562
582
  If is a :data:`dict`, the resource type will be guessed from the schema.
563
- :param check_request_payload: If set, overwrites :paramref:`SCIMClient.check_request_payload`.
564
- :param check_response_payload: If set, overwrites :paramref:`SCIMClient.check_response_payload`.
583
+ :param check_request_payload: If set, overwrites :paramref:`~scim2_client.SCIMClient.check_request_payload`.
584
+ :param check_response_payload: If set, overwrites :paramref:`~scim2_client.SCIMClient.check_response_payload`.
565
585
  :param expected_status_codes: The list of expected status codes form the response.
566
586
  If :data:`None` any status code is accepted.
567
- :param raise_scim_errors: If set, overwrites :paramref:`SCIMClient.raise_scim_errors`.
587
+ :param raise_scim_errors: If set, overwrites :paramref:`~scim2_client.SCIMClient.raise_scim_errors`.
568
588
  :param kwargs: Additional parameters passed to the underlying HTTP request
569
589
  library.
570
590
 
@@ -612,11 +632,11 @@ class BaseSyncSCIMClient(SCIMClient):
612
632
  :param resource_model: A :class:`~scim2_models.Resource` subtype or :data:`None`
613
633
  :param id: The SCIM id of an object to get, or :data:`None`
614
634
  :param search_request: An object detailing the search query parameters.
615
- :param check_request_payload: If set, overwrites :paramref:`SCIMClient.check_request_payload`.
616
- :param check_response_payload: If set, overwrites :paramref:`SCIMClient.check_response_payload`.
635
+ :param check_request_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_request_payload`.
636
+ :param check_response_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_response_payload`.
617
637
  :param expected_status_codes: The list of expected status codes form the response.
618
638
  If :data:`None` any status code is accepted.
619
- :param raise_scim_errors: If set, overwrites :paramref:`SCIMClient.raise_scim_errors`.
639
+ :param raise_scim_errors: If set, overwrites :paramref:`scim2_client.SCIMClient.raise_scim_errors`.
620
640
  :param kwargs: Additional parameters passed to the underlying HTTP request library.
621
641
 
622
642
  :return:
@@ -681,11 +701,11 @@ class BaseSyncSCIMClient(SCIMClient):
681
701
  :param resource_models: Resource type or union of types expected
682
702
  to be read from the response.
683
703
  :param search_request: An object detailing the search query parameters.
684
- :param check_request_payload: If set, overwrites :paramref:`SCIMClient.check_request_payload`.
685
- :param check_response_payload: If set, overwrites :paramref:`SCIMClient.check_response_payload`.
704
+ :param check_request_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_request_payload`.
705
+ :param check_response_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_response_payload`.
686
706
  :param expected_status_codes: The list of expected status codes form the response.
687
707
  If :data:`None` any status code is accepted.
688
- :param raise_scim_errors: If set, overwrites :paramref:`SCIMClient.raise_scim_errors`.
708
+ :param raise_scim_errors: If set, overwrites :paramref:`scim2_client.SCIMClient.raise_scim_errors`.
689
709
  :param kwargs: Additional parameters passed to the underlying
690
710
  HTTP request library.
691
711
 
@@ -728,10 +748,10 @@ class BaseSyncSCIMClient(SCIMClient):
728
748
 
729
749
  :param resource_model: The type of the resource to delete.
730
750
  :param id: The type id the resource to delete.
731
- :param check_response_payload: If set, overwrites :paramref:`SCIMClient.check_response_payload`.
751
+ :param check_response_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_response_payload`.
732
752
  :param expected_status_codes: The list of expected status codes form the response.
733
753
  If :data:`None` any status code is accepted.
734
- :param raise_scim_errors: If set, overwrites :paramref:`SCIMClient.raise_scim_errors`.
754
+ :param raise_scim_errors: If set, overwrites :paramref:`scim2_client.SCIMClient.raise_scim_errors`.
735
755
  :param kwargs: Additional parameters passed to the underlying
736
756
  HTTP request library.
737
757
 
@@ -766,11 +786,11 @@ class BaseSyncSCIMClient(SCIMClient):
766
786
 
767
787
  :param resource: The new resource to replace.
768
788
  If is a :data:`dict`, the resource type will be guessed from the schema.
769
- :param check_request_payload: If set, overwrites :paramref:`SCIMClient.check_request_payload`.
770
- :param check_response_payload: If set, overwrites :paramref:`SCIMClient.check_response_payload`.
789
+ :param check_request_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_request_payload`.
790
+ :param check_response_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_response_payload`.
771
791
  :param expected_status_codes: The list of expected status codes form the response.
772
792
  If :data:`None` any status code is accepted.
773
- :param raise_scim_errors: If set, overwrites :paramref:`SCIMClient.raise_scim_errors`.
793
+ :param raise_scim_errors: If set, overwrites :paramref:`scim2_client.SCIMClient.raise_scim_errors`.
774
794
  :param kwargs: Additional parameters passed to the underlying
775
795
  HTTP request library.
776
796
 
@@ -798,14 +818,25 @@ class BaseSyncSCIMClient(SCIMClient):
798
818
  """
799
819
  raise NotImplementedError()
800
820
 
801
- def discover(self):
802
- """Dynamically discover the server models :class:`~scim2_models.Schema` and :class:`~scim2_models.ResourceType`."""
803
- resource_types_response = self.query(ResourceType)
804
- schemas_response = self.query(Schema)
805
- self.service_provider_config = self.query(ServiceProviderConfig)
806
- self.resource_types = resource_types_response.resources
807
- schemas = schemas_response.resources
808
- self.resource_models = self.build_resource_models(self.resource_types, schemas)
821
+ def discover(self, schemas=True, resource_types=True, service_provider_config=True):
822
+ """Dynamically discover the server configuration objects.
823
+
824
+ :param schemas: Whether to discover the :class:`~scim2_models.Schema` endpoint.
825
+ :param resource_types: Whether to discover the :class:`~scim2_models.ResourceType` endpoint.
826
+ :param service_provider_config: Whether to discover the :class:`~scim2_models.ServiceProviderConfig` endpoint.
827
+ """
828
+ if resource_types:
829
+ resource_types_response = self.query(ResourceType)
830
+ self.resource_types = resource_types_response.resources
831
+
832
+ if schemas:
833
+ schemas_response = self.query(Schema)
834
+ self.resource_models = self.build_resource_models(
835
+ self.resource_types, schemas_response.resources
836
+ )
837
+
838
+ if service_provider_config:
839
+ self.service_provider_config = self.query(ServiceProviderConfig)
809
840
 
810
841
 
811
842
  class BaseAsyncSCIMClient(SCIMClient):
@@ -826,11 +857,11 @@ class BaseAsyncSCIMClient(SCIMClient):
826
857
 
827
858
  :param resource: The resource to create
828
859
  If is a :data:`dict`, the resource type will be guessed from the schema.
829
- :param check_request_payload: If set, overwrites :paramref:`SCIMClient.check_request_payload`.
830
- :param check_response_payload: If set, overwrites :paramref:`SCIMClient.check_response_payload`.
860
+ :param check_request_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_request_payload`.
861
+ :param check_response_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_response_payload`.
831
862
  :param expected_status_codes: The list of expected status codes form the response.
832
863
  If :data:`None` any status code is accepted.
833
- :param raise_scim_errors: If set, overwrites :paramref:`SCIMClient.raise_scim_errors`.
864
+ :param raise_scim_errors: If set, overwrites :paramref:`scim2_client.SCIMClient.raise_scim_errors`.
834
865
  :param kwargs: Additional parameters passed to the underlying HTTP request
835
866
  library.
836
867
 
@@ -878,11 +909,11 @@ class BaseAsyncSCIMClient(SCIMClient):
878
909
  :param resource_model: A :class:`~scim2_models.Resource` subtype or :data:`None`
879
910
  :param id: The SCIM id of an object to get, or :data:`None`
880
911
  :param search_request: An object detailing the search query parameters.
881
- :param check_request_payload: If set, overwrites :paramref:`SCIMClient.check_request_payload`.
882
- :param check_response_payload: If set, overwrites :paramref:`SCIMClient.check_response_payload`.
912
+ :param check_request_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_request_payload`.
913
+ :param check_response_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_response_payload`.
883
914
  :param expected_status_codes: The list of expected status codes form the response.
884
915
  If :data:`None` any status code is accepted.
885
- :param raise_scim_errors: If set, overwrites :paramref:`SCIMClient.raise_scim_errors`.
916
+ :param raise_scim_errors: If set, overwrites :paramref:`scim2_client.SCIMClient.raise_scim_errors`.
886
917
  :param kwargs: Additional parameters passed to the underlying HTTP request library.
887
918
 
888
919
  :return:
@@ -947,11 +978,11 @@ class BaseAsyncSCIMClient(SCIMClient):
947
978
  :param resource_models: Resource type or union of types expected
948
979
  to be read from the response.
949
980
  :param search_request: An object detailing the search query parameters.
950
- :param check_request_payload: If set, overwrites :paramref:`SCIMClient.check_request_payload`.
951
- :param check_response_payload: If set, overwrites :paramref:`SCIMClient.check_response_payload`.
981
+ :param check_request_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_request_payload`.
982
+ :param check_response_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_response_payload`.
952
983
  :param expected_status_codes: The list of expected status codes form the response.
953
984
  If :data:`None` any status code is accepted.
954
- :param raise_scim_errors: If set, overwrites :paramref:`SCIMClient.raise_scim_errors`.
985
+ :param raise_scim_errors: If set, overwrites :paramref:`scim2_client.SCIMClient.raise_scim_errors`.
955
986
  :param kwargs: Additional parameters passed to the underlying
956
987
  HTTP request library.
957
988
 
@@ -994,10 +1025,10 @@ class BaseAsyncSCIMClient(SCIMClient):
994
1025
 
995
1026
  :param resource_model: The type of the resource to delete.
996
1027
  :param id: The type id the resource to delete.
997
- :param check_response_payload: If set, overwrites :paramref:`SCIMClient.check_response_payload`.
1028
+ :param check_response_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_response_payload`.
998
1029
  :param expected_status_codes: The list of expected status codes form the response.
999
1030
  If :data:`None` any status code is accepted.
1000
- :param raise_scim_errors: If set, overwrites :paramref:`SCIMClient.raise_scim_errors`.
1031
+ :param raise_scim_errors: If set, overwrites :paramref:`scim2_client.SCIMClient.raise_scim_errors`.
1001
1032
  :param kwargs: Additional parameters passed to the underlying
1002
1033
  HTTP request library.
1003
1034
 
@@ -1032,11 +1063,11 @@ class BaseAsyncSCIMClient(SCIMClient):
1032
1063
 
1033
1064
  :param resource: The new resource to replace.
1034
1065
  If is a :data:`dict`, the resource type will be guessed from the schema.
1035
- :param check_request_payload: If set, overwrites :paramref:`SCIMClient.check_request_payload`.
1036
- :param check_response_payload: If set, overwrites :paramref:`SCIMClient.check_response_payload`.
1066
+ :param check_request_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_request_payload`.
1067
+ :param check_response_payload: If set, overwrites :paramref:`scim2_client.SCIMClient.check_response_payload`.
1037
1068
  :param expected_status_codes: The list of expected status codes form the response.
1038
1069
  If :data:`None` any status code is accepted.
1039
- :param raise_scim_errors: If set, overwrites :paramref:`SCIMClient.raise_scim_errors`.
1070
+ :param raise_scim_errors: If set, overwrites :paramref:`scim2_client.SCIMClient.raise_scim_errors`.
1040
1071
  :param kwargs: Additional parameters passed to the underlying
1041
1072
  HTTP request library.
1042
1073
 
@@ -1064,14 +1095,33 @@ class BaseAsyncSCIMClient(SCIMClient):
1064
1095
  """
1065
1096
  raise NotImplementedError()
1066
1097
 
1067
- async def discover(self):
1068
- """Dynamically discover the server models :class:`~scim2_models.Schema` and :class:`~scim2_models.ResourceType`."""
1069
- resources_task = asyncio.create_task(self.query(ResourceType))
1070
- schemas_task = asyncio.create_task(self.query(Schema))
1071
- spc_task = asyncio.create_task(self.query(ServiceProviderConfig))
1072
- resource_types_response = await resources_task
1073
- schemas_response = await schemas_task
1074
- self.service_provider_config = await spc_task
1075
- self.resource_types = resource_types_response.resources
1076
- schemas = schemas_response.resources
1077
- self.resource_models = self.build_resource_models(self.resource_types, schemas)
1098
+ async def discover(
1099
+ self, schemas=True, resource_types=True, service_provider_config=True
1100
+ ):
1101
+ """Dynamically discover the server configuration objects.
1102
+
1103
+ :param schemas: Whether to discover the :class:`~scim2_models.Schema` endpoint.
1104
+ :param resource_types: Whether to discover the :class:`~scim2_models.ResourceType` endpoint.
1105
+ :param service_provider_config: Whether to discover the :class:`~scim2_models.ServiceProviderConfig` endpoint.
1106
+ """
1107
+ if schemas:
1108
+ schemas_task = asyncio.create_task(self.query(Schema))
1109
+
1110
+ if resource_types:
1111
+ resources_types_task = asyncio.create_task(self.query(ResourceType))
1112
+
1113
+ if service_provider_config:
1114
+ spc_task = asyncio.create_task(self.query(ServiceProviderConfig))
1115
+
1116
+ if resource_types:
1117
+ resource_types_response = await resources_types_task
1118
+ self.resource_types = resource_types_response.resources
1119
+
1120
+ if schemas:
1121
+ schemas_response = await schemas_task
1122
+ self.resource_models = self.build_resource_models(
1123
+ self.resource_types, schemas_response.resources
1124
+ )
1125
+
1126
+ if service_provider_config:
1127
+ self.service_provider_config = await spc_task
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: scim2-client
3
- Version: 0.4.1
3
+ Version: 0.4.3
4
4
  Summary: Pythonically build SCIM requests and parse SCIM responses
5
5
  Project-URL: documentation, https://scim2-client.readthedocs.io
6
6
  Project-URL: repository, https://github.com/python-scim/scim2-client
@@ -1,11 +1,11 @@
1
1
  scim2_client/__init__.py,sha256=l0pyBLiTpFA68ao98PqQLT_Xx0mw8BHumwrIHYCWa_M,845
2
- scim2_client/client.py,sha256=8M_3truHEpFFlmnVy3fk7Hl67duS6iQlBMuKRoep5Ew,44048
2
+ scim2_client/client.py,sha256=ySG8sLOqOxzsW1CF2uR1UO_uuUef8sgUhfiWFviu-Wo,46293
3
3
  scim2_client/errors.py,sha256=FVmRXsaZLn1VZhJ3dSDs4IqycuU92AEun9JWWMseVO8,4397
4
4
  scim2_client/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  scim2_client/engines/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  scim2_client/engines/httpx.py,sha256=L39ZZHjqe43uIQpgh_r_maqM2gkf3_Rk6d8MeNe57gk,17781
7
7
  scim2_client/engines/werkzeug.py,sha256=mVpK0GjmD4fu0jI0W2zqrn7GjBFZ0AjNk2gBO5415Gk,10230
8
- scim2_client-0.4.1.dist-info/METADATA,sha256=k3S_PnzmSlWiNE2TMZgpt4gZf1Nv5Pv-7xGVSAFqHpQ,16961
9
- scim2_client-0.4.1.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
10
- scim2_client-0.4.1.dist-info/licenses/LICENSE.md,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
11
- scim2_client-0.4.1.dist-info/RECORD,,
8
+ scim2_client-0.4.3.dist-info/METADATA,sha256=YHWHLDbgqOKPjlVU6Ab-WEFrCZOrXnVrzixgZ4_6kzw,16961
9
+ scim2_client-0.4.3.dist-info/WHEEL,sha256=C2FUgwZgiLbznR-k0b_5k3Ai_1aASOXDss3lzCUsUug,87
10
+ scim2_client-0.4.3.dist-info/licenses/LICENSE.md,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
11
+ scim2_client-0.4.3.dist-info/RECORD,,