Users
- class activelogic.Users
This is the resource that gives the ability to manage users on an ActiveLogic system.
- async Users.list(cls, **kwargs)
Generic list function for all kinds of data that belong to this resource. The list may or may not be cached, depending on if
cache_enabled
is set.The following data can be listed from this resource:
User: Lists all the users on the system.
UserPubKey: Lists the public keys for a given user. The below is mandatory key value argument:
user(User object or int or str): The User object or id or name of the user.
>>> us = conn.users() >>> us.list(User) [User(id=1, name='user', readbm=55, writebm=99, lviewbm=99, timeout=0, hosts=[]] >>> user_1 = us.list(User)[0] >>> us.list(UserPubKey, user=user_1) [UserPubKey(username='user', key='AAAAB3NzaC1yc2EAAAADAQABAAACAQDHPNnxH8BLNZ..')] >>> us.list(UserPubKey, user='user') [UserPubKey(username='user', key='AAAAB3NzaC1yc2EAAAADAQABAAACAQDHPNnxH8BLNZ..')]
- class activelogic.User
Object representing information about a user on an ActiveLogic system.
- Parameters:
id (int) – The ID of the user.
name (str) – The name of the user.
readbm (int) – The bitmask of read permissions of the user.
writebm (int) – The bitmask of the write permissions of the user.
lviewbm (int) – The bitmask of the liveview permissions of the user.
timeout (int) – The inactivity timeout for the user in seconds.
hosts (list) – The list of hosts the user is allowed to connect from.
Managing users
- async Users.add_user(name, password, readbm=0, writebm=0, lviewbm=0, timeout=0, hosts=None)
Adds a new user to the system.
- Parameters:
name (str) – Name of the new user.
password (str) – Password of the new user.
readbm (int) – The bitmask of the read permissions of the user.
writebm (int) – The bitmask of the write permissions of the user.
lviewbm (int) – The bitmask of the liveview permissions of the user.
timeout (int) – The inactivity timeout for the user in seconds.
hosts (list) – The list of hosts the user is allowed to connect from. Each host can be a network in CIDR format or a single IP address.
- Returns:
An object of type
User
representing the newly added user.- Return type:
object of type
User
- Raises:
PLDBError – A User with the given name already exists
ValueError – Host is in not in a valid format
>>> us.add_user("new_user", "password", readbm=999) User(id=10, name='new_user', readbm=0, writebm=0, lviewbm=0, timeout=0, hosts=[])
- async Users.update_user(user, name=None, password=None, readbm=None, writebm=None, lviewbm=None, timeout=None, hosts=None)
Update the attributes of the specified user. Omitting an argument or setting it to
None
will leave that attribute unchanged.- Parameters:
user (int or str or
User
) – The id or name or object representing the user.name (str) – The updated name of the user.
password (str) – The new password for the user.
readbm (int) – The updated bitmask for the read permissions of the user.
writebm (int) – The updated bitmask for the write permissions of the user.
lviewbm (int) – The updated bitmask for the liveview permissions of the user.
timeout (int) – The updated inactivity timeout for the user in seconds.
hosts (list) – The updated list of hosts the user is allowed to connect from. Each host can be a network in CIDR format or a single IP address.
- Returns:
An object of type
User
representing the updated user- Return type:
object of type
User
- Raises:
TypeError – The user parameter must of type int or str or an instance of
User
ValueError – The user specified does not exist on the system.
ValueError – Host is not in a valid format
>>> usr = next(u for u in us.list(User) if u.name == 'old_user') >>> us.update_user(usr, timeout=10) User(id=10, name='old_user', readbm=0, writebm=0, lviewbm=0, timeout=10, hosts=[]) >>> us.update_user(usr, name="new_user", writebm=99999) User(id=10, name='new_user', readbm=0, writebm=99999, lviewbm=0, timeout=0, hosts=[])
- async Users.remove_user(user)
Remove a user from the ActiveLogic system.
- Parameters:
user (int or str or
User
) – The id or name or object representing the user.- Raises:
>>> us.remove_user("new_user") >>> us.remove_user(10) >>> usr = next(u for u in us.list(User) if u.name == "new_user") >>> us.remove_user(usr)
- async Users.change_user_password(user, current_password, new_password)
Change a user password in ActiveLogic system.
NOTE: Always provide currently logged in user’s password in current_password.
- Parameters:
user (int or str or
User
) – The id or name or object representing the user.current_password (str) – The session user’s password.
new_password (str) – The session user or other user’s new password.
- Raises:
ValueError – The user specified does not exist on the system.
PLDBUnsupportedInFirmware – Use ‘update_user’ to change the password of a user.
>>> usr = next(u for u in us.list(User) if u.name == "session_user") >>> us.change_user_password(usr, "session_user_password", "new_password") >>> usr = next(u for u in us.list(User) if u.name == "other_user") >>> us.change_user_password(usr, "session_user_password", "other_user_new_password")
Manage user public ssh keys
- async Users.add_pub_key(user, key)
Add specified public ssh key as valid authentication method for a specific user. The key should be base64 encoded.
- Parameters:
user (str or int or
User
) – The name or id or object representing a user.key (str or
UserPubKey
) – The public ssh key to be added in base64 encoded format or UserPubKey object representing the public key.
- Raises:
TypeError – The user parameter must of type int or str or an instance of
User
ValueError – The user specified does not exist on the system
TypeError – The key must of type str or an instance of UserPubKey
>>> us.add_pub_key('admin', 'AAAAB3NzaC1yc2EAAAADAQABAAACAQDHPNnxH8BLNZVF+Zxn6Mw...')
- async Users.remove_pub_key(user, key)
Remove a specified public ssh key from the user’s public key list.
- Parameters:
user (str or int or
User
) – The name or id or object representing a user.key (str or
UserPubKey
) – The ssh key to be removed from the list of keys in base64 encoded format or the UserPubKey representing the public key.
- Raises:
TypeError – The user parameter must of type int or str or an instance of
User
ValueError – The user specified does not exist on the system
TypeError – The key must of type str or an instance of UserPubKey
>>> x = us.list(UserPubKey, user='admin')[0] >>> us.remove_pub_key('admin', x) >>> us.remove_pub_key('admin', 'AAAAB3NzaC1yc2EAAAADAQABAAACAQDHPNnxH8BLNZVF+Zxn6Mw...')
Authenticate a user
- async Users.authenticate(username, password, ip_address)
Try to authenticate a user.
The ActiveLogic system checks if the specified credentials matches a valid user. Using this api method does not affect the current user in any fashion.
- Parameters:
username (str) – The username of the user being verified.
password (str) – The password of the user being verified.
ip_address (str) – The IP address of the host to which authentication is being done.
- Returns:
A tuple of (lviewbm, readbm, writebm) of that user on successful authentication.
- Return type:
A tuple
- Raises:
PLDBError – Login Failed
>>> us.authenticate("new_user", "password", "127.0.0.1") (9223372036854775807, 9223372036854775807, 9223372036854775807)