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

Use precompiled regexes and move OpenAPI call to tests #15170

Merged
merged 13 commits into from
Apr 26, 2022

Conversation

digivava
Copy link
Collaborator

@digivava digivava commented Apr 25, 2022

The digivava/output-policy branch currently grabs the sudo paths from the OpenAPI spec at runtime.

This way, like @averche 's suggestion, the sudo paths will be a static list which we will update only when the TestSudoPaths test fails.

The keys in the sudoPaths map are strings so we can quickly grab a URL by its string-key name in the scenario where no regex matching is needed, and so that anyone who wants a list of sudo paths can fetch it from this endpoint in the format the OpenAPI spec originally returned. The values of the map are regexes, so that consumers of the map can do regex matching when needed.

@digivava digivava requested a review from averche April 25, 2022 20:52
@digivava digivava requested a review from VinnyHC April 25, 2022 21:55
api/plugin_helpers.go Show resolved Hide resolved
api/plugin_helpers.go Outdated Show resolved Hide resolved
api/plugin_helpers.go Outdated Show resolved Hide resolved
Copy link
Contributor

@VinnyHC VinnyHC left a comment

Choose a reason for hiding this comment

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

This all seems reasonable, one comment about simplifying isSudoPath; I have some follow up questions but I think they are better suited for the main PR.

api/output_policy.go Outdated Show resolved Hide resolved
api/output_policy.go Outdated Show resolved Hide resolved
api/output_policy.go Outdated Show resolved Hide resolved
api/output_policy.go Outdated Show resolved Hide resolved
Copy link
Contributor

@averche averche left a comment

Choose a reason for hiding this comment

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

I definitely like this new approach 👍 Left a few nit-picky comments/suggestions.

@digivava digivava requested review from averche and VinnyHC and removed request for VinnyHC April 26, 2022 01:01
Copy link
Contributor

@averche averche left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Added a couple optional suggestions

api/plugin_helpers.go Show resolved Hide resolved
api/plugin_helpers.go Outdated Show resolved Hide resolved
Copy link
Contributor

@VinnyHC VinnyHC left a comment

Choose a reason for hiding this comment

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

This is really awesome and the sudo paths approach gives a solid framework to build on!

api/plugin_helpers.go Outdated Show resolved Hide resolved
@digivava digivava merged commit 384e2e8 into digivava/output-policy Apr 26, 2022
@digivava digivava deleted the digivava/output-policy-static-list branch April 26, 2022 17:25
digivava added a commit that referenced this pull request Apr 27, 2022
…#14899)

* WIP: output policy

* Outputs example policy HCL for given request

* Simplify conditional

* Add PATCH capability

* Use OpenAPI spec and regex patterns to determine if path is sudo

* Add test for isSudoPath

* Add changelog

* Fix broken CLI tests

* Add output-policy to client cloning code

* Smaller fixes from PR comments

* Clone client instead of saving and restoring custom values

* Fix test

* Address comments

* Don't unset output-policy flag on KV requests otherwise the preflight request will fail and not populate LastOutputPolicyError

* Print errors saved in buffer from preflight KV requests

* Unescape characters in request URL

* Rename methods and properties to improve readability

* Put KV-specificness at front of KV-specific error

* Simplify logic by doing more direct returns of strings and errors

* Use precompiled regexes and move OpenAPI call to tests

* Remove commented out code

* Remove legacy MFA paths

* Remove unnecessary use of client

* Move sudo paths map to plugin helper

* Remove unused error return

* Add explanatory comment

* Remove need to pass in address

* Make {name} regex less greedy

* Use method and path instead of info from retryablerequest

* Add test for IsSudoPaths, use more idiomatic naming

* Use precompiled regexes and move OpenAPI call to tests (#15170)

* Use precompiled regexes and move OpenAPI call to tests

* Remove commented out code

* Remove legacy MFA paths

* Remove unnecessary use of client

* Move sudo paths map to plugin helper

* Remove unused error return

* Add explanatory comment

* Remove need to pass in address

* Make {name} regex less greedy

* Use method and path instead of info from retryablerequest

* Add test for IsSudoPaths, use more idiomatic naming

* Make stderr writing more obvious, fix nil pointer deref
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.

3 participants