48 lines
1.6 KiB
JavaScript
48 lines
1.6 KiB
JavaScript
const mongoose = require('mongoose');
|
|
const dotenv = require('dotenv');
|
|
const path = require('path');
|
|
|
|
dotenv.config({ path: path.join(__dirname, '../.env') });
|
|
|
|
const Config = require('../models/Config');
|
|
const { encrypt } = require('../utils/crypto');
|
|
|
|
const PERFECT_CORP_API_KEY = 'sk-cKf0TV79X6Fp3CZwKfsnHv1Rq9GOK6nFCAXyDG9CvnIFKGYiTtSdOnjyadBaYc5y';
|
|
const PERFECT_CORP_SECRET_KEY = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCAiLqa5kyq7FR9WmK++HCPNjGLsljLfvJQq+JZzCx7pfLlVD5KzRb17iglHQJkFkSHxfqxtYNwosA54oT9uD1kA96TJy+uOLRwxry7BMPTFQyDdIoloJCI/Bl+SEnSxjDoYpU8zA3S4GDkmLH3A7vHkxhMydgB8B1EOxJahQsF7QIDAQAB';
|
|
|
|
async function seedKeys() {
|
|
try {
|
|
await mongoose.connect(process.env.MONGO_URI || 'mongodb://mongo:27017/limelite');
|
|
console.log('Connected to DB');
|
|
|
|
// 1. API KEY
|
|
const encryptedApi = encrypt(PERFECT_CORP_API_KEY);
|
|
await Config.findOneAndUpdate(
|
|
{ keyName: 'PERFECT_CORP_API_KEY' },
|
|
{ encryptedValue: encryptedApi.encryptedData, iv: encryptedApi.iv },
|
|
{ upsert: true, new: true }
|
|
);
|
|
|
|
// 2. SECRET KEY
|
|
const encryptedSecret = encrypt(PERFECT_CORP_SECRET_KEY);
|
|
await Config.findOneAndUpdate(
|
|
{ keyName: 'PERFECT_CORP_SECRET_KEY' },
|
|
{ encryptedValue: encryptedSecret.encryptedData, iv: encryptedSecret.iv },
|
|
{ upsert: true, new: true }
|
|
);
|
|
|
|
console.log('Successfully encrypted and stored Perfect Corp API keys in the database.');
|
|
} catch (error) {
|
|
console.error('Error seeding keys:', error);
|
|
}
|
|
}
|
|
|
|
module.exports = seedKeys;
|
|
|
|
if (require.main === module) {
|
|
seedKeys().then(() => {
|
|
console.log('Seeding complete. Exiting.');
|
|
process.exit(0);
|
|
});
|
|
}
|