Skip to content

Commit

Permalink
Merge branch 'main' into activation
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea authored Aug 16, 2024
2 parents 26bb752 + a772aad commit 52eb185
Show file tree
Hide file tree
Showing 26 changed files with 826 additions and 61 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ jobs:
use_oidc: true # cspell:ignore oidc
files: "*/tests/output/reports/coverage.xml"

- name: Check codecov.io status
if: github.event_name == 'pull_request'
uses: coactions/codecov-status@main
# - name: Check codecov.io status
# if: github.event_name == 'pull_request'
# uses: coactions/codecov-status@main

- name: Decide whether the needed jobs succeeded or failed
uses: re-actors/alls-green@release/v1
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ repos:
- xxhash

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.5.7"
rev: "v0.6.0"
hooks:
- id: ruff
args: [
Expand Down
29 changes: 27 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ Contributions are welcome, and they are greatly appreciated! Every little bit he
Every new feature should be tested and documented.
New source plugins or source filters will be evaluated for inclusion in the collection and might be rejected. Please consider the option of creating a new collection for your plugins if it is not a good fit for this collection.

If you are new here, read the [Quick-start development guide first](https://docs.ansible.com/ansible/devel/community/create_pr_quick_start.html).

## Code of Conduct
The ansible.eda collection follows the Ansible project's [Code of Conduct](https://docs.ansible.com/ansible/devel/community/code_of_conduct.html). Please read and familiarize yourself with this document.

## Submitting Issues
All software has bugs, and the amazon.aws collection is no exception. When you find a bug, you can help tremendously by telling us [about it](https://github.com/ansible/event-driven-ansible/issues/new/choose).

If you should discover that the bug you're trying to file already exists in an issue, you can help by verifying the behavior of the reported bug with a comment in that issue, or by reporting any additional information

## Writing New Code

## Cloning

Due to ansible-test own requirements, you must clone the repository into
Expand All @@ -28,6 +40,19 @@ Pre-commit is now set up to run each time you create a new commit. If you wish t
pre-commit run --all
```

# CI testing

This collection uses GitHub Actions to run Sanity, Integration and Units to validate its content.

# Adding tests

When fixing a bug, first reproduce it by adding a task as reported to a suitable file under the tests/integration/targets/<module_name>/tasks/ directory and run the integration tests as described below. The same is relevant for new features.

It is not necessary but if you want you can also add unit tests to a suitable file under the tests/units/ directory and run them as described below.

# Checking your code locally
It will make your and other people's life a bit easier if you run the tests locally and fix all failures before pushing. If you're unable to run the tests locally, please create your PR as a draft to avoid reviewers being added automatically.

## Running tests for source plugins

Running the tests requires `ansible-rulebook` to be installed. Please review the [ansible-rulebook requirements](https://ansible-rulebook.readthedocs.io/en/stable/installation.html#requirements), but do not install `ansible-rulebook` manually. It will be installed via the test requirements.
Expand All @@ -47,15 +72,15 @@ We recommend setting up a Python virtual environment to install the test depende

pip install -r test_requirements.txt

### Sanity and Unit tests
## Sanity and Unit tests

Sanity and unity tests can easily be run via tox:

```shell
tox -e py
```

### Integration tests
## Integration tests

Integration tests require the addition of [docker](https://docs.docker.com/engine/install/) or [podman](https://podman.io/getting-started/installation).

Expand Down
107 changes: 101 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,122 @@

This collection contains event source plugins, event filters and example rulebooks to be used with [ansible-rulebook](https://ansible-rulebook.readthedocs.io/en/stable/).

<a href="https://github.com/ansible/event-driven-ansible/actions?workflow=tox"><img height="20px" src="https://github.com/ansible/event-driven-ansible/actions/workflows/tox.yml/badge.svg?event=schedule"/> </a>
[![tox](https://github.com/ansible/event-driven-ansible/actions/workflows/tox.yml/badge.svg?event=push)](https://github.com/ansible/event-driven-ansible/actions/workflows/tox.yml)
[![codecov](https://codecov.io/github/ansible/event-driven-ansible/graph/badge.svg?token=XvFwDpezAH)](https://codecov.io/github/ansible/event-driven-ansible)

## Description

The primary purpose of this collection is to reduce manual tasks and deliver more efficient mission-critical workflows. By leveraging this collection, organizations can automate a variety of error-prone and time-consuming tasks and respond to changing conditions in any IT domain across IT environments for better agility and resiliency.

## Requirements

* python >= 3.9
* ansible-core >= 2.15
### Ansible version compatibility

Tested with the Ansible Core >= 2.15.0 versions, and the current development version of Ansible. Ansible Core versions before 2.15.0 are not supported.

### Python version compatibility

This collection requires Python 3.9 or greater.

## Install
### Additional dependencies

Install the ansible.eda collection with the Ansible Galaxy CLI:
This collection requires ansible-rulebook 1.0.0 or greater.

## Installation

The `ansible.eda` collection can be installed with the Ansible Galaxy command-line tool:

```shell
ansible-galaxy collection install ansible.eda
```

You can also include it in a `requirements.yml` file and install it with `ansible-galaxy collection install -r requirements.yml`, using the format:

```yaml
---
collections:
- name: ansible.eda
```
Note that if you install any collections from Ansible Galaxy, they will not be upgraded automatically when you upgrade the Ansible package.
To upgrade the collection to the latest available version, run the following command:
```shell
ansible-galaxy collection install ansible.eda --upgrade
```

A specific version of the collection can be installed by using the `version` keyword in the `requirements.yml` file:

```yaml
---
collections:
- name: ansible.eda
version: 1.0.0
```
or using the ansible-galaxy command as follows
```shell
ansible-galaxy collection install ansible.eda:==1.0.0
```

The Python module dependencies are not installed by ansible-galaxy. They must be installed manually using pip:

```shell
pip install -r requirements.txt
```

Refer to the following for more details.
* [using Ansible collections](https://docs.ansible.com/ansible/latest/user_guide/collections_using.html) for more details.

## Use Cases

You can either call modules, rulebooks and playbooks by their Fully Qualified Collection Name (FQCN), such as ansible.eda.activation, or you can call modules by their short name if you list the ansible.eda collection in the playbook's collections keyword:

```yaml
---
- name: Create a rulebook activation
ansible.eda.activation:
name: "Example Activation"
description: "Example Activation description"
project: "Example Project"
rulebook_name: "basic_short.yml"
decision_environment_name: "Example Decision Environment"
enabled: False
awx_token_id: 1

- name: Get information about the rulebook activation
ansible.eda.activation_info:
name: "Example Activation"

- name: Delete rulebook activation
ansible.eda.activation:
name: "Example Activation"
state: absent
```
## Contributing
Please refer to the [contributing guide](./CONTRIBUTING.md) for information about how you can contribute to the project.
We welcome community contributions to this collection. If you find problems, please open an issue or create a PR against the [Event-Driven Ansible collection repository](https://github.com/ansible/event-driven-ansible).
See [CONTRIBUTING.md](./CONTRIBUTING.md) for more details.
### More information about contributing
- [Ansible Community Guide](https://docs.ansible.com/ansible/latest/community/index.html) - Details on contributing to Ansible
- [Contributing to Collections](https://docs.ansible.com/ansible/devel/dev_guide/developing_collections.html#contributing-to-collections) - How to check out collection git repositories correctly
## Release notes
See the [raw generated changelog](https://github.com/ansible/event-driven-ansible/tree/main/CHANGELOG.rst).
## Related Information
- [Ansible Collection Overview](https://github.com/ansible-collections/overview)
- [Ansible User Guide](https://docs.ansible.com/ansible/latest/user_guide/index.html)
- [Ansible Developer Guide](https://docs.ansible.com/ansible/latest/dev_guide/index.html)
- [Ansible Collection Developer Guide](https://docs.ansible.com/ansible/devel/dev_guide/developing_collections.html)
- [Ansible Community Code of Conduct](https://docs.ansible.com/ansible/latest/community/code_of_conduct.html)
## License Information
See [LICENSE](./LICENSE) to see the full text.
2 changes: 1 addition & 1 deletion extensions/eda/plugins/event_source/aws_cloudtrail.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
from datetime import datetime
from typing import Any

from aiobotocore.client import BaseClient
from aiobotocore.session import get_session
from botocore.client import BaseClient


def _cloudtrail_event_to_dict(event: dict) -> dict:
Expand Down
2 changes: 1 addition & 1 deletion extensions/eda/plugins/event_source/azure_service_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ async def main(
class MockQueue(asyncio.Queue[Any]):
"""A fake queue."""

async def put_nowait(self: "MockQueue", event: dict) -> None:
def put_nowait(self: "MockQueue", event: dict) -> None:
"""Print the event."""
print(event) # noqa: T201

Expand Down
10 changes: 5 additions & 5 deletions extensions/eda/plugins/event_source/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import pathlib

import yaml
from watchdog.events import RegexMatchingEventHandler
from watchdog.events import FileSystemEvent, RegexMatchingEventHandler
from watchdog.observers import Observer


Expand Down Expand Up @@ -63,18 +63,18 @@ class Handler(RegexMatchingEventHandler):
def __init__(self: "Handler", **kwargs) -> None: # noqa: ANN003
RegexMatchingEventHandler.__init__(self, **kwargs)

def on_created(self: "Handler", event: dict) -> None:
def on_created(self: "Handler", event: FileSystemEvent) -> None:
if event.src_path in files:
send_facts(queue, event.src_path)

def on_deleted(self: "Handler", event: dict) -> None:
def on_deleted(self: "Handler", event: FileSystemEvent) -> None:
pass

def on_modified(self: "Handler", event: dict) -> None:
def on_modified(self: "Handler", event: FileSystemEvent) -> None:
if event.src_path in files:
send_facts(queue, event.src_path)

def on_moved(self: "Handler", event: dict) -> None:
def on_moved(self: "Handler", event: FileSystemEvent) -> None:
pass

observer = Observer()
Expand Down
14 changes: 7 additions & 7 deletions extensions/eda/plugins/event_source/file_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import concurrent.futures
from typing import Any

from watchdog.events import RegexMatchingEventHandler
from watchdog.events import FileSystemEvent, RegexMatchingEventHandler
from watchdog.observers import Observer


Expand All @@ -37,10 +37,10 @@ def watch(
class Handler(RegexMatchingEventHandler):
"""A handler for file system events."""

def __init__(self: "Handler", **kwargs: dict) -> None:
def __init__(self: "Handler", **kwargs: FileSystemEvent) -> None:
RegexMatchingEventHandler.__init__(self, **kwargs)

def on_created(self: "Handler", event: dict) -> None:
def on_created(self: "Handler", event: FileSystemEvent) -> None:
loop.call_soon_threadsafe(
queue.put_nowait,
{
Expand All @@ -51,7 +51,7 @@ def on_created(self: "Handler", event: dict) -> None:
},
)

def on_deleted(self: "Handler", event: dict) -> None:
def on_deleted(self: "Handler", event: FileSystemEvent) -> None:
loop.call_soon_threadsafe(
queue.put_nowait,
{
Expand All @@ -62,7 +62,7 @@ def on_deleted(self: "Handler", event: dict) -> None:
},
)

def on_modified(self: "Handler", event: dict) -> None:
def on_modified(self: "Handler", event: FileSystemEvent) -> None:
loop.call_soon_threadsafe(
queue.put_nowait,
{
Expand All @@ -73,7 +73,7 @@ def on_modified(self: "Handler", event: dict) -> None:
},
)

def on_moved(self: "Handler", event: dict) -> None:
def on_moved(self: "Handler", event: FileSystemEvent) -> None:
loop.call_soon_threadsafe(
queue.put_nowait,
{
Expand Down Expand Up @@ -110,7 +110,7 @@ async def main(queue: asyncio.Queue, args: dict) -> None:
class MockQueue(asyncio.Queue[Any]):
"""A fake queue."""

async def put_nowait(self: "MockQueue", event: dict) -> None:
def put_nowait(self: "MockQueue", event: dict) -> None:
"""Print the event."""
print(event) # noqa: T201

Expand Down
3 changes: 1 addition & 2 deletions extensions/eda/plugins/event_source/journald.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,8 @@ async def main(queue: asyncio.Queue, args: dict[str, Any]) -> None: # noqa: D41
class MockQueue(asyncio.Queue[Any]):
"""A mock implementation of a queue that prints the event."""

async def put(self, event: str) -> str:
async def put(self, event: str) -> None:
"""Add the event to the queue and print it."""
print(event) # noqa: T201
return ""

asyncio.run(main(MockQueue(), {"match": "ALL"}))
14 changes: 0 additions & 14 deletions extensions/eda/plugins/event_source/range_input_schema.json

This file was deleted.

14 changes: 0 additions & 14 deletions extensions/eda/plugins/event_source/range_output_schema.json

This file was deleted.

Loading

0 comments on commit 52eb185

Please sign in to comment.