Storages#
The storages reading and writing the resources with a SQLAlchemy Session.
- class scim2_sqlalchemy.SqlAlchemyStorage(mappings, session, provider=None, *, version_key=None)[source]#
Store SCIM resources in the records of SQLAlchemy models.
The storage never commits: committing the request is left to the application. Each write is flushed, so that the database fills the identifiers and checks its constraints.
A change the mappings cannot store raises an error rather than being lost:
InvalidValueExceptionfor an attribute no mapping stores, andMutabilityExceptionfor an attribute the mapping only reads. A value equal to the stored one is accepted, so a resource read and sent back can always be written.- Parameters:
mappings (Mapping[str, ResourceMapping]) – The mapping of each resource type, by resource type name.
session (Callable[[], Session]) – Return the current
Session, such as ascoped_session.provider (ScimProvider | None) – The provider of the server. The storage then returns instances of its models, rather than of the models of the mappings, and gives each link a
$refrelative to the SCIM root, from the endpoints of its resource types. Strings are compared with thecomparison_keyof its policy. Each of its resource types needs a mapping.version_key (bytes | None) – The key of the hash giving the version of the resources whose mapping has no version. Keep it secret, as the hash covers the values clients never read, such as a password hash. The hash covers the links too, so renaming a member changes the version of its groups. A write on such a resource locks its row until the end of the transaction.
- Raises:
ValueError – When a resource type has no mapping, or when a mapping has no version and no key is given.
- operation()[source]#
Run the operation in a savepoint.
The savepoint comes from
begin_nested(). A failed operation of a bulk request is then rolled back alone (RFC 7644 §3.7).- Return type:
Generator[None]
- class scim2_sqlalchemy.AsyncSqlAlchemyStorage(mappings, session, provider=None, *, version_key=None)[source]#
The asynchronous variant of
SqlAlchemyStorage.It needs the
asyncioextra, which installs the asynchronous support of SQLAlchemy:pip install "scim2-sqlalchemy[asyncio]".- Parameters:
mappings (Mapping[str, ResourceMapping]) – The mapping of each resource type, by resource type name.
session (Callable[[], AsyncSession]) – Return the current
AsyncSession, such as anasync_scoped_session.provider (ScimProvider | None) – The provider of the server. The storage then returns instances of its models, rather than of the models of the mappings. Strings are compared with the
comparison_keyof its policy. Each of its resource types needs a mapping.version_key (bytes | None) – The key of the hash giving the version of the resources whose mapping has no version. Keep it secret, as the hash covers the values clients never read, such as a password hash. The hash covers the links too, so renaming a member changes the version of its groups. A write on such a resource locks its row until the end of the transaction.
- Raises:
ValueError – When a resource type has no mapping, or when a mapping has no version and no key is given.
- operation()[source]#
Run the operation in a savepoint. See
SqlAlchemyStorage.operation().- Return type:
AsyncGenerator[None]