-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_dev_user.py
More file actions
90 lines (74 loc) · 3.04 KB
/
create_dev_user.py
File metadata and controls
90 lines (74 loc) · 3.04 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
"""
Create Development User Script
Creates a default admin user for development purposes
"""
import asyncio
import sys
import os
# Add the backend directory to the Python path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'backend'))
from app.core.database import prisma
from app.core.security import get_password_hash
async def create_dev_user():
"""Create a development admin user"""
try:
await prisma.connect()
print("Connected to database")
# Check if admin role exists
admin_role = await prisma.role.find_unique(where={"name": "Administrator"})
if not admin_role:
print("Creating Administrator role...")
admin_role = await prisma.role.create(
data={
"name": "Administrator",
"description": "Full system administrator access",
"permissions": '["*"]' # All permissions
}
)
print(f"Created Administrator role: {admin_role.id}")
else:
print(f"Administrator role already exists: {admin_role.id}")
# Check if admin user exists
admin_user = await prisma.user.find_unique(where={"username": "admin"})
if not admin_user:
print("Creating admin user...")
password_hash = get_password_hash("admin")
admin_user = await prisma.user.create(
data={
"username": "admin",
"email": "[email protected]",
"passwordHash": password_hash,
"roleId": admin_role.id,
"isActive": True
}
)
print(f"Created admin user: {admin_user.id}")
print("Username: admin")
print("Password: admin")
else:
print(f"Admin user already exists: {admin_user.id}")
# Create Network Engineer role if it doesn't exist
engineer_role = await prisma.role.find_unique(where={"name": "Network Engineer"})
if not engineer_role:
print("Creating Network Engineer role...")
engineer_role = await prisma.role.create(
data={
"name": "Network Engineer",
"description": "Network configuration and monitoring access",
"permissions": '["devices.read", "devices.write", "topology.read", "configuration.read", "configuration.write"]'
}
)
print(f"Created Network Engineer role: {engineer_role.id}")
print("\n✅ Development user setup complete!")
print("You can now login with:")
print(" Username: admin")
print(" Password: admin")
except Exception as e:
print(f"❌ Error creating development user: {e}")
raise
finally:
await prisma.disconnect()
print("Disconnected from database")
if __name__ == "__main__":
asyncio.run(create_dev_user())