39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import typer
|
|
from typing import Optional
|
|
|
|
from rich.console import Console
|
|
from rich.table import Table
|
|
from rich.prompt import Prompt
|
|
|
|
from secnex.kit.auth.auth import Auth
|
|
from secnex.kit.config.config import Config
|
|
|
|
console = Console()
|
|
|
|
auth_app = typer.Typer()
|
|
|
|
@auth_app.command(name="login", help="Login to the SecNex API")
|
|
def login():
|
|
"""Login to the SecNex API"""
|
|
config = Config("default")
|
|
auth = Auth(config)
|
|
auth.login()
|
|
|
|
@auth_app.command(name="logout", help="Logout from the SecNex API")
|
|
def logout():
|
|
"""Logout from the SecNex API"""
|
|
config = Config("default")
|
|
auth = Auth(config)
|
|
auth.delete_token()
|
|
console.print(f"Logged out successfully!", style="bold green")
|
|
|
|
@auth_app.command(name="status", help="Check if user is already logged in")
|
|
def status():
|
|
"""Check if user is already logged in"""
|
|
config = Config("default")
|
|
auth = Auth(config)
|
|
token = auth.get_token()
|
|
if token is not None:
|
|
console.print(f"User is logged in!", style="bold green")
|
|
else:
|
|
console.print(f"User is not logged in!", style="bold red") |