Skip to main content

No project description provided

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

celgcp-1.1.1.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

celgcp-1.1.1-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

Details for the file celgcp-1.1.1.tar.gz.

File metadata

  • Download URL: celgcp-1.1.1.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.6 Darwin/23.6.0

File hashes

Hashes for celgcp-1.1.1.tar.gz
Algorithm Hash digest
SHA256 ccf9246bd862db8b7e1496a4cabf150c6c0b93ac4fd2b3c3691e03bdfb0ad0b2
MD5 985c98ca62743443ffb7a252b80c728a
BLAKE2b-256 3ebdbb47596287b053f93025a630bf1578989bdf5e18a5a28c3eec1dca6cd0e0

See more details on using hashes here.

File details

Details for the file celgcp-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: celgcp-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.6 Darwin/23.6.0

File hashes

Hashes for celgcp-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a202fc6c15b5901661e9e3fbcd25e716a6f95b924759ebb72ab8193399e3d106
MD5 80eb7fcfa122feb66bfd13bdfcf2ae9e
BLAKE2b-256 1b8e6607f39c346f37d09a45e7b574815f99547b7626caa54272e41c1f4d3b4c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page