11import click
22from click import ClickException
3- from scim2_client import SCIMClientError
43from scim2_models import ResourceType
4+ from scim2_models import ResponseParameters
55from scim2_models import Schema
66from scim2_models import SearchRequest
77from scim2_models import ServiceProviderConfig
1010from scim2_cli .utils import exception_to_click_error
1111
1212from .utils import DOC_URL
13+ from .utils import SCIM_EXCEPTIONS
1314from .utils import formatted_payload
1415
1516
@@ -73,6 +74,9 @@ def query_cli(
7374 - If :code:`RESOURCE_TYPE` is :code:`user` and :code:`id` is not set, then the request will made on the :code:`/Users` endpoint.
7475 - If :code:`RESOURCE_TYPE` is not set, then the request will made on the :code:`/` endpoint.
7576
77+ When a single resource is queried, only :code:`--attribute` and :code:`--excluded-attribute` are
78+ available, as defined in `RFC7644 §3.4.1 <https://www.rfc-editor.org/rfc/rfc7644#section-3.4.1>`_.
79+
7680 Data passed in JSON format to stdin is sent as request arguments and all the other query arguments are ignored:
7781
7882 .. code-block:: bash
@@ -92,10 +96,35 @@ def query_cli(
9296 f"Unknown resource type '{ resource_type } . Available values are: { ok_values } '"
9397 ) from exc
9498
99+ # ServiceProviderConfig is a singleton endpoint, so it is reached without an id.
100+ single_resource = bool (id ) or resource_type is ServiceProviderConfig
101+ listing_options = [
102+ name
103+ for name , value in (
104+ ("--start-index" , start_index ),
105+ ("--count" , count ),
106+ ("--filter" , filter ),
107+ ("--sort-by" , sort_by ),
108+ ("--sort-order" , sort_order ),
109+ )
110+ if value is not None
111+ ]
112+ if single_resource and listing_options :
113+ raise ClickException (
114+ f"{ ', ' .join (listing_options )} cannot be used when querying a single resource."
115+ )
116+
95117 if ctx .obj .get ("stdin" ):
96118 check_request_payload = False
97119 payload = ctx .obj .get ("stdin" )
98120
121+ elif single_resource :
122+ check_request_payload = True
123+ payload = ResponseParameters (
124+ attributes = attribute ,
125+ excluded_attributes = excluded_attribute ,
126+ )
127+
99128 else :
100129 check_request_payload = True
101130 payload = SearchRequest (
@@ -112,12 +141,12 @@ def query_cli(
112141 response = ctx .obj ["client" ].query (
113142 resource_type ,
114143 id ,
115- search_request = payload ,
144+ query_parameters = payload ,
116145 check_request_payload = check_request_payload ,
117146 raise_scim_errors = False ,
118147 )
119148
120- except SCIMClientError as scim_exc :
149+ except SCIM_EXCEPTIONS as scim_exc :
121150 raise exception_to_click_error (scim_exc ) from scim_exc
122151
123152 payload = formatted_payload (response .model_dump (), indent )
0 commit comments