-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
core - add ability to add custom functions to jmespath #8533
core - add ability to add custom functions to jmespath #8533
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it. I'm all for giving jmespath some more smarts and this seems like a reasonable way to handle it 👍 . I know the idea of extending jmespath from the c7n side has come up before, with split()
and slicing being recurring patterns. Thanks for jumping on this.
seems cool, but needs docs, else its not discoverable. |
@kapilt updated with docs and test |
tools/c7n_mailer/c7n_mailer/utils.py
Outdated
from dateutil import parser | ||
from dateutil.tz import gettz, tzutc | ||
|
||
from c7n.utils import jmespath_search |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically mailer doesn't have a runtime dependency on c7n, so we should just leave the default here afaics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, one minor
Adds the ability to include custom jmespath functions for use anywhere we express jmespath queries
This came up in the finops slack where there was a question around copy-related-tag(s) from a lambda function to its corresponding cloudwatch log group. The Cloudwatch log group follows the convention of
/aws/lambda/$function_name
but there's no way to do that in jmespath currently. There are enhancement proposals/issues here:array[string] split(string $separator, string $subject)
jmespath/jmespath.site#35array[string] split(string $separator, string $subject)
jmespath/jmespath.jep#26jmespath's python library includes a way to include custom functions via its
jmespath.functions.Functions
class, which is utilized in this PR.extant usage of jmespath should be preserved, as we're utilizing
functools.partial
to inject the additional options into the call, so extant call sites should continue to behave as normal and newjmespath.search
andjmespath.compile.search
calls should also be fine.