Skip to content

Commit

Permalink
Fix error in getSecrets
Browse files Browse the repository at this point in the history
  • Loading branch information
giade committed Oct 4, 2023
1 parent e1ded0c commit 6bdbd14
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
3 changes: 2 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"});
});


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
24 changes: 7 additions & 17 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand All @@ -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 = {};
Expand All @@ -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 = {};

Expand All @@ -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);
}

0 comments on commit 6bdbd14

Please sign in to comment.