Skip to main content

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

  1. Install the package
    pip install celgcp
    
    or
    poetry add celgcp
    
  2. Import the class and exception
    from celgcp.celgcp import CELEvaluator, CELEvaluatorException
    
  3. Create a CEL Expression
    cel_source = """
    resource.matchTag('prj/dataset', 'value_1') 
    && resource.name.startsWith('projects/my-project/datasets/foo')
    """
    
  4. Create an instance of the CELEvaluator
    cel_evaluator = CELEvaluator(cel_source)
    
  5. 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"},
                ],
            },
        ),
    }
    
  6. 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)

Source distribution for celgcp 1.1.2
File Size Uploaded
celgcp-1.1.2.tar.gz 6.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for celgcp 1.1.2
File Interpreter ABI Platform
celgcp-1.1.2-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files

1.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page