Skip to content

Commit

Permalink
feat: [AAP-38755] add documentation for azure_service_bus, file and f…
Browse files Browse the repository at this point in the history
…ile_watch plugins (#390)
  • Loading branch information
Dostonbek1 authored Feb 4, 2025
1 parent a8b1303 commit f1bec29
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 55 deletions.
49 changes: 31 additions & 18 deletions extensions/eda/plugins/event_source/azure_service_bus.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
"""azure_service_bus.py.
An ansible-rulebook event source module for receiving events from an Azure service bus
Arguments:
---------
conn_str: The connection string to connect to the Azure service bus
queue_name: The name of the queue to pull messages from
logging_enable: Whether to turn on logging. Default to True
Example:
-------
- ansible.eda.azure_service_bus:
conn_str: "{{connection_str}}"
queue_name: "{{queue_name}}"
"""

import asyncio
import concurrent.futures
import contextlib
Expand All @@ -24,6 +6,37 @@

from azure.servicebus import ServiceBusClient

DOCUMENTATION = r"""
---
short_description: Receive events from an Azure service bus.
description:
- An ansible-rulebook event source module for receiving events from an Azure service bus.
- In order to get the service bus and the connection string, refer to
https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-python-how-to-use-queues?tabs=passwordless
options:
conn_str:
description:
- The connection string to connect to the Azure service bus.
type: str
required: true
queue_name:
description:
- The name of the queue to pull messages from.
type: str
required: true
logging_enable:
description:
- Whether to turn on logging.
type: bool
default: true
"""

EXAMPLES = r"""
- ansible.eda.azure_service_bus:
conn_str: "{{connection_str}}"
queue_name: "{{queue_name}}"
"""


def receive_events(
loop: asyncio.events.AbstractEventLoop,
Expand Down
37 changes: 20 additions & 17 deletions extensions/eda/plugins/event_source/file.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
"""file.py.
An ansible-rulebook event source plugin for loading facts from YAML files
initially and when the file changes.
Arguments:
---------
files - a list of YAML files
Example:
-------
- ansible.eda.file:
files:
- fact.yml
"""

import pathlib
from asyncio import Queue
from typing import Any, Union
Expand All @@ -23,6 +6,26 @@
from watchdog.events import FileSystemEvent, RegexMatchingEventHandler
from watchdog.observers import Observer

DOCUMENTATION = r"""
---
short_description: Load facts from YAML files initially and when the file changes.
description:
- An ansible-rulebook event source plugin for loading facts from YAML files
initially and when the file changes.
options:
files:
description:
- A list of file paths pointing to YAML files.
type: list
elements: str
"""

EXAMPLES = r"""
- ansible.eda.file:
files:
- /path/to/fact.yml
"""


def send_facts(queue: Queue[Any], filename: Union[str, bytes]) -> None:
"""Send facts to the queue."""
Expand Down
50 changes: 30 additions & 20 deletions extensions/eda/plugins/event_source/file_watch.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,40 @@
r"""file_watch.py.
An ansible-rulebook event source plugin for watching file system changes.
Arguments:
---------
path: The directory to watch for changes.
ignore_regexes: A list of regular expressions to ignore changes
recursive: Recursively watch the path if true
Example:
-------
- name: file_watch
file_watch:
path: "{{src_path}}"
recursive: true
ignore_regexes: ['.*\\.pytest.*', '.*__pycache__.*', '.*/.git.*']
"""

import asyncio
import concurrent.futures
from typing import Any

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

DOCUMENTATION = r"""
---
short_description: Watch file system changes.
description:
- An ansible-rulebook event source plugin for watching file system changes.
options:
path:
description:
- The directory to watch for changes.
type: str
required: true
ignore_regexes:
description:
- A list of regular expressions to ignore changes.
type: list
elements: str
recursive:
description:
- Recursively watch the path if true.
type: bool
required: true
"""

EXAMPLES = r"""
- ansible.eda.file_watch:
path: "/directory/to/watch"
recursive: true
ignore_regexes: ['.*\\.pytest.*', '.*__pycache__.*', '.*/.git.*']
"""


def watch(
loop: asyncio.events.AbstractEventLoop,
Expand Down

0 comments on commit f1bec29

Please sign in to comment.