How to manage users

> See also: juju:user

Add a user

To add a user to a controller, on a connected Controller object, use the add_user() method.

await my_controller.add_user("alex")

> See more: add_user()

List all the known users

To view a list of all the users known (i.e., allowed to log in) to a controller, on a connected Controller object, use the get_users() method.

await my_controller.get_users()

> See more: get_users()

View details about a user

To view details about a specific user, on a connected Controller, use the get_user() method to retrieve a User object that encapsulates everything about that user. Using that object, you can access all the details (via the object properties) for that user.

user_object = await my_controller.get_user("alice")
# Then we can access all the properties to view details
print(user_object.display_name)
print(user_object.access)
print(user_object.date_created)
print(user_object.last_connection)

> See more: get_user(), User (module)

View details about the current user

To see details about the current user, on a connected Controller, use the get_current_user() method to retrieve a User object that encapsulates everything about the current user. Using that object, you can access all the details (via the object properties) for that user.

user_object = await my_controller.get_current_user()
# Then we can access all the properties to view details
print(user_object.display_name)
print(user_object.access)
print(user_object.date_created)
print(user_object.last_connection)

> See more: get_current_user(), User (module)

Manage a user’s access level

> See also: juju:user-access-levels

To manage a user’s access to a controller, a model, or an offer, on a User object, use the grant() and revoke() methods to grant or revoke a certain access level to a user.

# grant a superuser access to the controller (that the user is on)
await user_object.grant('superuser')

# grant user the access to see a model
await user_object.grant("read", model_name="test-model")

# revoke ‘read’ (and ‘write’) access from user for application offer ‘fred/prod.hosted-mysql’:
await user_object.revoke("read", offer_url="fred/prod.hosted-mysql")

> See more: grant(), revoke(), User (module)

Manager a user’s login details

To set or change a user’s password, on a User object, use the set_password() method.

await user_object.set_password('123')

> See more: set_password(), User (module)

Manage a user’s enabled status

To enable or disable a user, on a User object, use the enable() and disable() methods.

await user_object.enable()

await user_object.disable()

You can also check if a user is enabled or disabled using the enabled and disabled properties on the User object.

# re-enable a disabled user
if user_object.disabled:
    await user_object.enable()

> See more: enable(), disable(), User (module)

Remove a user

To remove a user, on a connected Controller object, use the remove_user() method.

await my_controller.remove_user("bob")

> See more: remove_user(), User (module)