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

core - add ability to add custom functions to jmespath #8533

Merged
merged 9 commits into from
May 11, 2023
11 changes: 11 additions & 0 deletions c7n/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Copyright The Cloud Custodian Authors.
# SPDX-License-Identifier: Apache-2.0
#

import jmespath
from functools import partial
from c7n.utils import C7NJmespathFunctions

jmespath.search = partial(
thisisshi marked this conversation as resolved.
Show resolved Hide resolved
jmespath.search,
options=jmespath.Options(
custom_functions=C7NJmespathFunctions()
)
)
10 changes: 9 additions & 1 deletion c7n/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import sys
import threading
import time
from jmespath import functions
from urllib import parse as urlparse
from urllib.request import getproxies, proxy_bypass


from dateutil.parser import ParserError, parse

from c7n import config
Expand Down Expand Up @@ -912,3 +912,11 @@
else:
rtype = 'unknown'
return rtype


class C7NJmespathFunctions(functions.Functions):
@functions.signature(
{'types': ['string']}, {'types': ['string']}
)
def _func_split(self, sep, string):
return string.split(sep)

Check warning on line 922 in c7n/utils.py

View check run for this annotation

Codecov / codecov/patch

c7n/utils.py#L922

Added line #L922 was not covered by tests