Fix Demo enterprise
This commit is contained in:
90
scripts/generate_child_auth_files.py
Executable file
90
scripts/generate_child_auth_files.py
Executable file
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Generate Child Auth Files Script
|
||||
|
||||
Creates auth.json files for each child tenant with appropriate users.
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
from datetime import datetime, timedelta
|
||||
import uuid
|
||||
|
||||
def generate_child_auth_file(tenant_id: str, tenant_name: str, parent_tenant_id: str) -> dict:
|
||||
"""Generate auth.json data for a child tenant"""
|
||||
|
||||
# Generate user IDs based on tenant ID
|
||||
manager_id = str(uuid.uuid5(uuid.NAMESPACE_DNS, f"manager-{tenant_id}"))
|
||||
staff_id = str(uuid.uuid5(uuid.NAMESPACE_DNS, f"staff-{tenant_id}"))
|
||||
|
||||
# Create users
|
||||
users = [
|
||||
{
|
||||
"id": manager_id,
|
||||
"tenant_id": tenant_id,
|
||||
"name": f"Gerente {tenant_name}",
|
||||
"email": f"gerente.{tenant_id.lower()}@panaderiaartesana.es",
|
||||
"role": "manager",
|
||||
"is_active": True,
|
||||
"created_at": "BASE_TS - 180d",
|
||||
"updated_at": "BASE_TS - 180d"
|
||||
},
|
||||
{
|
||||
"id": staff_id,
|
||||
"tenant_id": tenant_id,
|
||||
"name": f"Empleado {tenant_name}",
|
||||
"email": f"empleado.{tenant_id.lower()}@panaderiaartesana.es",
|
||||
"role": "user",
|
||||
"is_active": True,
|
||||
"created_at": "BASE_TS - 150d",
|
||||
"updated_at": "BASE_TS - 150d"
|
||||
}
|
||||
]
|
||||
|
||||
return {"users": users}
|
||||
|
||||
def main():
|
||||
"""Main function to generate auth files for all child tenants"""
|
||||
print("=== Generating Child Auth Files ===")
|
||||
|
||||
base_path = Path("shared/demo/fixtures/enterprise")
|
||||
children_dir = base_path / "children"
|
||||
|
||||
# Get parent tenant info
|
||||
parent_tenant_file = base_path / "parent" / "01-tenant.json"
|
||||
with open(parent_tenant_file, 'r', encoding='utf-8') as f:
|
||||
parent_data = json.load(f)
|
||||
|
||||
parent_tenant_id = parent_data["tenant"]["id"]
|
||||
|
||||
# Process each child directory
|
||||
for child_dir in children_dir.iterdir():
|
||||
if child_dir.is_dir():
|
||||
tenant_id = child_dir.name
|
||||
|
||||
# Get tenant info from child's tenant.json
|
||||
child_tenant_file = child_dir / "01-tenant.json"
|
||||
if child_tenant_file.exists():
|
||||
with open(child_tenant_file, 'r', encoding='utf-8') as f:
|
||||
tenant_data = json.load(f)
|
||||
|
||||
# Child files have location data, not tenant data
|
||||
tenant_name = tenant_data["location"]["name"]
|
||||
|
||||
# Generate auth data
|
||||
auth_data = generate_child_auth_file(tenant_id, tenant_name, parent_tenant_id)
|
||||
|
||||
# Write auth.json file
|
||||
auth_file = child_dir / "02-auth.json"
|
||||
with open(auth_file, 'w', encoding='utf-8') as f:
|
||||
json.dump(auth_data, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print(f"✓ Generated {auth_file}")
|
||||
else:
|
||||
print(f"✗ Missing tenant.json in {child_dir}")
|
||||
|
||||
print("\n=== Auth File Generation Complete ===")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user