@unito/integration-cli
Version:
Integration CLI
43 lines (42 loc) • 1.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.decryptEntries = decryptEntries;
const tslib_1 = require("tslib");
const errors_1 = require("../errors");
const GlobalConfiguration = tslib_1.__importStar(require("./globalConfiguration"));
const integrationsPlatform_1 = require("./integrationsPlatform");
const configuration_1 = require("./configuration");
const integrationsPlatform_2 = require("../services/integrationsPlatform");
async function decryptEntries(configurationName, environment, configDir, entries) {
if (!Object.keys(entries).length) {
return { successful: entries, failed: [] };
}
const toDecrypt = {};
const toKeepAsIs = {};
for (const [key, value] of Object.entries(entries)) {
if (typeof value === 'string' && value.startsWith(configuration_1.ENCRYPTION_PREFIX)) {
toDecrypt[key] = value;
}
else {
toKeepAsIs[key] = value;
}
}
const globalConfiguration = await GlobalConfiguration.read(configDir);
try {
await (0, integrationsPlatform_1.validateAuthenticated)(globalConfiguration, environment);
}
catch {
throw new errors_1.DecryptionAuthenticationError();
}
const decrypted = {};
const failed = [];
for (const [key, encryptedValue] of Object.entries(toDecrypt)) {
try {
decrypted[key] = (await (0, integrationsPlatform_2.decryptData)(configurationName, encryptedValue)).decryptedData;
}
catch {
failed.push(key);
}
}
return { successful: { ...toKeepAsIs, ...decrypted }, failed };
}