Update modules/database.py
Browse files- modules/database.py +11 -1
modules/database.py
CHANGED
@@ -31,6 +31,9 @@ def initialize_cosmos_sql_connection():
|
|
31 |
cosmos_endpoint = os.environ.get("COSMOS_ENDPOINT")
|
32 |
cosmos_key = os.environ.get("COSMOS_KEY")
|
33 |
|
|
|
|
|
|
|
34 |
if not cosmos_endpoint or not cosmos_key:
|
35 |
raise ValueError("Las variables de entorno COSMOS_ENDPOINT y COSMOS_KEY deben estar configuradas")
|
36 |
|
@@ -38,6 +41,7 @@ def initialize_cosmos_sql_connection():
|
|
38 |
user_database = cosmos_client.get_database_client("user_database")
|
39 |
user_container = user_database.get_container_client("users")
|
40 |
|
|
|
41 |
logger.info("Conexi贸n a Cosmos DB SQL API exitosa")
|
42 |
return True
|
43 |
except Exception as e:
|
@@ -74,8 +78,14 @@ def initialize_mongodb_connection():
|
|
74 |
|
75 |
#######################################################################################################
|
76 |
def create_user(username, password, role):
|
|
|
77 |
try:
|
78 |
print(f"Attempting to create user: {username} with role: {role}")
|
|
|
|
|
|
|
|
|
|
|
79 |
hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
|
80 |
print(f"Password hashed successfully for user: {username}")
|
81 |
user_data = {
|
@@ -88,7 +98,7 @@ def create_user(username, password, role):
|
|
88 |
print(f"Usuario {role} creado: {username}") # Log para depuraci贸n
|
89 |
return True
|
90 |
except Exception as e:
|
91 |
-
print(f"
|
92 |
return False
|
93 |
|
94 |
#######################################################################################################
|
|
|
31 |
cosmos_endpoint = os.environ.get("COSMOS_ENDPOINT")
|
32 |
cosmos_key = os.environ.get("COSMOS_KEY")
|
33 |
|
34 |
+
print(f"Cosmos Endpoint: {cosmos_endpoint}")
|
35 |
+
print(f"Cosmos Key: {'*' * len(cosmos_key) if cosmos_key else 'Not set'}")
|
36 |
+
|
37 |
if not cosmos_endpoint or not cosmos_key:
|
38 |
raise ValueError("Las variables de entorno COSMOS_ENDPOINT y COSMOS_KEY deben estar configuradas")
|
39 |
|
|
|
41 |
user_database = cosmos_client.get_database_client("user_database")
|
42 |
user_container = user_database.get_container_client("users")
|
43 |
|
44 |
+
print(f"user_container initialized: {user_container is not None}")
|
45 |
logger.info("Conexi贸n a Cosmos DB SQL API exitosa")
|
46 |
return True
|
47 |
except Exception as e:
|
|
|
78 |
|
79 |
#######################################################################################################
|
80 |
def create_user(username, password, role):
|
81 |
+
global user_container
|
82 |
try:
|
83 |
print(f"Attempting to create user: {username} with role: {role}")
|
84 |
+
if user_container is None:
|
85 |
+
print("Error: user_container is None. Attempting to reinitialize connection.")
|
86 |
+
if not initialize_cosmos_sql_connection():
|
87 |
+
raise Exception("Failed to initialize SQL connection")
|
88 |
+
|
89 |
hashed_password = bcrypt.hashpw(password.encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
|
90 |
print(f"Password hashed successfully for user: {username}")
|
91 |
user_data = {
|
|
|
98 |
print(f"Usuario {role} creado: {username}") # Log para depuraci贸n
|
99 |
return True
|
100 |
except Exception as e:
|
101 |
+
print(f"Detailed error in create_user: {str(e)}")
|
102 |
return False
|
103 |
|
104 |
#######################################################################################################
|