Users

class pyniryo_nate.components.Users(http_client: HttpClient, mqtt_client: MqttClient, correlation_id: str)[source]

Bases: BaseAPIComponent

Users component for managing user accounts.

This component provides methods for: - Creating, retrieving, updating, and deleting users - Managing user tokens - Updating user passwords

Methods

close

Close the component and release any resources if needed.

create

Create a new user.

create_token

Create a new token for a user.

delete

Delete a user by its ID.

get

Get a user by its ID.

get_all

Get all the registered users.

get_tokens

Get all the tokens of a user.

update

Update a user.

update_password

Update the password of a user.

Parameters:
  • http_client (HttpClient)

  • mqtt_client (MqttClient)

  • correlation_id (str)

get_all() → list[User][source]

Get all the registered users.

Returns:

The list of all the users.

Return type:

list[User]

create(email: str, name: str, role_id: int, password: str) → User[source]

Create a new user.

Parameters:
  • email (str) – The email of the user.

  • name (str) – The name of the user.

  • role_id (int) – The role ID of the user.

  • password (str) – The password of the user.

Returns:

The created user.

Return type:

User

get(user_id: str) → User[source]

Get a user by its ID.

Parameters:

user_id (str) – The ID of the user.

Returns:

The corresponding user.

Return type:

User

delete(user_id: str) → None[source]

Delete a user by its ID.

Parameters:

user_id (str) – The ID of the user.

Returns:

None

Return type:

None

update(user: User) → User[source]

Update a user.

Parameters:

user (User) – The user with its new properties.

Returns:

The updated user.

Return type:

User

get_tokens(user_id: str) → list[TokenInfo][source]

Get all the tokens of a user. The robot lists them without their secret, which it hands out once, on creation.

Parameters:

user_id (str) – The ID of the user.

Returns:

The list of all the tokens of the user.

Return type:

list[TokenInfo]

create_token(user_id: str, expires_at: datetime) → Token[source]

Create a new token for a user.

Parameters:
  • user_id (str) – The ID of the user.

  • expires_at (datetime) – The expiration date of the token, timezone-aware.

Returns:

The created token.

Raises:

DataValidationError – If expires_at carries no timezone.

Return type:

Token

update_password(user_id: str, old_password: str, new_password: str) → None[source]

Update the password of a user.

Parameters:
  • user_id (str) – The ID of the user.

  • old_password (str) – The old password of the user.

  • new_password (str) – The new password of the user.

Returns:

None

Return type:

None