#!/usr/bin/env python3 """ Create initial API key for GasFlux """ import sys from pathlib import Path # Add src to path src_dir = Path(__file__).parent / "src" sys.path.insert(0, str(src_dir)) from gasflux.config_reader import config_reader def main(): print("GasFlux API Key Creator") print("=" * 30) # Check if bootstrap key is configured bootstrap_key = config_reader.admin_bootstrap_key if not bootstrap_key: print("ERROR: No admin_bootstrap_key configured in gasflux.ini") print("Please set [security] admin_bootstrap_key in gasflux.ini first") return print(f"Bootstrap key configured: {'Yes' if bootstrap_key else 'No'}") # Get key details description = input("Enter API key description (default: 'Default API Key'): ").strip() if not description: description = "Default API Key" scopes = input("Enter API key scopes (default: '*'): ").strip() if not scopes: scopes = "*" try: from gasflux.app import app from gasflux.auth import create_api_key with app.app_context(): key_id, plain_key = create_api_key(description=description, scopes=scopes) print("\n✅ API Key Created Successfully!") print("=" * 30) print(f"Key ID: {key_id}") print(f"Key: {plain_key}") print(f"Description: {description}") print(f"Scopes: {scopes}") print("\n⚠️ IMPORTANT: Save this key securely!") print(" This key will only be shown once.") print("\nTo use this key in API requests:") print(f" curl -H 'X-API-Key: {plain_key}' http://localhost:5000/upload") print("\nOr set it as an environment variable:") print(f" export GASFLUX_API_KEY={plain_key}") except Exception as e: print(f"ERROR: Failed to create API key: {e}") import traceback traceback.print_exc() if __name__ == "__main__": main()