2020from .integrations import delete_record
2121from .integrations import from_scim_user
2222from .integrations import get_record
23+ from .integrations import get_resource_type
2324from .integrations import get_resource_types
25+ from .integrations import get_schema
2426from .integrations import get_schemas
2527from .integrations import list_records
2628from .integrations import save_record
@@ -165,11 +167,10 @@ def delete_user(app_record):
165167def list_users ():
166168 """Return one page of users as a SCIM ListResponse."""
167169 req = SearchRequest .model_validate (request .args .to_dict ())
168- all_records = list_records ()
169- page = all_records [req .start_index_0 : req .stop_index_0 ]
170+ total , page = list_records (req .start_index_0 , req .stop_index_0 )
170171 resources = [to_scim_user (record ) for record in page ]
171172 response = ListResponse [User ](
172- total_results = len ( all_records ) ,
173+ total_results = total ,
173174 start_index = req .start_index or 1 ,
174175 items_per_page = len (resources ),
175176 resources = resources ,
@@ -211,10 +212,9 @@ def create_user():
211212def list_schemas ():
212213 """Return one page of SCIM schemas the server exposes."""
213214 req = SearchRequest .model_validate (request .args .to_dict ())
214- all_schemas = get_schemas ()
215- page = all_schemas [req .start_index_0 : req .stop_index_0 ]
215+ total , page = get_schemas (req .start_index_0 , req .stop_index_0 )
216216 response = ListResponse [Schema ](
217- total_results = len ( all_schemas ) ,
217+ total_results = total ,
218218 start_index = req .start_index or 1 ,
219219 items_per_page = len (page ),
220220 resources = page ,
@@ -226,16 +226,17 @@ def list_schemas():
226226
227227
228228@bp .get ("/Schemas/<path:schema_id>" )
229- def get_schema (schema_id ):
229+ def get_schema_by_id (schema_id ):
230230 """Return one SCIM schema by its URI identifier."""
231- for schema in get_schemas ():
232- if schema .id == schema_id :
233- return (
234- schema .model_dump_json (scim_ctx = Context .RESOURCE_QUERY_RESPONSE ),
235- HTTPStatus .OK ,
236- )
237- scim_error = Error (status = 404 , detail = f"Schema { schema_id !r} not found" )
238- return scim_error .model_dump_json (), HTTPStatus .NOT_FOUND
231+ try :
232+ schema = get_schema (schema_id )
233+ except KeyError :
234+ scim_error = Error (status = 404 , detail = f"Schema { schema_id !r} not found" )
235+ return scim_error .model_dump_json (), HTTPStatus .NOT_FOUND
236+ return (
237+ schema .model_dump_json (scim_ctx = Context .RESOURCE_QUERY_RESPONSE ),
238+ HTTPStatus .OK ,
239+ )
239240# -- schemas-end --
240241
241242
@@ -244,10 +245,9 @@ def get_schema(schema_id):
244245def list_resource_types ():
245246 """Return one page of SCIM resource types the server exposes."""
246247 req = SearchRequest .model_validate (request .args .to_dict ())
247- all_resource_types = get_resource_types ()
248- page = all_resource_types [req .start_index_0 : req .stop_index_0 ]
248+ total , page = get_resource_types (req .start_index_0 , req .stop_index_0 )
249249 response = ListResponse [ResourceType ](
250- total_results = len ( all_resource_types ) ,
250+ total_results = total ,
251251 start_index = req .start_index or 1 ,
252252 items_per_page = len (page ),
253253 resources = page ,
@@ -259,18 +259,19 @@ def list_resource_types():
259259
260260
261261@bp .get ("/ResourceTypes/<resource_type_id>" )
262- def get_resource_type (resource_type_id ):
262+ def get_resource_type_by_id (resource_type_id ):
263263 """Return one SCIM resource type by its identifier."""
264- for rt in get_resource_types ():
265- if rt .id == resource_type_id :
266- return (
267- rt .model_dump_json (scim_ctx = Context .RESOURCE_QUERY_RESPONSE ),
268- HTTPStatus .OK ,
269- )
270- scim_error = Error (
271- status = 404 , detail = f"ResourceType { resource_type_id !r} not found"
264+ try :
265+ rt = get_resource_type (resource_type_id )
266+ except KeyError :
267+ scim_error = Error (
268+ status = 404 , detail = f"ResourceType { resource_type_id !r} not found"
269+ )
270+ return scim_error .model_dump_json (), HTTPStatus .NOT_FOUND
271+ return (
272+ rt .model_dump_json (scim_ctx = Context .RESOURCE_QUERY_RESPONSE ),
273+ HTTPStatus .OK ,
272274 )
273- return scim_error .model_dump_json (), HTTPStatus .NOT_FOUND
274275# -- resource-types-end --
275276
276277
0 commit comments