Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue234 Import all keys from specific path #238

Closed
wants to merge 7 commits into from

Conversation

slemme1
Copy link
Contributor

@slemme1 slemme1 commented Jul 28, 2021

I am a first time contributor. Any constructive feedback is appreciated.

@hashicorp-cla
Copy link

hashicorp-cla commented Jul 28, 2021

CLA assistant check
All committers have signed the CLA.

@slemme1
Copy link
Contributor Author

slemme1 commented Oct 11, 2021

Am I supposed to close this pull request?

@bfaulk96
Copy link

This would be really useful.

@silvan02
Copy link

silvan02 commented Mar 8, 2022

This is exactly what we need for our project. We current have to create our own action to do this, Any change this would be merge soon?

@ltcarbonell
Copy link
Contributor

Good work here. This appears to be very similar to #247. Is there anything different here from that PR (other than a slightly different approach?). If not I think it would be best to close this PR and continue the conversation there.

Copy link
Contributor

@maxcoulombe maxcoulombe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @slemme1! Thanks for taking a jab at this. The change looks good overall, my comment are mostly around styling and some leftovers changes from development we might not want to bring back into main.

I tested the modifications locally and the feature & tests (thanks for taking the time to add acceptance tests btw) work like a charm (with the small fix proposed of awaiting the response from selectData).

I know there are other PRs opened to address this wildcard support request such as #247 & #398. I'm inclined to accept yours over the others. It is more complete, uses a simpler approach, has more test coverage and I like the option you added of regrouping all the keys under a shared prefix if desired.

Let me know if you need anything from us to get this updated and ready to ship!

}
return outputKey;
}
module.exports.normalizeOutputKey = normalizeOutputKey;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it causes circular dependency problems, it'd be better to move the normalizeOutputKey method into it's own normalization.js or utils.js file so it can be imported and used by both secrets.js & actions.js.

It's usually better to rethink how a project is compartmentalised rather than hack the exports.

};
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we go ahead and move the normalization method in its own file well be able to keep this unique export block which I think is more "standard" than exporting methods one at a time throughout the file.

if (!selector.match(/.*[\.].*/)) {
selector = '"' + selector + '"'

if (selector == wildcard) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe strict equality with === should be used unless there is a specific reason not to.

//console.log("After", newRequest, value);

// used cachedResponse for first entry in wildcard list and set to true for the rest
cachedResponse = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think setting this to true does anything here? It gets reset to false at the beginning of every loops before we check for a cache hit.

});

//DEBUG
//console.log("After", newRequest, value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try not to leave leftover debug code or console.logs even if commented out.


selector = key;

//This code (with exception of parsing body again and using newRequest instead of secretRequest) should match the else code for a single key
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to isolate the shared code in a method instead of hoping maintainers see this comment and think to copy-paste changes between the wildcard and single-key paths?

selector = '"' + selector + '"'
}
selector = "data." + selector
//body = JSON.parse(body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover comment, should it be deleted or it's important?

if (body.data["data"] != undefined) {
selector = "data." + selector
}
const value = selectData(body, selector);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selectData was changed to be async due to the recent bump to Jsonata 2.x, you'll need to await the response otherwise the code does not work and tries to manipulate a promise.

const value = await selectData(body, selector);

}
return results;
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This extra empty line can be removed?

@maxcoulombe
Copy link
Contributor

Good work here. This appears to be very similar to #247. Is there anything different here from that PR (other than a slightly different approach?). If not I think it would be best to close this PR and continue the conversation there.

After reviewing both PRs I'm of the opinion that we should aim to ship this one and close #247.

The approach here is simpler & cleaner plus it adds the option of specifying a prefix shared by all secrets form the same path which I think is useful.

@ShiroTian
Copy link

Why hasn't this PR been resolved for so long? Is there any other solution?

@ShiroTian
Copy link

ShiroTian commented Jun 27, 2023

Why hasn't this PR been resolved for so long? Is there any other solution?

I found out that $.$ can solve
#247

@keattang
Copy link
Contributor

keattang commented Sep 8, 2023

Hi @maxcoulombe I see this PR no longer seems active and so I have implemented all of your requested changes in #488

Please let me know if you have any other changes you would like to see. Very keen to get this into the repo as we are currently using this functionality in production.

maxcoulombe pushed a commit that referenced this pull request Sep 15, 2023
* Initial check-in of wildcard to get all secrets in path (Issue#234)
* Fix wildcard for K/V v2 and Cubbyhole.  Add more tests
* Refactored out selectAndAppendResults
* Use selectAndAppendResults for wildcard
* Use normalizeOutputKey in action.js
* Refactored wildcard

---------

Co-authored-by: Scott Lemme <[email protected]>
Co-authored-by: Lemme <[email protected]>
@maxcoulombe
Copy link
Contributor

maxcoulombe commented Sep 15, 2023

Hi @maxcoulombe I see this PR no longer seems active and so I have implemented all of your requested changes in #488

Please let me know if you have any other changes you would like to see. Very keen to get this into the repo as we are currently using this functionality in production.

Awesome thank you so much for picking this up. Thanks also to @slemme1 for the initial implementation. #488 got merged a couple of minutes ago, I'll follow-up with the team to include this new feature in a v2.8.0 release!

Since #488 supercedes this I'll go ahead and close #238.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants