Mapping#

The classes describing how SCIM resources are stored in SQLAlchemy models.

class scim2_sqlalchemy.ResourceMapping(model, record, attributes, *, version)[source]#

How the resources of a SCIM model are stored in the records of a SQLAlchemy model.

The paths are checked against the SCIM model when the mapping is created, so a mistake raises at import time rather than at the first request.

Parameters:
Raises:

ValueError – When a path is not valid for the model, or when a value does not fit the attribute of its path.

schemas()[source]#

Return the schemas of the resources, restricted to what the mapping stores.

They hold the mapped attributes only, and an attribute the mapping reads but never writes is readOnly. Publish them, rather than the schemas of model, so that clients know what the server stores: build the provider of the server with ScimProvider.from_discovery, and pass it to the storage.

Returns:

The schema of the resource, then the schemas of its extensions.

Return type:

list[Schema]

class scim2_sqlalchemy.Attribute(expression, *, readable=True, writable=True)[source]#

A column holding a SCIM attribute that the storage only reads, or only writes.

To store a value in another form, map the attribute to a hybrid_property that converts it, in Python and in SQL.

Parameters:
  • expression (Any) – The column, or the hybrid_property, holding the value.

  • readable (bool) – Whether the storage reads the attribute. When False, the attribute is write-only, such as a password: the storage never returns it, nor filters or sorts on it.

  • writable (bool) – Whether the storage writes the attribute. When False, the attribute is read-only.

class scim2_sqlalchemy.Many(relationship, attributes)[source]#

The entries of a multi-valued complex attribute, stored in a child table.

The entries belong to the resource: writing the resource replaces them. The relationship needs cascade="all, delete-orphan" (delete-orphan). Its order_by gives the order of the entries. A sort uses the primary entry, or else the first one.

Parameters:
  • relationship (Any) – The relationship() from the resource record to the entry records.

  • attributes (Mapping[str, Any]) – The columns of the entry records, by sub-attribute name, such as "value" or "type".

A complex attribute linking to other resources.

A multi-valued attribute, such as the members of a group, maps to a relationship holding several records. A single-valued one, such as the manager of an enterprise user, maps to a relationship holding one record.

value is the id of the linked resource. Its display name, the display or displayName sub-attribute, is the displayName of the linked resource when its mapping has one, or else its userName. Writing the resource changes the links, and never creates nor deletes the linked resources.

A Link links to the resources of one resource type. An attribute linking to several resource types, such as the members of a group holding users and groups, maps to a list of Links, one per resource type. The entries are read in the order of the list.

Parameters:
  • relationship (Any) – The relationship() from the resource record to the records of the linked resources.

  • resource_type (str) – The name of the resource type of the linked resources, as the storage knows it.

  • type (str | None) – The type sub-attribute of the entries, such as "User" for the members of a group, or "direct" for the groups of a user. A client may send it, and a write with another value is refused. Without it, the storage does not store type.