Skip to content

cmem_client.repositories.user_accounts¤

Repository for the Keycloak user accounts of a Corporate Memory deployment.

Provides UserAccountRepository for creating, updating and deleting user accounts, for managing their group membership and for resetting their password. Accounts are keyed by their username, while the group operations take the internal Keycloak account ID.

Examples:

List the accounts and read one of them:

>>> from cmem_client.client import Client
>>> client = Client.from_env()
>>> list(client.user_accounts)
>>> account = client.user_accounts["admin"]

Inspect the groups of the deployment and of a single account. Note that the group operations expect the internal account ID, not the username:

>>> [group.name for group in client.user_accounts.list_groups()]
>>> [group.name for group in client.user_accounts.get_user_groups(account.id)]

reset_password() sets a new password for an account and request_password_change() makes the account choose one at its next login. Both are described rather than shown running, because they change a credential which is in use, and unlike the workspace and the store, Keycloak is not restored afterwards.

Classes:

UserAccountCreateConfig¤

Bases: CreateConfig

User account creation configuration.

Attributes:

  • model_config

UserAccountDeleteConfig¤

Bases: DeleteConfig

User account deletion configuration.

Attributes:

  • model_config

UserAccountRepository¤

Bases: PlainListRepository, CreateItemProtocol, DeleteItemProtocol, UpdateItemProtocol

Repository for Keycloak user accounts.

Provides access to user accounts in the Corporate Memory Keycloak realm. Users are identified by their username and stored in a dictionary keyed by username.

In addition to standard CRUD operations, this repository provides methods for group assignment, group listing, and password management.

Functions:

Attributes:

  • logger (Logger) – Gets the client logger

assign_group¤

assign_group(user_id, group_id)

Assign a group to a user.

Parameters:

  • user_id (str) – The Keycloak UUID of the user.
  • group_id (str) – The Keycloak UUID of the group.

create_item¤

create_item(item, skip_if_existing=False, configuration=None)

Create (add) a new item to the repository

Parameters:

  • item (ItemType) – The item to add to the repository
  • skip_if_existing (bool) – If true, creating already existing items will be ignored
  • configuration (CreateItemConfig_contra | None) – Optional configuration

Raises:

delete_all¤

delete_all()

Delete all items from the repository

delete_item¤

delete_item(key, skip_if_missing=False, configuration=None)

Delete an item from the repository

Parameters:

  • key (str) – The key of the item to delete
  • skip_if_missing (bool) – If True, it is ignored if the deleted item even exists
  • configuration (DeleteItemConfig) – Optional configuration for deletion

Raises:

fetch_data¤

fetch_data()

Fetch simple list from a JSON endpoint via a type adapter

Use this method to fetch data when your result set is an array of objects.

get_user_groups¤

get_user_groups(user_id)

Get groups assigned to a user.

Parameters:

  • user_id (str) – The Keycloak UUID of the user.

Returns:

  • list[Group] – List of Group objects currently assigned to the user.

items¤

items()

Get the items of the repository

keys¤

keys()

Get the keys of the repository

list_groups¤

list_groups()

List all groups in the Keycloak realm.

Returns:

  • list[Group] – List of Group objects available in the realm.

logger¤

logger: logging.Logger

Gets the client logger

raise_modification_error¤

raise_modification_error(response)

Raise an exception if needed

request_password_change¤

request_password_change(user_id)

Send a password-change request email to a user.

Parameters:

  • user_id (str) – The Keycloak UUID of the user.

reset_password¤

reset_password(user_id, value, temporary=False)

Reset the password for a user.

Parameters:

  • user_id (str) – The Keycloak UUID of the user.
  • value (str) – The new password value.
  • temporary (bool) – If True, the user must change the password on next login.

unassign_group¤

unassign_group(user_id, group_id)

Remove a group from a user.

Parameters:

  • user_id (str) – The Keycloak UUID of the user.
  • group_id (str) – The Keycloak UUID of the group.

update_item¤

update_item(item, configuration=None)

Update an existing item in the repository.

Parameters:

  • item (ItemType) – The item to update in the repository.
  • configuration (UpdateItemConfig_contra | None) – Optional configuration for the update operation.

Raises:

values¤

values()

Get the values of the repository

UserAccountUpdateConfig¤

Bases: UpdateConfig

User account update configuration.

Attributes:

  • model_config

Comments