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 console = Console() query_app = typer.Typer() @query_app.command(name="tables", help="Create query to list all tables") def create_query_tables(): """Create query to list all tables""" q = """SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'public'""" console.print(f"Query: {q}", style="dim") return q @query_app.command(name="new-apikey", help="Create query to create a new API key") def create_query_new_apikey(): """Create query to create a new API key""" secret = utils.generate_secret() secret_hash = utils.hash_secret(secret) id = uuid.uuid4() q = f"""INSERT INTO api_keys (id, key, enabled, created_at, updated_at) VALUES ('{id}', '{secret_hash}', true, NOW(), NOW())""" console.print(f"Query: {q}", style="dim") key = base64.b64encode(f"{id}:{secret}".encode()).decode() console.print(f"Key: {key}", style="dim") return key