CEL evaluator for GCP
This is not an official Google product.
This module allows to evaluate the Google Cloud IAM Conditions where CEL is the expression language.
Author
hm98765@github
Usage
- Install the package
pip install celgcp
orpoetry add celgcp - Import the class and exception
from celgcp.celgcp import CELEvaluator, CELEvaluatorException
- Create a CEL Expression
cel_source = """ resource.matchTag('prj/dataset', 'value_1') && resource.name.startsWith('projects/my-project/datasets/foo') """
- Create an instance of the CELEvaluator
cel_evaluator = CELEvaluator(cel_source)
- Create the activation context
activation = { "resource": celpy.json_to_cel( { "name": "projects/my-project/datasets/foo/bar", "Tags": [ {"prj/dataset": "value_1"}, {"prj/table": "value_2"}, {"prj/mytag": "value_38"}, {"tagKeys/123456789012": "tagValues/567890123456"}, {"tagKeys/987654321": "tagValues/111111"}, ], }, ), }
- call the evaluate method
result = cel_evaluator.evaluate(activation)
Example
A complete example
from datetime import datetime
import celpy
from celgcp.celgcp import CELEvaluator, CELEvaluatorException
cel_source = """
resource.matchTag('prj/dataset', 'value_1')
&& resource.name.startsWith('projects/my-project/datasets/foo')
&& request.time < timestamp("2024-03-21T01:14:51Z")
"""
date_string = "2021-03-21T01:14:51Z"
datetime_object = datetime.strptime(date_string, "%Y-%m-%dT%H:%M:%SZ")
activation = {
"request": celpy.json_to_cel({"time": datetime_object}),
"resource": celpy.json_to_cel(
{
"name": "projects/my-project/datasets/foo/bar",
"Tags": [
{"prj/dataset": "value_1"},
{"prj/table": "value_2"},
{"prj/mytag": "value_38"},
{"tagKeys/123456789012": "tagValues/567890123456"},
{"tagKeys/987654321": "tagValues/111111"},
],
},
),
}
cel_evaluator = CELEvaluator(cel_source)
result = cel_evaluator.evaluate(activation)
Language
Dependencies
The dependencies are listed in the pyproject.toml
License
Apache 2.0; see LICENSE for details.
Tests
poetry run pytest ./tests/tests.py
This is not an officially supported Google product. This project is not eligible for the Google Open Source Software Vulnerability Rewards Program.
Metadata
Release files for celgcp 1.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| celgcp-1.1.2.tar.gz | 6.3 kB | Without provenance | Details for celgcp-1.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| celgcp-1.1.2-py3-none-any.whl | Python 3 | none | any | Details for celgcp-1.1.2-py3-none-any.whl |
Total release size: 13.9 kB
Release files / celgcp-1.1.2.tar.gz
| Download URL | celgcp-1.1.2.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cefe9e1e3e01041835c4986b6022998190b13917ea06175f697a15f1d7410656
|
|
BLAKE2b-256 checksum How to use checksums |
bb284f742c46b6ab306363d5a038f946b3b81b0a24d03c3a3d99b950387d1533
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.9.6 Darwin/23.6.0
|
Release files / celgcp-1.1.2-py3-none-any.whl
| Download URL | celgcp-1.1.2-py3-none-any.whl |
|---|---|
| Size | 7.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
99aa158525520e2e2d5e730ffe52019a42a32551487a18c750b93d5f7d8dd584
|
|
BLAKE2b-256 checksum How to use checksums |
55fc5d73e6ed5d05e37b88d7cdeda511a74c361c25ce632b585faceb9f70e43c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.9.6 Darwin/23.6.0
|
Security for celgcp 1.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.