tiny_pacs_identity.users

Database-backed user registry component.

Keeps the users that incoming associations authenticate as in the database. Passwords are stored salted and hashed (see tiny_pacs_identity.hashing), never in plaintext; the UserIdentityAuth component consumes the records when enforcing a device’s identity policy.

Create and maintain users with the users CLI subcommands against the offline database before starting a server that requires identity.

Module Attributes

MAX_USERNAME_LENGTH

Maximum length of a login name (size of the database column)

Classes

Users(bus, config)

Component that keeps user accounts in the database.

UsersConfig(*[, on])

Configuration of the Users component.

tiny_pacs_identity.users.MAX_USERNAME_LENGTH = 64

Maximum length of a login name (size of the database column)

class tiny_pacs_identity.users.UsersConfig(*, on: bool = False)[source]

Bases: ComponentConfig

Configuration of the Users component.

The component has no settings of its own; this model exists so the component provides its own config type to the loader like every other component.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

class tiny_pacs_identity.users.Users(bus: EventBus, config: UsersConfig | dict[str, Any])[source]

Bases: Component[UsersConfig]

Component that keeps user accounts in the database.

Handles the following events:

Component initialization.

Parameters:
  • bus (trolleybus.EventBus) – event bus

  • config (UsersConfig or dict) – component configuration

config_model

alias of UsersConfig

migrations(_: None = None) ComponentMigrations[source]

Returns schema migrations of the component tables

Returns:

component migrations

Return type:

schema.ComponentMigrations

user_by_name(username: str) UserModel | None[source]

Handles UserByName event

Parameters:

username (str) – login name of the user

Returns:

user record or None for unknown usernames

Return type:

UserModel or None

user_list(_: None = None) list[UserModel][source]

Handles UserList event

Returns:

every user, ordered by username

Return type:

list[UserModel]

user_add(payload: Mapping[str, Any]) UserModel[source]

Handles UserAdd event

Parameters:

payload (Mapping) – username and password mapping

Returns:

the created user record

Return type:

UserModel

Raises:

ValueError – raised for missing, invalid or duplicate usernames and for empty passwords

user_set_password(payload: Mapping[str, Any]) UserModel[source]

Handles UserSetPassword event

Parameters:

payload (Mapping) – username and password mapping

Returns:

the updated user record

Return type:

UserModel

Raises:

ValueError – raised for a missing or unknown username and for an empty password

user_remove(username: str) bool[source]

Handles UserRemove event

Parameters:

username (str) – login name of the user to remove; normalized like in every other handler (stripped, validated)

Returns:

whether the user existed and was removed

Return type:

bool

Raises:

ValueError – raised for a missing, empty or oversized username

user_set_active(payload: Mapping[str, Any]) UserModel[source]

Handles UserSetActive event

Parameters:

payload (Mapping) – username and is_active mapping

Returns:

the updated user record

Return type:

UserModel

Raises:

ValueError – raised for a missing or unknown username and for a missing is_active flag

atomic() Any[source]

Context manager for handling simple transactions

Returns:

atomic transaction