Spaces:
Running
Running
Config Creator
Browse files- autenticacion.py +2 -1
- config_creator.py +36 -0
- fireWhale.py +1 -1
autenticacion.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import os
|
| 2 |
import socket
|
|
|
|
| 3 |
|
| 4 |
def defineAmbiente(env):
|
| 5 |
|
|
@@ -21,7 +22,7 @@ def defineAmbiente(env):
|
|
| 21 |
print("Ambiente stripe es: ", os.getenv("ambiente_stripe"))
|
| 22 |
llave = os.getenv("STRIPE_KEY_PROD") #Acceso a HF
|
| 23 |
webhook = os.getenv("STRIPE_WEBHOOK_SECRET_PROD")
|
| 24 |
-
|
| 25 |
else: #if dev
|
| 26 |
print("Ambiente stripe es: ", os.getenv("ambiente_stripe"))
|
| 27 |
llave = os.getenv("STRIPE_KEY_SANDBOX") #Acceso a HF
|
|
|
|
| 1 |
import os
|
| 2 |
import socket
|
| 3 |
+
import config_creator
|
| 4 |
|
| 5 |
def defineAmbiente(env):
|
| 6 |
|
|
|
|
| 22 |
print("Ambiente stripe es: ", os.getenv("ambiente_stripe"))
|
| 23 |
llave = os.getenv("STRIPE_KEY_PROD") #Acceso a HF
|
| 24 |
webhook = os.getenv("STRIPE_WEBHOOK_SECRET_PROD")
|
| 25 |
+
config_creator.creaConfigFirestore()
|
| 26 |
else: #if dev
|
| 27 |
print("Ambiente stripe es: ", os.getenv("ambiente_stripe"))
|
| 28 |
llave = os.getenv("STRIPE_KEY_SANDBOX") #Acceso a HF
|
config_creator.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import json
|
| 3 |
+
|
| 4 |
+
def creaConfigFirestore():
|
| 5 |
+
|
| 6 |
+
# Paso 1: Obtener la variable de entorno
|
| 7 |
+
# El valor de os.getenv es siempre un string.
|
| 8 |
+
firestore_config_str = os.getenv('configuracion')
|
| 9 |
+
|
| 10 |
+
# Asegúrate de que la variable de entorno existe antes de continuar
|
| 11 |
+
if firestore_config_str is None:
|
| 12 |
+
print("Error: La variable de entorno 'configuracion' no está definida.")
|
| 13 |
+
else:
|
| 14 |
+
try:
|
| 15 |
+
# Paso 2: Convertir el string JSON en un diccionario de Python
|
| 16 |
+
# json.loads() es la función que hace esta conversión
|
| 17 |
+
firestore_config_dict = json.loads(firestore_config_str)
|
| 18 |
+
|
| 19 |
+
# Paso 3: Definir el nombre del archivo de salida
|
| 20 |
+
nombre_archivo = "config.json"
|
| 21 |
+
|
| 22 |
+
# Paso 4: Escribir el diccionario en un archivo JSON
|
| 23 |
+
# Usamos 'with open(...)' para asegurarnos de que el archivo se cierre correctamente
|
| 24 |
+
with open(nombre_archivo, 'w') as archivo_json:
|
| 25 |
+
# json.dump() escribe el objeto de Python en el archivo
|
| 26 |
+
# indent=4 hace que el archivo sea legible y esté bien formateado
|
| 27 |
+
json.dump(firestore_config_dict, archivo_json, indent=4)
|
| 28 |
+
|
| 29 |
+
print(f"Archivo '{nombre_archivo}' creado exitosamente.")
|
| 30 |
+
|
| 31 |
+
except json.JSONDecodeError as e:
|
| 32 |
+
# Este error ocurre si el string de la variable de entorno no es un JSON válido
|
| 33 |
+
print(f"Error: El contenido de la variable de entorno no es un JSON válido. Detalles: {e}")
|
| 34 |
+
except IOError as e:
|
| 35 |
+
# Este error maneja problemas al escribir el archivo
|
| 36 |
+
print(f"Error al escribir en el archivo: {e}")
|
fireWhale.py
CHANGED
|
@@ -5,7 +5,7 @@ from firebase_admin import firestore
|
|
| 5 |
from firebase_admin import credentials
|
| 6 |
|
| 7 |
# Use the application default credentials.
|
| 8 |
-
cred = credentials.Certificate(
|
| 9 |
firebase_admin.initialize_app(cred)
|
| 10 |
|
| 11 |
db = firestore.client()
|
|
|
|
| 5 |
from firebase_admin import credentials
|
| 6 |
|
| 7 |
# Use the application default credentials.
|
| 8 |
+
cred = credentials.Certificate('config.json')
|
| 9 |
firebase_admin.initialize_app(cred)
|
| 10 |
|
| 11 |
db = firestore.client()
|