From 6bdbd148c477ecec05ba3e16a69a2abbf25675b5 Mon Sep 17 00:00:00 2001 From: Giada Date: Wed, 4 Oct 2023 17:45:22 +0200 Subject: [PATCH] Fix error in getSecrets --- bin/cli.js | 3 ++- package.json | 2 +- src/index.js | 24 +++++++----------------- 3 files changed, 10 insertions(+), 19 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 0017688..5033f4f 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -58,9 +58,10 @@ program .option('-g, --groupKey [groupKey]', 'The name of the group') .option('-s, --secretKey [secretKey]', 'Secret token for the group name') .option('-na, --name [name]', 'Name of the secret') + .option('-e', '--env [env]', 'Env of the secret') .option('-nt, --note [note]', 'Note of the secret') .action((options) => { - updateNoteSecret({ groupKey: options.groupKey || "", groupSecret: options.secretKey || "", name: options.name, note: options.note}); + updateNoteSecret({ groupKey: options.groupKey || "", groupSecret: options.secretKey || "", name: options.name, note: options.note, env: options.env || "site"}); }); diff --git a/package.json b/package.json index 53de732..6dbf3d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jumpgroup/secret-fetcher", - "version": "1.6.1", + "version": "1.6.2", "author": "JumpGroup srl", "main": "src/index.js", "license": "MIT", diff --git a/src/index.js b/src/index.js index 8127b51..0d4928c 100755 --- a/src/index.js +++ b/src/index.js @@ -332,11 +332,11 @@ export const getSecrets = async (options) => { var result = []; - if (options.name) { + if (options.env) { //filter the variables by name Object.keys(mergedVariables).forEach(key => { - if (key === options.name) { + if (key === options.env) { //push object with key result[key] = mergedVariables[key]; } @@ -355,20 +355,14 @@ export const updateNoteSecret = async (options) => { console.log("Updating note of secret..."); - if (!options.name) { - throw new Error("Name is required"); - } - if (!options.note) { throw new Error("Note is required"); } if(!options.env){ - options.env = options.name.split(":")[1]; - console.log(options.env); + options.env = "site"; } - console.log(options.note); console.log("Checking if Note is a valid yaml"); var newNote = {}; @@ -386,12 +380,13 @@ export const updateNoteSecret = async (options) => { console.log("Get note of secret from Passwd"); const noteOfSecret = await getSecrets(options); - if (noteOfSecret.length == 0) { + //check if noteOfSecret is empty + if (noteOfSecret == []) { throw new Error("Secret not found"); } //object to string - const noteOfSecretString = JSON.stringify(noteOfSecret[options.name]); + const noteOfSecretString = JSON.stringify(noteOfSecret[options.env]); var itemProperties = {}; @@ -409,14 +404,9 @@ export const updateNoteSecret = async (options) => { ...newNote }; - console.log(mergedNote); - console.log("Updating note of secret..."); - const note = yaml.dump(mergedNote); - - console.log(note); + options.note = yaml.dump(mergedNote); console.log("Adding secret to Passwd") - console.log(options.groupKey, options.groupSecret, note, options.env); await addUpdateSecret(options); }