File size: 1,448 Bytes
a477044
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"""
Quick script to check if admin rules are saved in the database
"""
import sqlite3
from pathlib import Path

db_path = Path("data/admin_rules.db")

if db_path.exists():
    print(f"✅ Database found at: {db_path}")
    print("\n" + "="*60)
    
    conn = sqlite3.connect(db_path)
    conn.row_factory = sqlite3.Row
    cursor = conn.cursor()
    
    # Get all rules
    cursor.execute("SELECT * FROM admin_rules ORDER BY created_at DESC")
    rules = cursor.fetchall()
    
    if rules:
        print(f"📋 Found {len(rules)} rule(s) in database:\n")
        for rule in rules:
            print(f"Tenant: {rule['tenant_id']}")
            print(f"Rule: {rule['rule']}")
            print(f"Pattern: {rule['pattern'] or 'N/A'}")
            print(f"Severity: {rule['severity']}")
            print(f"Enabled: {rule['enabled']}")
            print(f"Created: {rule['created_at']}")
            print("-" * 60)
    else:
        print("⚠️ No rules found in database.")
        print("   Add rules via the Gradio UI or API to populate the database.")
    
    conn.close()
else:
    print(f"❌ Database not found at: {db_path}")
    print("   The database will be created automatically when you add your first rule.")
    print("\n💡 To add rules:")
    print("   1. Open Gradio UI (python app.py)")
    print("   2. Go to 'Admin Rules & Compliance' tab")
    print("   3. Add rules in the text box and click 'Upload / Append Rules'")