Skip to content

Commit 4f82fe5

Browse files
committed
doc: document server discovery
1 parent be0c26a commit 4f82fe5

File tree

2 files changed

+53
-11
lines changed

2 files changed

+53
-11
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,24 @@ pip install scim2-client[httpx]
2222

2323
## Usage
2424

25-
Check the [tutorial](https://scim2-client.readthedocs.io/en/latest/tutorial.html) and the [reference](https://scim2-client.readthedocs.io/en/latest/reference.html) for more details.
25+
Check the [tutorial](https://scim2-client.readthedocs.io/en/latest/tutorial.html)
26+
and the [reference](https://scim2-client.readthedocs.io/en/latest/reference.html) for more details.
2627

2728
Here is an example of usage:
2829

2930
```python
3031
import datetime
3132
from httpx import Client
32-
from scim2_models import User, EnterpriseUser, Group, Error
33+
from scim2_models import Error
3334
from scim2_client.engines.httpx import SyncSCIMClient
3435

3536
client = Client(base_url="https://auth.example/scim/v2", headers={"Authorization": "Bearer foobar"})
36-
scim = SyncSCIMClient(client, resource_types=(User[EnterpriseUser], Group))
37+
scim = SyncSCIMClient(client)
38+
scim.discover()
39+
User = scim.get_resource_model("User")
3740

3841
# Query resources
39-
user = scim.query(User[EnterpriseUser], "2819c223-7f76-453a-919d-413861904646")
42+
user = scim.query(User, "2819c223-7f76-453a-919d-413861904646")
4043
assert user.user_name == "[email protected]"
4144
assert user.meta.last_updated == datetime.datetime(
4245
2024, 4, 13, 12, 0, 0, tzinfo=datetime.timezone.utc

doc/tutorial.rst

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,58 @@ In addition to your SCIM server root endpoint, you will probably want to provide
1313
.. code-block:: python
1414
1515
from httpx import Client
16-
from scim2_models import User, EnterpriseUserUser, Group
1716
from scim2_client.engines.httpx import SyncSCIMClient
1817
1918
client = Client(base_url="https://auth.example/scim/v2", headers={"Authorization": "Bearer foobar"})
20-
scim = SyncSCIMClient(client, resource_models=(User[EnterpriseUser], Group))
19+
scim = SyncSCIMClient(client)
2120
22-
You need to give to indicate to :class:`~scim2_client.BaseSCIMClient` all the different :class:`~scim2_models.Resource` types that you will need to manipulate with the :code:`resource_models` parameter.
23-
This is needed so scim2-client will be able to guess which resource type to instante when an arbitrary payload is met.
21+
You need to give to indicate to :class:`~scim2_client.BaseSCIMClient` all the different :class:`~scim2_models.Resource` models that you will need to manipulate, and the matching :class:`~scim2_models.ResourceType` objects to let the client know where to look for resources on the server.
2422

25-
.. todo::
23+
You can either provision those objects manually or automatically.
2624

27-
We plan to implement the automatic discovery of SCIM server resources,
28-
so they can dynamically be used without explicitly passing them with the :code:`resource_models` parameter.
25+
Automatic provisioning
26+
~~~~~~~~~~~~~~~~~~~~~~
27+
28+
The easiest way is to let the client discover what :class:`~scim2_models.Schema` and :class:`~scim2_models.ResourceType` are available on the server by calling :meth:`~scim2_client.BaseSyncSCIMClient.discover`.
29+
It will dynamically generate models based on those schema, and make them available to use with :meth:`~scim2_client.BaseSCIMClient.get_resource_model`.
30+
31+
.. code-block:: python
32+
:caption: Dynamically discover models from the server
33+
34+
scim.discover()
35+
User = scim.get_resource_model("User")
36+
37+
Manual provisioning
38+
~~~~~~~~~~~~~~~~~~~
39+
To manually register models and resource types, you can simply use the :paramref:`~scim2_client.BaseSCIMClient.resource_models` and :paramref:`~scim2_client.BaseSCIMClient.resource_types` arguments.
40+
41+
42+
.. code-block:: python
43+
:caption: Manually registering models and resource types
44+
45+
from scim2_models import User, EnterpriseUserUser, Group, ResourceType
46+
scim = SyncSCIMClient(
47+
client,
48+
resource_models=[User[EnterpriseUser], Group],
49+
resource_types=[ResourceType(id="User", ...), ResourceType(id="Group", ...)],
50+
)
51+
52+
.. tip::
53+
54+
If you know that all the resources are hosted at regular server endpoints
55+
(for instance `/Users` for :class:`~scim2_models.User` etc.),
56+
you can skip passing the :class:`~scim2_models.ResourceType` objects by hand,
57+
and simply call :meth:`~scim2_client.BaseSCIMClient.register_naive_resource_types`.
58+
59+
.. code-block:: python
60+
:caption: Manually registering models and resource types
61+
62+
from scim2_models import User, EnterpriseUserUser, Group, ResourceType
63+
scim = SyncSCIMClient(
64+
client,
65+
resource_models=[User[EnterpriseUser], Group],
66+
)
67+
scim.register_naive_resource_types()
2968
3069
Performing actions
3170
==================

0 commit comments

Comments
 (0)