This commit is contained in:
2024-11-30 17:55:00 -05:00
parent 496aa6e73c
commit 5ff6ac9251
3 changed files with 31 additions and 1 deletions
+22
View File
@@ -103,6 +103,19 @@ export const setSecretFile = async ({ absFilePath, secretKey, secretValue }) =>
logger.success(`adding secret for ${absFilePath} with Key ${secretKey.toUpperCase()} done`); logger.success(`adding secret for ${absFilePath} with Key ${secretKey.toUpperCase()} done`);
await decryptFile(absFilePath); await decryptFile(absFilePath);
}; };
export const setRawFile = async ({ absFilePath, secretKey, secretValue }) => {
if (!fs.existsSync(absFilePath)) {
logger.error(`Secret ${absFilePath} is not exist`);
}
logger.log(`adding raw secret for ${absFilePath} with Key ${secretKey.toUpperCase()} start`);
const secretFileObjRaw = await fs.readFile(absFilePath, "utf8");
const secretObj = JSON.parse(secretFileObjRaw);
secretObj[secretKey.toUpperCase()] = secretValue;
saveFileIfItChanged(JSON.stringify(secretObj, null, 4), absFilePath);
logger.success(`adding secret for ${absFilePath} with Key ${secretKey.toUpperCase()} done`);
await decryptFile(absFilePath);
};
export const commitSecretMeta = async () => { export const commitSecretMeta = async () => {
const metadataRepoFolderRelative = getJJConfigByKeyChain(`metadataRepo.path`); const metadataRepoFolderRelative = getJJConfigByKeyChain(`metadataRepo.path`);
@@ -219,6 +232,15 @@ export const secrets = async () => {
process.exit(1); process.exit(1);
} }
if (process.env.JJ_CLI_ARG_2 == "setRaw") {
await setRawFile({
absFilePath,
secretKey,
secretValue,
});
process.exit(0);
}
if (process.env.JJ_CLI_ARG_2 == "setSecret") { if (process.env.JJ_CLI_ARG_2 == "setSecret") {
await setSecretFile({ await setSecretFile({
absFilePath, absFilePath,
+8
View File
@@ -206,6 +206,14 @@ export const jjEnsure = async ({ returnProcessEnvs = false }) => {
postCommand: "", postCommand: "",
maxLength: 12, maxLength: 12,
keys: [ keys: [
{
key: "setRaw",
desc: "Set a Raw to the given file",
postCommand: " file key val",
maxLength: 50,
keys: [],
postCommandsForce: [],
},
{ {
key: "setSecret", key: "setSecret",
desc: "Set a secret to the given file", desc: "Set a secret to the given file",
+1 -1
View File
@@ -1,7 +1,7 @@
{ {
"name": "jj-command-line", "name": "jj-command-line",
"description": "jj cli", "description": "jj cli",
"version": "1.0.20", "version": "1.0.21",
"author": "Jason Jafari", "author": "Jason Jafari",
"bin": { "bin": {
"jj": "./jj.sh" "jj": "./jj.sh"