WIP
This commit is contained in:
+31
-2
@@ -31,10 +31,40 @@ export const getEncryptionKeyForEnv = (envKey) => {
|
||||
return encryptionKey;
|
||||
};
|
||||
|
||||
export async function isFileOlder(fileA, fileB) {
|
||||
try {
|
||||
// Check if both files exist
|
||||
await fs.access(fileA);
|
||||
await fs.access(fileB);
|
||||
|
||||
// Get stats for both
|
||||
const statA = await fs.stat(fileA);
|
||||
const statB = await fs.stat(fileB);
|
||||
|
||||
// Compare modification times
|
||||
return statA.mtime > statB.mtime;
|
||||
} catch (err) {
|
||||
console.error('Error:', err.message);
|
||||
return false; // or throw err depending on use case
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const decryptFile = async (absFilePath) => {
|
||||
if (!fs.existsSync(absFilePath)) {
|
||||
logger.error(`Secret ${absFilePath} is not exist`);
|
||||
}
|
||||
const absDirPath = path.dirname(absFilePath);
|
||||
const fileName = path.basename(absFilePath).replace(".json", "");
|
||||
const decryptFileJsonPath = `${absDirPath}/~~decrypt/${fileName}.json`
|
||||
if (fs.existsSync(decryptFileJsonPath) ) {
|
||||
const isOlderThanOriginal = await isFileOlder(decryptFileJsonPath, absFilePath)
|
||||
if(isOlderThanOriginal) {
|
||||
logger.log(`decrypt file-secret for ${absFilePath} no need skip`);
|
||||
const decryptedSecretObj = await fs.readJSON(decryptFileJsonPath )
|
||||
return decryptedSecretObj
|
||||
}
|
||||
}
|
||||
logger.log(`decrypt file-secret for ${absFilePath} start`);
|
||||
|
||||
const secretFileObjRaw = await fs.readFile(absFilePath, "utf8");
|
||||
@@ -59,8 +89,7 @@ export const decryptFile = async (absFilePath) => {
|
||||
shFormatDecrypt += `export ${key}="${decryptedSecretObj[key]}"\n`;
|
||||
});
|
||||
|
||||
const absDirPath = path.dirname(absFilePath);
|
||||
const fileName = path.basename(absFilePath).replace(".json", "");
|
||||
|
||||
|
||||
if (!fs.existsSync(`${absDirPath}/~~decrypt`)) {
|
||||
fs.mkdirSync(`${absDirPath}/~~decrypt`, { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user