WIP
This commit is contained in:
+31
-2
@@ -31,10 +31,40 @@ export const getEncryptionKeyForEnv = (envKey) => {
|
|||||||
return encryptionKey;
|
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) => {
|
export const decryptFile = async (absFilePath) => {
|
||||||
if (!fs.existsSync(absFilePath)) {
|
if (!fs.existsSync(absFilePath)) {
|
||||||
logger.error(`Secret ${absFilePath} is not exist`);
|
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`);
|
logger.log(`decrypt file-secret for ${absFilePath} start`);
|
||||||
|
|
||||||
const secretFileObjRaw = await fs.readFile(absFilePath, "utf8");
|
const secretFileObjRaw = await fs.readFile(absFilePath, "utf8");
|
||||||
@@ -59,8 +89,7 @@ export const decryptFile = async (absFilePath) => {
|
|||||||
shFormatDecrypt += `export ${key}="${decryptedSecretObj[key]}"\n`;
|
shFormatDecrypt += `export ${key}="${decryptedSecretObj[key]}"\n`;
|
||||||
});
|
});
|
||||||
|
|
||||||
const absDirPath = path.dirname(absFilePath);
|
|
||||||
const fileName = path.basename(absFilePath).replace(".json", "");
|
|
||||||
|
|
||||||
if (!fs.existsSync(`${absDirPath}/~~decrypt`)) {
|
if (!fs.existsSync(`${absDirPath}/~~decrypt`)) {
|
||||||
fs.mkdirSync(`${absDirPath}/~~decrypt`, { recursive: true });
|
fs.mkdirSync(`${absDirPath}/~~decrypt`, { recursive: true });
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "jj-command-line",
|
"name": "jj-command-line",
|
||||||
"description": "jj cli",
|
"description": "jj cli",
|
||||||
"version": "1.0.28",
|
"version": "1.0.29",
|
||||||
"author": "Jason Jafari",
|
"author": "Jason Jafari",
|
||||||
"bin": {
|
"bin": {
|
||||||
"jj": "./jj.sh"
|
"jj": "./jj.sh"
|
||||||
|
|||||||
Reference in New Issue
Block a user