Skip to main content

A configuration-driven engine that dynamically mutates incoming payloads based on conditional rules defined in YAML or JSON.

Project description

~ Kairo

Configuration-driven engine that dynamically mutates incoming payloads based on conditional rules defined in YAML or JSON.


--Overview--

Kairo is a configuration engine that modifies payload requests into a new one. With Canaries defined in a YAML-config or JSON-config, you can specify a matching Condition that applies Mutations if the condition is met i.e - if an path with a value is found. A mutation then applies any mutation given it finds a path and mutates it to a jmes-path search condition. Refer to 'How to Run' and 'Example Usage' for further examples.


--How To Run--

To run the engine, you need to create a Kairo() instance, load it properly with a yaml or json config - then run any condition or mutation(s) into incoming requests.

E.g -

kairo = Kairo()
kairo.load_from_yaml("canaries.yaml")
result = kairo.run({"some": "request"})

You can also create your own Condition / Mutations objects dynamically and run it through the Canary evaluator. To do so you first define a Match, and Filter objects to create your condition/mutation instances, initialize a canary object and evaluate it with an incoming payload request as such:

1️⃣ Get your request

original_request = {"foo": {"bar": 1, "baz": 2}}

2️⃣ Create your Match and Filter objects

match_obj = Match(path="foo.bar", with_value=1) # create match condition
filter_obj = Filter(path="foo.bar", to_value="foo.baz") # create filter condition

3️⃣ Create your Condition, Mutation, and (optional) added config

condition = Condition(match=match_obj)
mutation = Mutation(filter=filter_obj)
config = {"add": "me"}

4️⃣ Create Canary object and run evaluation

canary = Canary("test_foo_bar_baz", condition=condition, mutations=[mutation], config=config)
new_request = canary.evaluate(original_request, override=False)

5️⃣ Result

new_request = {
    "foo": {
        "bar": 2,
        "baz": 2
    },
    "add": "me"
}

--- To run it through a YAML-config or JSON-config the format should be as follows:

YAML Config:

global_config:
  name: (str)

  canaries:
    - name: (str)
      condition:
        match:
          path: (str)
          with_value: (Any)
      mutations:
        - filter:
            path: (str)
            to_value: (str)
        ...
    ...

      config:
          ...

JSON Config:

{
    "global_config": {
        "name": (str),
        "canaries": [
            {
                "name": (str),
                "condition": {
                    "match": {
                        "path": (str),
                        "with_value": (Any)
                    }
                },
                "mutations": [
                    {
                        "filter": {
                            "path": (str),
                            "to_value": (str)
                        }
                    } ...
                ]
            } ...
        ],
        "config": (Any)
    }
}

Testing

This is a dockerized python-3.12 and can be ran with Makefile commands as follows:

  1. "make ps" -> docker-compose ps

  2. "make build" -> docker-compose build

  3. "make build-clean" -> docker-compose build-clean

  4. "make exec" -> docker-compose exec server bash

  5. "make up" -> docker-compose up

  6. "make up-test" -> docker-compose up test

  7. "make down" -> docker-compose down

Testing can be done inside of the container. Once it's spun up you can exec into it and run tests there.

1) Make a build or new clean build.
2) Exec into the container.
3) Inside the container run commands: `python3.12 -m pytest tests`

License

Released under the MIT License — see LICENSE.

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

kairo_engine-1.0.0.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

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

kairo_engine-1.0.0-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file kairo_engine-1.0.0.tar.gz.

File metadata

  • Download URL: kairo_engine-1.0.0.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for kairo_engine-1.0.0.tar.gz
Algorithm Hash digest
SHA256 dafc4b81fc8e892398c5cba479e85f92289f4b8e05bb97986d5361a03723f33c
MD5 45f0829e24e9ff30c8a8402af3a80cac
BLAKE2b-256 21002b37ddca3232e79d9d8664fb5ec245023fdbf2726c58c1dc1e6121cfaafc

See more details on using hashes here.

File details

Details for the file kairo_engine-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: kairo_engine-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for kairo_engine-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b3bdc40e2283fc510cc957b02080fca0f3e1e1ecb1babfe8055254b1d94b4430
MD5 f168bda8950afbb0c077cfd39a448cda
BLAKE2b-256 2e96fe5915e3ded7091ffa92af2d6ac1cd1e3e456e189ad5cf98252c145c6728

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