panels-origin/api/scripts/verify-storage.ts
Cursor Agent 1ac04996b6
ops: generar accesos por ambiente y verificar Postgres, Redis y Contabo
Scripts create-accesses / verify-connectivity para un Postgres+Redis+bucket
por ambiente. /v1/health y el arranque de la API incluyen sonda de storage.

Co-authored-by: alberto.martinez <alberto.martinez@mrdev.mx>
2026-09-02 21:22:39 +00:00

35 lines
1.3 KiB
TypeScript

/**
* Sonda de Contabo (S3): HeadBucket + put/get/delete.
*
* Desde api/:
* deno run --allow-net --allow-env --allow-read --allow-write scripts/verify-storage.ts
*
* Requiere S3_ENDPOINT, S3_BUCKET, S3_ACCESS_KEY_ID, S3_SECRET_ACCESS_KEY.
* Si REQUIRE_S3=1 y no hay credenciales, sale con error (staging/prod).
* Si no están, sale 0 y avisa (dev local con disco).
*/
import { config } from "../config.ts";
import { pingStorage, probeStorageReadWrite, s3Configured } from "../storage.ts";
const requireS3 = ["1", "true", "yes"].includes((Deno.env.get("REQUIRE_S3") ?? "").toLowerCase());
if (!s3Configured()) {
const msg =
"S3 no configurado (S3_ENDPOINT / S3_BUCKET / S3_ACCESS_KEY_ID / S3_SECRET_ACCESS_KEY).";
if (requireS3) {
console.error(`FAIL - ${msg} Obligatorio en staging/producción.`);
Deno.exit(1);
}
console.log(`SKIP - ${msg} En este ambiente se usará disco local.`);
Deno.exit(0);
}
console.log(`S3 endpoint=${config.s3Endpoint} bucket=${config.s3Bucket} region=${config.s3Region}`);
const ping = await pingStorage();
if (!ping.ok) {
console.error("FAIL - HeadBucket: no se pudo alcanzar el bucket (credenciales, red o nombre).");
Deno.exit(1);
}
console.log("OK - HeadBucket");
await probeStorageReadWrite();
console.log("OK - put/get/delete de objeto sonda");