isp-maintenance/mgrctl/apps/vm6/auth/commands.py

32 lines
826 B
Python
Raw Normal View History

import click
from mgrctl.db.vm6.databases import isp_database
from mgrctl.db.vm6.models import AuthUser
from mgrctl.apps.vm6.auth import __version__
@click.group(help='auth cmd for auth in VMmanager 6')
@click.version_option(
version=__version__,
package_name='mgrctl.apps.vm6.auth',
message=__version__
)
def cli():
pass
@cli.command(help='show all users and their roles on platform (DEMO EXAMPLE)')
def users():
# check and init connection to db:
isp_database.connect()
# get all fields from auth_user table
# SELECT * FROM auth_user;
all_users = AuthUser.select()
# Iterate fields and print to console users' email and role
for user in all_users:
result = f'{user.email} | {user.roles[0]}'
click.echo(result)
# Close connection
isp_database.close()