import typer from typing import Optional from rich.console import Console from rich.table import Table from rich.prompt import Prompt import os import json import uuid import base64 import secnex.utils as utils from secnex.kit.config.config import Config from secnex.kit.clients.user import UserClient console = Console() user_app = typer.Typer() @user_app.command(name="ls", help="List all users") def ls(): """List all users""" config = Config("default") user_client = UserClient(config) users = user_client.get_all() count_users = len(users) console.print(f"Found {count_users} users") if count_users == 0: return table = Table(title="Users") table.add_column("ID", style="bold green") table.add_column("First Name", style="bold yellow") table.add_column("Last Name", style="bold purple") table.add_column("Email", style="bold blue") table.add_column("Tenant ID", style="bold red") for u in users: table.add_row(u.id, u.first_name, u.last_name, u.email, u.tenant_id) console.print(table) @user_app.command(name="tenant", help="Set the tenant for a user") def set_tenant(id: Optional[str] = typer.Option(None, "--id", "-i", help="The ID of the user"), tenant: Optional[str] = typer.Option(None, "--tenant", "-t", help="The tenant to set for the user")): """Set the tenant for a user""" if id is None: id = Prompt.ask("Enter the ID of the user") if tenant is None: tenant = Prompt.ask("Enter the ID of the tenant to set for the user") config = Config("default") user_client = UserClient(config) success, status_code = user_client.add_user_to_tenant(tenant, id) if not success: console.print(f"Failed to set tenant for user! Please check the logs for more information.", style="bold red") return console.print(f"Tenant set for user successfully!", style="bold green")