knot.user
The knot.user library provides user management functions.
Functions
| Function | Description |
|---|---|
list(state='', zone='') |
List all users with optional filters |
get(user_id) |
Get user by ID, username, or email |
get_me() |
Get the current user |
create(username, email, password, ...) |
Create a new user |
update(user_id, ...) |
Update user properties |
delete(user_id) |
Delete a user |
get_quota(user_id) |
Get user quota and usage |
list_permissions(user_id) |
List all permissions for a user |
has_permission(user_id, permission_id) |
Check if user has a specific permission |
Usage
import knot.user as user
# Get current user
me = user.get_me()
print(me['username'])
# List users
users = user.list()
for u in users:
print(f"{u['username']}: {u['email']}")
# Get a specific user
u = user.get("some-user-id")
print(u['username'])
# Check permissions
if user.has_permission(me['id'], 2): # MANAGE_SPACES = 2
print("User can manage spaces")
# Get quota information
quota = user.get_quota(me['id'])
print(f"Spaces: {quota['number_spaces']}/{quota['max_spaces']}")User Properties
Users contain:
id- User IDusername- Usernameemail- Email addressactive- Whether user is activemax_spaces- Maximum spaces allowedcompute_units- Compute units quotastorage_units- Storage units quotamax_tunnels- Maximum tunnels allowedpreferred_shell- Preferred shelltimezone- User timezonegithub_username- GitHub usernamenumber_spaces- Current number of spacesnumber_spaces_deployed- Number of running spacesused_compute_units- Used compute unitsused_storage_units- Used storage unitsused_tunnels- Used tunnelscurrent- Whether this is the current userroles- List of role namesgroups- List of group names
Quota Properties
get_quota() returns:
max_spaces- Maximum spaces allowedcompute_units- Compute units quotastorage_units- Storage units quotamax_tunnels- Maximum tunnels allowednumber_spaces- Current number of spacesnumber_spaces_deployed- Number of running spacesused_compute_units- Used compute unitsused_storage_units- Used storage unitsused_tunnels- Used tunnels