sheets: soporta GOOGLE_CREDENTIALS_FILE (archivo montado)
La UI de env vars de Coolify (beta.463) limita valores a varchar(255) y el JSON de la service account (~2.4KB) no cabe. Nuevo camino: montar el JSON como archivo y apuntar GOOGLE_CREDENTIALS_FILE al path. GOOGLE_CREDENTIALS_JSON inline sigue teniendo prioridad si existe.
This commit is contained in:
1 parent
0d66d27589
commit
c5668ef879
1 file changed
+15
-1
+15
-1
@@ -102,9 +102,23 @@ def _get_client() -> gspread.Client | None:
|
||||
global _gc
|
||||
if _gc is not None:
|
||||
return _gc
|
||||
# Credenciales: env var inline o archivo montado. El archivo existe
|
||||
# porque la UI de env vars de Coolify trunca valores >255 chars y el
|
||||
# JSON de una service account no cabe.
|
||||
creds_json = os.getenv("GOOGLE_CREDENTIALS_JSON")
|
||||
if not creds_json:
|
||||
logger.warning("GOOGLE_CREDENTIALS_JSON no configurado")
|
||||
ruta = os.getenv("GOOGLE_CREDENTIALS_FILE")
|
||||
if ruta:
|
||||
try:
|
||||
with open(ruta, encoding="utf-8") as f:
|
||||
creds_json = f.read()
|
||||
except OSError:
|
||||
logger.exception("No pude leer GOOGLE_CREDENTIALS_FILE=%s", ruta)
|
||||
return None
|
||||
if not creds_json:
|
||||
logger.warning(
|
||||
"Ni GOOGLE_CREDENTIALS_JSON ni GOOGLE_CREDENTIALS_FILE configurados"
|
||||
)
|
||||
return None
|
||||
creds_dict = json.loads(creds_json)
|
||||
_gc = gspread.service_account_from_dict(creds_dict)
|
||||
|
||||
Reference in new issue
Block a user