Users¶
- class pyniryo_nate.components.Users(http_client: HttpClient, mqtt_client: MqttClient, correlation_id: str)[source]¶
Bases:
BaseAPIComponentUsers component for managing user accounts.
This component provides methods for: - Creating, retrieving, updating, and deleting users - Managing user tokens - Updating user passwords
Methods
closeClose the component and release any resources if needed.
Create a new user.
Create a new token for a user.
Delete a user by its ID.
Get a user by its ID.
Get all the registered users.
Get all the tokens of a user.
Update a user.
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:
- 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:
- 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
- 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_atcarries no timezone.- Return type: