#!/usr/bin/env python3 """ Temporary patch to disable authentication for testing """ import os import sys from pathlib import Path def patch_auth_function(): """Temporarily patch the auth_required function to always return False""" auth_file = Path("core/security/api_tokens.py") if not auth_file.exists(): print(f"File not found: {auth_file}") return False # Read the current content with open(auth_file, 'r') as f: content = f.read() # Create backup backup_file = auth_file.with_suffix('.py.backup') with open(backup_file, 'w') as f: f.write(content) print(f"Backup created: {backup_file}") # Simple replacement - just make auth_required always return False if "def auth_required() -> bool:" in content: # Find the function and replace its body lines = content.split('\n') new_lines = [] in_auth_function = False indent_level = 0 for line in lines: if "def auth_required() -> bool:" in line: in_auth_function = True indent_level = len(line) - len(line.lstrip()) new_lines.append(line) # Add the docstring and simple return new_lines.append(' ' * (indent_level + 4) + '"""Auth temporarily disabled for testing"""') new_lines.append(' ' * (indent_level + 4) + 'print("AUTH DISABLED FOR TESTING")') new_lines.append(' ' * (indent_level + 4) + 'return False') elif in_auth_function: # Skip lines until we reach the next function or class if line.strip() and not line.startswith(' ' * (indent_level + 1)) and not line.startswith('#'): in_auth_function = False new_lines.append(line) # Skip the original function body else: new_lines.append(line) new_content = '\n'.join(new_lines) with open(auth_file, 'w') as f: f.write(new_content) print("Authentication temporarily disabled") return True else: print("Could not find auth_required function") return False if __name__ == "__main__": patch_auth_function()