geronimo.cli.auth_cmd
Authentication CLI commands.
1"""Authentication CLI commands.""" 2 3import typer 4from rich.panel import Panel 5 6from geronimo.deploy_cloud.client import GeronimoCloudClient 7from geronimo.cli.utils import console, success, warning 8 9auth_app = typer.Typer( 10 name="auth", 11 help="Manage Geronimo Cloud authentication for developers.", 12 no_args_is_help=True, 13) 14 15 16@auth_app.command() 17def login( 18 token: str = typer.Option( 19 None, 20 "--token", 21 "-t", 22 help="Authentication token.", 23 prompt="Enter your Geronimo Cloud token", 24 hide_input=True, 25 ), 26) -> None: 27 """Log in to Geronimo Cloud.""" 28 client = GeronimoCloudClient() 29 30 try: 31 console.print("[blue]Verifying token...[/blue]") 32 user_data = client.login(token) 33 34 console.print( 35 Panel( 36 f"[green]✓ Successfully logged in![/green]\n\n" 37 f"User: [cyan]{user_data.get('email', 'unknown')}[/cyan]\n" 38 f"Organization: [cyan]{user_data.get('org', 'default')}[/cyan]", 39 title="Login Success", 40 border_style="green", 41 ) 42 ) 43 except Exception as e: 44 console.print(f"[bold red]Login failed:[/bold red] {e}") 45 raise typer.Exit(code=1) 46 47 48@auth_app.command() 49def logout() -> None: 50 """Log out and clear credentials.""" 51 import shutil 52 from pathlib import Path 53 54 creds_dir = Path.home() / ".geronimo" 55 if creds_dir.exists(): 56 shutil.rmtree(creds_dir) 57 success("Credentials cleared. Logged out.") 58 else: 59 warning("No credentials found. Already logged out.") 60 61 62@auth_app.command() 63def status() -> None: 64 """Check authentication status.""" 65 client = GeronimoCloudClient() 66 67 if client.token: 68 try: 69 console.print( 70 Panel( 71 "[green]✓ Authenticated[/green]\n" 72 "Token is present in credentials file.", 73 title="Auth Status", 74 border_style="green", 75 ) 76 ) 77 except Exception: 78 console.print("[red]✗ Token invalid or expired[/red]") 79 else: 80 console.print( 81 Panel( 82 "[yellow]Not authenticated[/yellow]\n" 83 "Run [cyan]geronimo auth login[/cyan] to sign in.", 84 title="Auth Status", 85 border_style="yellow", 86 ) 87 )
auth_app =
<typer.main.Typer object>
@auth_app.command()
def
login(token: str = <typer.models.OptionInfo object>) -> None:
17@auth_app.command() 18def login( 19 token: str = typer.Option( 20 None, 21 "--token", 22 "-t", 23 help="Authentication token.", 24 prompt="Enter your Geronimo Cloud token", 25 hide_input=True, 26 ), 27) -> None: 28 """Log in to Geronimo Cloud.""" 29 client = GeronimoCloudClient() 30 31 try: 32 console.print("[blue]Verifying token...[/blue]") 33 user_data = client.login(token) 34 35 console.print( 36 Panel( 37 f"[green]✓ Successfully logged in![/green]\n\n" 38 f"User: [cyan]{user_data.get('email', 'unknown')}[/cyan]\n" 39 f"Organization: [cyan]{user_data.get('org', 'default')}[/cyan]", 40 title="Login Success", 41 border_style="green", 42 ) 43 ) 44 except Exception as e: 45 console.print(f"[bold red]Login failed:[/bold red] {e}") 46 raise typer.Exit(code=1)
Log in to Geronimo Cloud.
@auth_app.command()
def
logout() -> None:
49@auth_app.command() 50def logout() -> None: 51 """Log out and clear credentials.""" 52 import shutil 53 from pathlib import Path 54 55 creds_dir = Path.home() / ".geronimo" 56 if creds_dir.exists(): 57 shutil.rmtree(creds_dir) 58 success("Credentials cleared. Logged out.") 59 else: 60 warning("No credentials found. Already logged out.")
Log out and clear credentials.
@auth_app.command()
def
status() -> None:
63@auth_app.command() 64def status() -> None: 65 """Check authentication status.""" 66 client = GeronimoCloudClient() 67 68 if client.token: 69 try: 70 console.print( 71 Panel( 72 "[green]✓ Authenticated[/green]\n" 73 "Token is present in credentials file.", 74 title="Auth Status", 75 border_style="green", 76 ) 77 ) 78 except Exception: 79 console.print("[red]✗ Token invalid or expired[/red]") 80 else: 81 console.print( 82 Panel( 83 "[yellow]Not authenticated[/yellow]\n" 84 "Run [cyan]geronimo auth login[/cyan] to sign in.", 85 title="Auth Status", 86 border_style="yellow", 87 ) 88 )
Check authentication status.