|
| 1 | +# Common Expression Language |
| 2 | + |
| 3 | +The Common Expression Language (CEL) implements common semantics for expression |
| 4 | +evaluation, enabling different applications to more easily interoperate. |
| 5 | + |
| 6 | +Key Applications |
| 7 | + |
| 8 | +* Security policy: organizations have complex infrastructure and need common |
| 9 | + tooling to reason about the system as a whole |
| 10 | +* Protocols: expressions are a useful data type and require interoperability |
| 11 | + across programming languages and platforms. |
| 12 | + |
| 13 | + |
| 14 | +Guiding philosophy: |
| 15 | + |
| 16 | +1. Keep it small & fast. |
| 17 | + * CEL evaluates in linear time, is mutation free, and not Turing-complete. |
| 18 | + This limitation is a feature of the language design, which allows the |
| 19 | + implementation to evaluate orders of magnitude faster than equivalently |
| 20 | + sandboxed JavaScript. |
| 21 | +2. Make it extensible. |
| 22 | + * CEL is designed to be embedded in applications, and allows for |
| 23 | + extensibility via its context which allows for functions and data to be |
| 24 | + provided by the software that embeds it. |
| 25 | +3. Developer-friendly. |
| 26 | + * The language is approachable to developers. The initial spec was based |
| 27 | + on the experience of developing Firebase Rules and usability testing |
| 28 | + many prior iterations. |
| 29 | + * The library itself and accompanying toolings should be easy to adopt by |
| 30 | + teams that seek to integrate CEL into their platforms. |
| 31 | + |
| 32 | +The required components of a system that supports CEL are: |
| 33 | + |
| 34 | +* The textual representation of an expression as written by a developer. It is |
| 35 | + of similar syntax to expressions in C/C++/Java/JavaScript |
| 36 | +* A representation of the program's abstract syntax tree (AST). |
| 37 | +* A compiler library that converts the textual representation to the binary |
| 38 | + representation. This can be done ahead of time (in the control plane) or |
| 39 | + just before evaluation (in the data plane). |
| 40 | +* A context containing one or more typed variables, often protobuf messages. |
| 41 | + Most use-cases will use `attribute_context.proto` |
| 42 | +* An evaluator library that takes the binary format in the context and |
| 43 | + produces a result, usually a Boolean. |
| 44 | + |
| 45 | +For use cases which require persistence or cross-process communcation, it is |
| 46 | +highly recommended to serialize the type-checked expression as a protocol |
| 47 | +buffer. The CEL team will maintains canonical protocol buffers for ASTs and |
| 48 | +will keep these versions identical and wire-compatible in perpetuity: |
| 49 | + |
| 50 | +* [CEL canonical](https://github.com/google/cel-spec/tree/master/proto/cel/expr) |
| 51 | +* [CEL v1alpha1](https://github.com/googleapis/googleapis/tree/master/google/api/expr/v1alpha1) |
| 52 | + |
| 53 | + |
| 54 | +Example of boolean conditions and object construction: |
| 55 | + |
| 56 | +``` c |
| 57 | +// Condition |
| 58 | +account.balance >= transaction.withdrawal |
| 59 | + || (account.overdraftProtection |
| 60 | + && account.overdraftLimit >= transaction.withdrawal - account.balance) |
| 61 | + |
| 62 | +// Object construction |
| 63 | +common.GeoPoint{ latitude: 10.0, longitude: -5.5 } |
| 64 | +``` |
| 65 | +
|
| 66 | +For more detail, see: |
| 67 | +
|
| 68 | +* [Introduction](doc/intro.md) |
| 69 | +* [Language Definition](doc/langdef.md) |
| 70 | +
|
| 71 | +Released under the [Apache License](LICENSE). |
| 72 | +
|
| 73 | +Disclaimer: This is not an official Google product. |
0 commit comments