Files
wehub-resource-sync 7a0da7932b
OSV-Scanner (Scheduled) / scan-scheduled (push) Failing after 0s
Create Release / test-gate (push) Has been cancelled
Create Release / release-gate (push) Has been cancelled
Create Release / ci-gate (push) Has been cancelled
Create Release / version-check (push) Has been cancelled
Create Release / e2e-test-gate (push) Has been cancelled
Create Release / responsive-test-gate (push) Has been cancelled
Create Release / compat-test-gate (push) Has been cancelled
Create Release / compose-integration-gate (push) Has been cancelled
Create Release / vulture-gate (push) Has been cancelled
Create Release / build (push) Has been cancelled
Create Release / provenance (push) Has been cancelled
Create Release / prerelease-docker (push) Has been cancelled
Create Release / publish-docker (push) Has been cancelled
Create Release / create-release (push) Has been cancelled
Create Release / cleanup-changelog (push) Has been cancelled
Create Release / trigger-pypi (push) Has been cancelled
Create Release / monitor-pypi (push) Has been cancelled
Create Release / Clean up orphan prerelease tags and signatures (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-form] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-metrics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [research-workflow] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-core] (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [history-news] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [library] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [link-analytics] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-core] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [chat-lifecycle] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [error-benchmark] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [settings-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) (push) Has been cancelled
Docker Tests (Consolidated) / Accessibility Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Unit Tests (push) Has been cancelled
Docker Tests (Consolidated) / LLM Example Tests (push) Has been cancelled
Docker Tests (Consolidated) / Production Image Smoke Test (push) Has been cancelled
Docker Tests (Consolidated) / Infrastructure Tests (push) Has been cancelled
OSSF Scorecard / OSSF Security Scorecard Analysis (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [mobile] (push) Has been cancelled
Backwards Compatibility / Verify Encryption Constants (push) Has been cancelled
Backwards Compatibility / PyPI Version Compatibility (push) Has been cancelled
Backwards Compatibility / Database Migration Tests (push) Has been cancelled
CodeQL Advanced / Analyze (python) (push) Has been cancelled
Docker Tests (Consolidated) / detect-changes (push) Has been cancelled
Docker Tests (Consolidated) / Build Test Image (push) Has been cancelled
Docker Tests (Consolidated) / All Pytest Tests + Coverage (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [accessibility] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [api-crud] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-login] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-pages] (push) Has been cancelled
Docker Tests (Consolidated) / UI Tests (Puppeteer) [auth-register] (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:08:55 +08:00

94 lines
2.7 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Pre-commit hook to prevent usage of ldr.db (shared database).
All data should be stored in per-user encrypted databases.
"""
import sys
import re
import os
from pathlib import Path
# Set environment variable for pre-commit hooks to allow unencrypted databases
os.environ["LDR_ALLOW_UNENCRYPTED"] = "true"
def check_file_for_ldr_db(file_path):
"""Check if a file contains references to ldr.db."""
try:
with open(file_path, "r", encoding="utf-8") as f:
content = f.read()
except (UnicodeDecodeError, IOError):
# Skip binary files or files we can't read
return []
# Pattern to find ldr.db references
pattern = r"ldr\.db"
matches = []
for line_num, line in enumerate(content.splitlines(), 1):
if re.search(pattern, line, re.IGNORECASE):
# Skip comments and documentation
stripped = line.strip()
if not (
stripped.startswith("#")
or stripped.startswith("//")
or stripped.startswith("*")
or stripped.startswith('"""')
or stripped.startswith("'''")
):
matches.append((line_num, line.strip()))
return matches
def main():
"""Main function to check all Python files for ldr.db usage."""
# Get all Python files from command line arguments
files_to_check = sys.argv[1:] if len(sys.argv) > 1 else []
if not files_to_check:
# If no files specified, check all Python files
src_dir = Path(__file__).parent.parent / "src"
files_to_check = list(src_dir.rglob("*.py"))
violations = []
for file_path in files_to_check:
file_path = Path(file_path)
# Only skip this hook file itself
if file_path.name == "check-ldr-db.py":
continue
matches = check_file_for_ldr_db(file_path)
if matches:
violations.append((file_path, matches))
if violations:
print("❌ DEPRECATED ldr.db USAGE DETECTED!")
print("=" * 60)
print("The shared ldr.db database is deprecated.")
print("All data must be stored in per-user encrypted databases.")
print("=" * 60)
for file_path, matches in violations:
print(f"\n📄 {file_path}")
for line_num, line in matches:
print(f" Line {line_num}: {line}")
print("\n" + "=" * 60)
print("MIGRATION REQUIRED:")
print("1. Store user-specific data in encrypted per-user databases")
print("2. Use get_user_db_session() instead of shared database access")
print("3. See migration guide in documentation")
print("=" * 60)
return 1
return 0
if __name__ == "__main__":
sys.exit(main())