Skip to content

Commit c098a30

Browse files
Update 'Resource', 'Now', and 'Event' fields to 'resource', 'now', and 'event' to be more Pythonic
1 parent 0820f2c commit c098a30

12 files changed

Lines changed: 418 additions & 407 deletions

File tree

‎benches/large_resource_set.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def run(self, error_limit: Optional[int] = None) -> None:
307307
self.errors: Counter[Exception] = collections.Counter()
308308
self.results: Counter[celpy.celtypes.Value] = collections.Counter()
309309

310-
decls = {"Resource": celpy.celtypes.MapType}
310+
decls = {"resource": celpy.celtypes.MapType}
311311
decls.update(celpy.c7nlib.DECLARATIONS)
312312
cel_env = celpy.Environment(annotations=decls)
313313
ast = cel_env.compile(self.example.filter_expr)
@@ -320,7 +320,7 @@ def run(self, error_limit: Optional[int] = None) -> None:
320320
for resource in self.resources:
321321
start = time.perf_counter()
322322
activation = {
323-
"Resource": celpy.json_to_cel(resource)
323+
"resource": celpy.json_to_cel(resource)
324324
}
325325
try:
326326
result = program.evaluate(activation)

‎demo/celdemo.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
2727
% PYTHONPATH=src python demo/celdemo.py --cel '355./113.'
2828
3.1415929203539825
29-
% PYTHONPATH=src python demo/celdemo.py --cel 'Now+duration("1h")' --now "2020-09-10T11:12:13Z"
29+
% PYTHONPATH=src python demo/celdemo.py --cel 'now+duration("1h")' --now "2020-09-10T11:12:13Z"
3030
2020-09-10T12:12:13Z
3131
3232
@@ -49,8 +49,8 @@
4949

5050
def cel_compile(text: str) -> celpy.Runner:
5151
decls: Dict[str, celpy.Annotation] = {
52-
"Resource": celpy.celtypes.MapType,
53-
"Now": celpy.celtypes.TimestampType,
52+
"resource": celpy.celtypes.MapType,
53+
"now": celpy.celtypes.TimestampType,
5454
}
5555
env = celpy.Environment(annotations=decls)
5656
ast = env.compile(text)
@@ -64,14 +64,14 @@ def run_cel_resource(cel: str, now: str, resource_iter: Iterable[Any]) -> None:
6464
for document in resource_iter:
6565
logger.debug(f"INPUT: {document!r}\n")
6666
activation = {
67-
"Resource": celpy.adapter.json_to_cel(document),
68-
"Now": celpy.celtypes.TimestampType(now),
67+
"resource": celpy.adapter.json_to_cel(document),
68+
"now": celpy.celtypes.TimestampType(now),
6969
}
7070
try:
7171
result = prgm.evaluate(activation)
72-
print(f"{result!r} from Now {now!r}, Resource {document}")
72+
print(f"{result!r} from now {now!r}, resource {document}")
7373
except Exception as ex:
74-
print(f"{ex!r} from Now {now!r}, Resource {document}")
74+
print(f"{ex!r} from now {now!r}, resource {document}")
7575

7676

7777
def get_options(argv: List[str] = sys.argv[1:]) -> argparse.Namespace:

‎docs/source/c7n_functions.rst‎

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,17 @@ interface.
5454

5555
3. The CEL activation context has these expected objects:
5656

57-
:Resource:
57+
:resource:
5858
This is the cloud resource being examined by C7N.
5959
This will be a CEL mapping object built from JSON source data.
6060

61-
:Now:
61+
:now:
6262
This is the current time.
6363
This will be a CEL timestamp.
6464
This promotes testability by removing the need to mock
6565
a clock to provide proper ``utcnow()`` values.
6666

67-
:Event:
67+
:event:
6868
For lambda-related resources, this is the triggering event.
6969
This will be a CEL mapping object built from JSON source data.
7070

@@ -85,7 +85,7 @@ This has a single attribite.
8585
In many cases, a number of additional functions are also present in this class.
8686

8787

88-
A number of filter expressions rely on data not directly avalable in the ``Resource`` or ``Event`` objects.
88+
A number of filter expressions rely on data not directly avalable in the ``resource`` or ``event`` objects.
8989
These are called *related resource* filters, and there are several examples.
9090

9191
- ``type: image`` and ``type: image-age`` filters gather details about the image associated with a resource
@@ -249,11 +249,11 @@ See the :py:mod:`celpy.c7nlib` module for additional information on this interfa
249249

250250
It also includes three global objects:
251251

252-
- ``Resource`` the cloud resource to be examined.
252+
- ``resource`` the cloud resource to be examined.
253253

254-
- ``Now`` the current time as a CEL timestamp.
254+
- ``now`` the current time as a CEL timestamp.
255255

256-
- ``Event`` an Event for those resources where the C7N check is triggered by a CloudWatch event.
256+
- ``event`` an event for those resources where the C7N check is triggered by a CloudWatch event.
257257

258258
"""
259259
schema = type_schema(
@@ -263,9 +263,9 @@ See the :py:mod:`celpy.c7nlib` module for additional information on this interfa
263263
)
264264

265265
decls: Dict[str, celpy.Annotation] = {
266-
"Resource": celpy.celtypes.MapType,
267-
"Now": celpy.celtypes.TimestampType,
268-
"Event": celpy.celtypes.MapType,
266+
"resource": celpy.celtypes.MapType,
267+
"now": celpy.celtypes.TimestampType,
268+
"event": celpy.celtypes.MapType,
269269
}
270270
decls.update(celpy.c7nlib.DECLARATIONS)
271271

@@ -292,9 +292,9 @@ See the :py:mod:`celpy.c7nlib` module for additional information on this interfa
292292
for resource in resources:
293293
with C7NContext(filter=the_filter):
294294
cel_activation = {
295-
"Resource": celpy.json_to_cel(resource),
296-
"Now": celpy.celtypes.TimestampType(now),
297-
# "Event": ...,
295+
"resource": celpy.json_to_cel(resource),
296+
"now": celpy.celtypes.TimestampType(now),
297+
# "event": ...,
298298
}
299299
if self.pgm.evaluate(cel_activation):
300300
yield resource
@@ -1256,7 +1256,7 @@ Policies studied have 125 examples.
12561256
# REDACTED #
12571257
12581258
The ``type: event`` filter examines data not directly part of a resource.
1259-
A Lambda is changed by an event. This ``Event`` detail is available in the activation along with the ``Resource``.
1259+
A Lambda is changed by an event. This ``event`` detail is available in the activation along with the ``resource``.
12601260

12611261
metrics
12621262
-------

0 commit comments

Comments
 (0)