#!/usr/bin/env python3 """ Auth0 Organizations Export Script Exports all organizations to a JSON file. """ import json import logging import subprocess from datetime import datetime from pathlib import Path from src.auth0.auth import check_auth0_login logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') logger = logging.getLogger(__name__) def get_all_orgs() -> list[dict[str, str]]: """Fetch all organizations using Auth0 CLI.""" cmd = ['auth0', 'orgs', 'list', '--json', '--number', '1000'] logger.info(f'Running: {" ".join(cmd)}') result = subprocess.run(cmd, capture_output=True, text=True, check=True) orgs: list[dict[str, str]] = json.loads(result.stdout) return orgs def main() -> Path: check_auth0_login() output_dir = Path('./data/input') output_dir.mkdir(parents=True, exist_ok=True) logger.info('Fetching organizations...') orgs = get_all_orgs() timestamp = datetime.now().strftime('%Y%m%d_%H%M%S') output_file = output_dir / f'orgs_{timestamp}.json' with open(output_file, 'w') as f: json.dump(orgs, f, indent=2) logger.info(f'✓ Exported {len(orgs)} organizations to {output_file}') return output_file if __name__ == '__main__': main()