CognxSafeTrack
Claude Sonnet 4.6
refactor(worker): Sprint 2 — dead code removal and queue consolidation
37fb9ce Download scripts/db-ops/encrypt_existing_secrets.ts from safetrack/edtech: direct link, hf CLI and curl.
- Browser
- Download file 2 kB
-
https://huggingface.co/spaces/safetrack/edtech/resolve/main/scripts/db-ops/encrypt_existing_secrets.ts
- Command line
-
hf download hf://spaces/safetrack/edtech/scripts/db-ops/encrypt_existing_secrets.ts
-
curl -L -o encrypt_existing_secrets.ts https://huggingface.co/spaces/safetrack/edtech/resolve/main/scripts/db-ops/encrypt_existing_secrets.ts
2 kB
| import 'dotenv/config'; | |
| import { PrismaClient } from '@prisma/client'; | |
| import { encrypt } from '../../../packages/shared-types/src/crypto'; | |
| // ATTENTION: CE SCRIPT DOIT ÊTRE EXÉCUTÉ AVEC LA CLÉ DE PRODUCTION | |
| const prisma = new PrismaClient(); | |
| async function migrateSecrets() { | |
| const ENCRYPTION_SECRET = process.env.PROD_ENCRYPTION_SECRET || process.env.ENCRYPTION_SECRET; | |
| if (!ENCRYPTION_SECRET || ENCRYPTION_SECRET.length < 32) { | |
| console.error('❌ ERREUR: Une clé ENCRYPTION_SECRET valide de 32 caractères minimum est requise.'); | |
| process.exit(1); | |
| } | |
| console.log('🔍 Début de la migration des secrets...'); | |
| const orgs = await prisma.organization.findMany(); | |
| let updatedCount = 0; | |
| for (const org of orgs) { | |
| const dataToUpdate: any = {}; | |
| if (org.systemUserToken && !org.systemUserToken.startsWith('enc:')) { | |
| dataToUpdate.systemUserToken = encrypt(org.systemUserToken, ENCRYPTION_SECRET); | |
| } | |
| if (org.webhookSecret && !org.webhookSecret.startsWith('enc:')) { | |
| dataToUpdate.webhookSecret = encrypt(org.webhookSecret, ENCRYPTION_SECRET); | |
| } | |
| if (org.openAiApiKey && !org.openAiApiKey.startsWith('enc:')) { | |
| dataToUpdate.openAiApiKey = encrypt(org.openAiApiKey, ENCRYPTION_SECRET); | |
| } | |
| if (org.googleAiApiKey && !org.googleAiApiKey.startsWith('enc:')) { | |
| dataToUpdate.googleAiApiKey = encrypt(org.googleAiApiKey, ENCRYPTION_SECRET); | |
| } | |
| if (Object.keys(dataToUpdate).length > 0) { | |
| await prisma.organization.update({ | |
| where: { id: org.id }, | |
| data: dataToUpdate | |
| }); | |
| console.log(`✅ Organisation sécurisée : ${org.name} (${org.id})`); | |
| updatedCount++; | |
| } | |
| } | |
| console.log(`\n🎉 Migration terminée. ${updatedCount} organisation(s) mise(s) à jour.`); | |
| await prisma.$disconnect(); | |
| } | |
| migrateSecrets().catch(console.error); | |