mirror of
https://github.com/johndoe6345789/docker-swarm-termina.git
synced 2026-04-25 22:25:35 +00:00
Split monolithic 631-line app.py into focused modules: **Structure:** - config.py - Configuration and shared state - utils/ - Utility functions (1-2 functions per file) - auth.py - Authentication helpers - docker_client.py - Docker client getter - exec_helpers.py - Command execution helpers - formatters.py - Data formatting utilities - terminal_helpers.py - Terminal operation helpers - diagnostics/docker_env.py - Docker diagnostics - routes/ - HTTP endpoints (1 endpoint per file) - login.py, logout.py, health.py - containers/list.py, exec.py, start.py, stop.py, restart.py, remove.py - handlers/ - WebSocket handlers (1 handler per file) - terminal/connect.py, disconnect.py, start.py, input.py, resize.py, register.py **Improvements:** - Reduced function complexity (from 21 locals to 18 max) - Fixed all pylint import order issues - Removed unused imports (select, timedelta, stat) - Applied lazy logging formatting throughout - Added comprehensive docstrings - Each file has focused responsibility - Easier to test, maintain, and extend **Pylint score improvement:** - Before: 25 problems (15 errors, 10 warnings) - After: Only duplicate code warnings (expected for similar routes) https://claude.ai/code/session_011PzvkCnVrsatoxbY3HbGXz
21 lines
598 B
Python
21 lines
598 B
Python
"""Authentication utilities."""
|
|
from flask import request, jsonify
|
|
from config import sessions
|
|
|
|
|
|
def check_auth():
|
|
"""Check if request has valid authentication.
|
|
|
|
Returns:
|
|
tuple: (is_valid, token, error_response)
|
|
"""
|
|
auth_header = request.headers.get('Authorization')
|
|
if not auth_header or not auth_header.startswith('Bearer '):
|
|
return False, None, (jsonify({'error': 'Unauthorized'}), 401)
|
|
|
|
token = auth_header.split(' ')[1]
|
|
if token not in sessions:
|
|
return False, None, (jsonify({'error': 'Invalid session'}), 401)
|
|
|
|
return True, token, None
|