sheets: GOOGLE_CREDENTIALS_B64 · sobrevive la inyección ARG de Coolify
Coolify inyecta las env vars como ARG en el Dockerfile al buildear. Un JSON crudo (espacios, comillas, \n del private_key) rompe el parse: "unexpected end of statement while looking for matching double-quote". Base64 es un token único [A-Za-z0-9+/=] — indestructible como ARG. Prioridad: B64 > JSON crudo > FILE. Los tres caminos conviven.
This commit is contained in:
1 parent
c5668ef879
commit
130140aac8
1 file changed
+19
-5
+19
-5
@@ -102,10 +102,24 @@ 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")
|
||||
# Credenciales, tres caminos en orden de prioridad:
|
||||
# 1. GOOGLE_CREDENTIALS_B64 — JSON en base64. El camino recomendado
|
||||
# con Coolify: sus env vars se inyectan como ARG en el Dockerfile
|
||||
# y un JSON crudo (espacios/comillas/\n) rompe el build. Base64
|
||||
# es un token único y sobrevive cualquier inyección.
|
||||
# 2. GOOGLE_CREDENTIALS_JSON — JSON crudo inline (deploys sin ARG).
|
||||
# 3. GOOGLE_CREDENTIALS_FILE — path a archivo montado.
|
||||
creds_json: str | None = None
|
||||
creds_b64 = os.getenv("GOOGLE_CREDENTIALS_B64")
|
||||
if creds_b64:
|
||||
import base64
|
||||
try:
|
||||
creds_json = base64.b64decode(creds_b64).decode("utf-8")
|
||||
except Exception:
|
||||
logger.exception("GOOGLE_CREDENTIALS_B64 no es base64 válido")
|
||||
return None
|
||||
if not creds_json:
|
||||
creds_json = os.getenv("GOOGLE_CREDENTIALS_JSON")
|
||||
if not creds_json:
|
||||
ruta = os.getenv("GOOGLE_CREDENTIALS_FILE")
|
||||
if ruta:
|
||||
@@ -117,7 +131,7 @@ def _get_client() -> gspread.Client | None:
|
||||
return None
|
||||
if not creds_json:
|
||||
logger.warning(
|
||||
"Ni GOOGLE_CREDENTIALS_JSON ni GOOGLE_CREDENTIALS_FILE configurados"
|
||||
"Configura GOOGLE_CREDENTIALS_B64, _JSON o _FILE — ninguno presente"
|
||||
)
|
||||
return None
|
||||
creds_dict = json.loads(creds_json)
|
||||
|
||||
Reference in new issue
Block a user