Path
The Path
class is used to pass JSONPath expressions as values to assertion methods of the Check
class.
Constructor
Path(json_path)
Creates a new Path
instance. The provided json_path always starts from the root of the component data, so the leading $
is optional. This constructor raises ValueError
if the path is invalid.
Missing data behavior:
Raises
NoDataError
before collectors finished (results inNO_DATA
status).Raises
ValueError
after collectors finished (results inERROR
status).
This means that Path
is best used when you are assuming that the data will eventually be provided by a collector.
json_path (str): A JSONPath expression to query component data
Usage
The primary use of the Path
class is to provide a wrapper around JSONPath expressions that will be automatically evaluated by assertion methods in the Check
class.
from lunar_policy import Check, Path
with Check("my-check") as check:
# Using Path in assertions
check.assert_true(Path(".api.requires_auth"))
check.assert_equals(Path(".api.version"), "v1")
check.assert_contains(Path(".tags"), "security")
Last updated