From 4e21dd227f2760f46606222a6bc2198964529c6e Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Fri, 16 Aug 2024 12:02:34 +0100 Subject: [PATCH 1/4] Address more typing errors (#264) Related: #258 --- .pre-commit-config.yaml | 2 +- .../eda/plugins/event_source/aws_cloudtrail.py | 2 +- .../eda/plugins/event_source/azure_service_bus.py | 2 +- extensions/eda/plugins/event_source/file.py | 10 +++++----- extensions/eda/plugins/event_source/file_watch.py | 14 +++++++------- extensions/eda/plugins/event_source/journald.py | 3 +-- plugins/modules/project_info.py | 2 ++ pyproject.toml | 5 ----- 8 files changed, 18 insertions(+), 22 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c3c44f34..4e57abdb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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: [ diff --git a/extensions/eda/plugins/event_source/aws_cloudtrail.py b/extensions/eda/plugins/event_source/aws_cloudtrail.py index 5f9bcb00..6f6b680e 100644 --- a/extensions/eda/plugins/event_source/aws_cloudtrail.py +++ b/extensions/eda/plugins/event_source/aws_cloudtrail.py @@ -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: diff --git a/extensions/eda/plugins/event_source/azure_service_bus.py b/extensions/eda/plugins/event_source/azure_service_bus.py index dcd51d98..f00d14c5 100644 --- a/extensions/eda/plugins/event_source/azure_service_bus.py +++ b/extensions/eda/plugins/event_source/azure_service_bus.py @@ -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 diff --git a/extensions/eda/plugins/event_source/file.py b/extensions/eda/plugins/event_source/file.py index 09403d98..df5809e9 100644 --- a/extensions/eda/plugins/event_source/file.py +++ b/extensions/eda/plugins/event_source/file.py @@ -18,7 +18,7 @@ import pathlib import yaml -from watchdog.events import RegexMatchingEventHandler +from watchdog.events import FileSystemEvent, RegexMatchingEventHandler from watchdog.observers import Observer @@ -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() diff --git a/extensions/eda/plugins/event_source/file_watch.py b/extensions/eda/plugins/event_source/file_watch.py index aa2b09aa..2c28306e 100644 --- a/extensions/eda/plugins/event_source/file_watch.py +++ b/extensions/eda/plugins/event_source/file_watch.py @@ -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 @@ -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, { @@ -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, { @@ -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, { @@ -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, { @@ -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 diff --git a/extensions/eda/plugins/event_source/journald.py b/extensions/eda/plugins/event_source/journald.py index 2de64c50..67087e0e 100644 --- a/extensions/eda/plugins/event_source/journald.py +++ b/extensions/eda/plugins/event_source/journald.py @@ -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"})) diff --git a/plugins/modules/project_info.py b/plugins/modules/project_info.py index 0a1ba8c4..858d45a9 100644 --- a/plugins/modules/project_info.py +++ b/plugins/modules/project_info.py @@ -72,8 +72,10 @@ ] """ # NOQA +# pylint: disable=wrong-import-position, from ansible.module_utils.basic import AnsibleModule +# pylint: disable=relative-beyond-top-level from ..module_utils.arguments import AUTH_ARGSPEC from ..module_utils.client import Client from ..module_utils.controller import Controller diff --git a/pyproject.toml b/pyproject.toml index 2a7da5e9..23018d44 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,10 +39,6 @@ color_output = true error_summary = true # TODO: Remove temporary skips and close https://github.com/ansible/event-driven-ansible/issues/258 -disable_error_code = [ - "attr-defined", - "override", -] # strict = true # disallow_untyped_calls = true # disallow_untyped_defs = true @@ -65,7 +61,6 @@ module = [ "aiokafka.*", # https://github.com/aio-libs/aiokafka/issues/980 "ansible.*", # https://github.com/ansible/ansible/issues/83801 "asyncmock", # https://github.com/timsavage/asyncmock/issues/8 - # "botocore.*", # https://github.com/boto/botocore/issues/2297 "kafka.*", # https://github.com/dpkp/kafka-python/issues/2446 ] ignore_missing_imports = true From 6fde899bbe3ab10e6389f1dcf8e4d2d51c78c80f Mon Sep 17 00:00:00 2001 From: Madhu Kanoor Date: Fri, 16 Aug 2024 07:21:45 -0400 Subject: [PATCH 2/4] Add schemas for our source plugins (#198) * feat: Added schemas for our source plugins This is some of the work needed for the UI to generate source args for Fanout. * Fix spelling --------- Co-authored-by: Mauricio Magnani Jr Co-authored-by: Sorin Sbarnea Co-authored-by: Sorin Sbarnea --- .../event_source/range_input_schema.json | 14 -- .../event_source/range_output_schema.json | 14 -- .../event_source/schemas/alertmanager.json | 49 +++++++ .../event_source/schemas/aws_cloudtrail.json | 81 +++++++++++ .../event_source/schemas/aws_sqs_queue.json | 51 +++++++ .../schemas/azure_service_bus.json | 29 ++++ .../plugins/event_source/schemas/file.json | 20 +++ .../event_source/schemas/file_watch.json | 31 +++++ .../plugins/event_source/schemas/generic.json | 112 +++++++++++++++ .../event_source/schemas/journald.json | 22 +++ .../plugins/event_source/schemas/kafka.json | 127 ++++++++++++++++++ .../event_source/schemas/pg_listener.json | 26 ++++ .../plugins/event_source/schemas/range.json | 22 +++ .../event_source/schemas/url_check.json | 32 +++++ .../plugins/event_source/schemas/webhook.json | 75 +++++++++++ 15 files changed, 677 insertions(+), 28 deletions(-) delete mode 100644 extensions/eda/plugins/event_source/range_input_schema.json delete mode 100644 extensions/eda/plugins/event_source/range_output_schema.json create mode 100644 extensions/eda/plugins/event_source/schemas/alertmanager.json create mode 100644 extensions/eda/plugins/event_source/schemas/aws_cloudtrail.json create mode 100644 extensions/eda/plugins/event_source/schemas/aws_sqs_queue.json create mode 100644 extensions/eda/plugins/event_source/schemas/azure_service_bus.json create mode 100644 extensions/eda/plugins/event_source/schemas/file.json create mode 100644 extensions/eda/plugins/event_source/schemas/file_watch.json create mode 100644 extensions/eda/plugins/event_source/schemas/generic.json create mode 100644 extensions/eda/plugins/event_source/schemas/journald.json create mode 100644 extensions/eda/plugins/event_source/schemas/kafka.json create mode 100644 extensions/eda/plugins/event_source/schemas/pg_listener.json create mode 100644 extensions/eda/plugins/event_source/schemas/range.json create mode 100644 extensions/eda/plugins/event_source/schemas/url_check.json create mode 100644 extensions/eda/plugins/event_source/schemas/webhook.json diff --git a/extensions/eda/plugins/event_source/range_input_schema.json b/extensions/eda/plugins/event_source/range_input_schema.json deleted file mode 100644 index 45fe7929..00000000 --- a/extensions/eda/plugins/event_source/range_input_schema.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://redhat.com/ansible_events/sources/range_input_schema.json", - "title": "Input of range Plugin", - "description": "A simple plugin to generate integer values given a limit", - "type": "object", - "properties": { - "limit": { - "description": "The max integer value", - "type": "integer" - } - }, - "required": ["limit"] -} diff --git a/extensions/eda/plugins/event_source/range_output_schema.json b/extensions/eda/plugins/event_source/range_output_schema.json deleted file mode 100644 index d6a60898..00000000 --- a/extensions/eda/plugins/event_source/range_output_schema.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://redhat.com/ansible_events/sources/range_output_schema.json", - "title": "Output of range Plugin", - "description": "A simple plugin to generate integer values given a limit", - "type": "object", - "properties": { - "i": { - "description": "The current integer value", - "type": "integer" - } - }, - "required": ["i"] -} diff --git a/extensions/eda/plugins/event_source/schemas/alertmanager.json b/extensions/eda/plugins/event_source/schemas/alertmanager.json new file mode 100644 index 00000000..68515090 --- /dev/null +++ b/extensions/eda/plugins/event_source/schemas/alertmanager.json @@ -0,0 +1,49 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://redhat.com/ansible_events/sources/alertmanager.json", + "title": "Alert manager Source Plugin", + "description": "A plugin for Alert Manager", + "type": "object", + "properties": { + "host": { + "description": "The webserver hostname to listen to. Set to 0.0.0.0 to listen on all interfaces. Defaults to 127.0.0.1", + "title": "Host", + "type": "string", + "default": "127.0.0.1" + }, + "port": { + "description": "The TCP port to listen to. Defaults to 5000", + "title": "Port", + "type": "integer", + "default": 5000 + }, + "data_alerts_path": { + "description": "The json path to find alert data. Default to alerts Use empty string to treat the whole payload data as one alert.", + "title": "Alerts Path", + "type": "string", + "default": "alerts" + }, + "data_host_path": { + "description": "The json path inside the alert data to find alerting host. Use empty string if there is no need to find host. Default to labels.instance.", + "title": "Host Path", + "type": "string", + "default": "labels.instance" + }, + "data_path_separator": { + "description": "The separator to interpret data_host_path and data_alerts_path. Default is . (dot or period)", + "title": "Path Separator", + "type": "string", + "default": "." + }, + "skip_original_data": { + "description": "If enabled only the alert data will be put in queue, else put sequentially both the received original data and each parsed alert item to the queue.", + "title": "Skip Original Data", + "type": "boolean", + "default": false + } + }, + "required": [ + "host", + "port" + ] +} diff --git a/extensions/eda/plugins/event_source/schemas/aws_cloudtrail.json b/extensions/eda/plugins/event_source/schemas/aws_cloudtrail.json new file mode 100644 index 00000000..d356abad --- /dev/null +++ b/extensions/eda/plugins/event_source/schemas/aws_cloudtrail.json @@ -0,0 +1,81 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://redhat.com/ansible_events/sources/aws_cloudtrail.json", + "title": "Source Plugin for AWS CloudTrail", + "description": "An ansible-rulebook event source module for getting events from an AWS CloudTrail", + "type": "object", + "properties": { + "access_key": { + "description": "AWS access key ID", + "title": "Access Key", + "type": "string", + "format": "password" + }, + "secret_key": { + "description": "AWS secret key", + "title": "Secret Key", + "type": "string", + "format": "password" + }, + "session_token": { + "description": "STS session token for use with temporary credentials", + "title": "Session Token", + "type": "string", + "format": "password" + }, + "endpoint_url": { + "description": "URL to connect to instead of the default AWS endpoints", + "title": "Endpoint URL", + "type": "string" + }, + "region": { + "description": "AWS region to use", + "title": "Region", + "type": "string" + }, + "delay_seconds": { + "description": "The number of seconds to wait between polling", + "title": "Poll Delay", + "type": "integer", + "default": 10 + }, + "lookup_attributes": { + "description": "Lookup attributes", + "title": "Filters", + "type": "array", + "items": { + "$ref": "#/$defs/lookup" + } + }, + "event_category": { + "description": "Event Category", + "title": "Event Category", + "type": "string" + } + }, + "$defs": { + "lookup": { + "type": "object", + "required": [ + "AttributeKey", + "AttributeValue" + ], + "properties": { + "AttributeKey": { + "type": "string", + "title": "Key", + "description": "Specifies an attribute on which to filter the events" + }, + "AttributeValue": { + "type": "string", + "title": "Value", + "description": "Specifies a value for the specified AttributeKey" + } + } + } + }, + "required": [ + "lookup_attributes", + "event_category" + ] +} diff --git a/extensions/eda/plugins/event_source/schemas/aws_sqs_queue.json b/extensions/eda/plugins/event_source/schemas/aws_sqs_queue.json new file mode 100644 index 00000000..3b2d0f3c --- /dev/null +++ b/extensions/eda/plugins/event_source/schemas/aws_sqs_queue.json @@ -0,0 +1,51 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://redhat.com/ansible_events/sources/aws_sqs_queue.json", + "title": "Source Plugin for AWS SQS Queue", + "description": "An ansible-rulebook event source plugin for receiving events via an AWS SQS queue.", + "type": "object", + "properties": { + "access_key": { + "description": "AWS access key ID", + "type": "string", + "title": "Access Key", + "format": "password" + }, + "secret_key": { + "description": "AWS secret key", + "type": "string", + "title": "Secret Key", + "format": "password" + }, + "session_token": { + "description": "STS session token for use with temporary credentials", + "title": "Session Token", + "type": "string", + "format": "password" + }, + "endpoint_url": { + "description": "URL to connect to instead of the default AWS endpoints", + "type": "string", + "title": "End Point URL" + }, + "region": { + "description": "AWS region to use", + "type": "string", + "title": "Region" + }, + "name": { + "description": "The name of the queue", + "type": "string", + "title": "Queue Name" + }, + "delay_seconds": { + "description": "The SQS long polling duration. Set to 0 to disable", + "title": "Polling Interval", + "type": "integer", + "default": 2 + } + }, + "required": [ + "name" + ] +} diff --git a/extensions/eda/plugins/event_source/schemas/azure_service_bus.json b/extensions/eda/plugins/event_source/schemas/azure_service_bus.json new file mode 100644 index 00000000..80dabc84 --- /dev/null +++ b/extensions/eda/plugins/event_source/schemas/azure_service_bus.json @@ -0,0 +1,29 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://redhat.com/ansible_events/sources/azure_service_bus.json", + "title": "Azure Service Bus plugin for EDA", + "description": "An ansible-rulebook event source module for receiving events from an Azure service bus", + "type": "object", + "properties": { + "conn_str": { + "description": "The connection string", + "type": "string", + "title": "Connection String" + }, + "queue_name": { + "description": "The queue name", + "type": "string", + "title": "Queue Name" + }, + "logging_enable": { + "description": "Turn on logging", + "type": "boolean", + "default": true, + "title": "Enable Logging" + } + }, + "required": [ + "conn_str", + "queue_name" + ] +} diff --git a/extensions/eda/plugins/event_source/schemas/file.json b/extensions/eda/plugins/event_source/schemas/file.json new file mode 100644 index 00000000..ebe0e6c8 --- /dev/null +++ b/extensions/eda/plugins/event_source/schemas/file.json @@ -0,0 +1,20 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://redhat.com/ansible_events/sources/file.json", + "title": "YAML File monitor plugin for EDA", + "description": "An ansible-rulebook event source plugin for loading facts from YAML files initially and when the file changes.", + "type": "object", + "properties": { + "files": { + "description": "An array of YAML files to monitor", + "title": "YAML Files", + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "files" + ] +} diff --git a/extensions/eda/plugins/event_source/schemas/file_watch.json b/extensions/eda/plugins/event_source/schemas/file_watch.json new file mode 100644 index 00000000..3d5c5c1b --- /dev/null +++ b/extensions/eda/plugins/event_source/schemas/file_watch.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://redhat.com/ansible_events/sources/file_watch.json", + "title": "File Watcher Source plugin", + "description": "An ansible-rulebook event source plugin for watching file system changes.", + "type": "object", + "properties": { + "path": { + "description": "The directory to watch for changes.", + "type": "string", + "title": "Path" + }, + "recursive": { + "description": "Recursively watch the path if true", + "type": "boolean", + "title": "Recursive" + }, + "ignore_regexes": { + "description": "A list of regular expressions to ignore changes", + "title": "Ignore Regexes", + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "path", + "recursive" + ] +} diff --git a/extensions/eda/plugins/event_source/schemas/generic.json b/extensions/eda/plugins/event_source/schemas/generic.json new file mode 100644 index 00000000..584474cd --- /dev/null +++ b/extensions/eda/plugins/event_source/schemas/generic.json @@ -0,0 +1,112 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://redhat.com/ansible_events/sources/generic.json", + "title": "A generic event generator plugin", + "description": "A generic source plugin that allows you to insert custom data.", + "type": "object", + "properties": { + "payload": { + "description": "An array of event payloads", + "title": "Payload", + "type": "array", + "items": { + "$ref": "#/$defs/generic_payload" + } + }, + "randomize": { + "description": "Randomize the events in the payload", + "title": "Randomize", + "type": "boolean", + "default": false + }, + "display": { + "description": "Display the event data in stdout", + "title": "Display", + "type": "boolean", + "default": false + }, + "timestamp": { + "title": "Time Stamp", + "description": "Add an event timestamp, to every event", + "type": "boolean", + "default": false + }, + "time_format": { + "title": "Time Format", + "description": "The time format of event timestamp", + "enum": [ + "local", + "epoch", + "iso8601" + ], + "default": "local" + }, + "create_index": { + "title": "Index Key", + "description": "The index to create for each event starts at 0", + "type": "string" + }, + "startup_delay": { + "title": "Startup Delay", + "description": "Number of seconds to wait before injecting events", + "type": "number", + "default": 0 + }, + "event_delay": { + "title": "Event Delay", + "description": "Number of seconds to wait before injecting the next event from the payload.", + "type": "number", + "default": 0 + }, + "repeat_delay": { + "title": "Repeat Delay", + "description": "Number of seconds to wait before injecting a repeated event from the payload", + "type": "number", + "default": 0 + }, + "loop_delay": { + "title": "Loop Delay", + "description": "Number of seconds to wait before inserting the next set of events.", + "type": "number", + "default": 0 + }, + "shutdown_after": { + "title": "Shutdown After", + "description": "Number of seconds to wait before shutting down the plugin", + "type": "number", + "default": 0 + }, + "loop_count": { + "title": "Loop Count", + "description": "Number of times the set of events in the payload should be repeated, -1 loops for ever", + "type": "integer", + "default": 1 + }, + "repeat_count": { + "title": "Repeat Count", + "description": "Number of times each individual event in the payload should be repeated", + "type": "integer", + "default": 1 + }, + "blob_size": { + "title": "Blob Size", + "description": "An arbitrary blob of blob_size bytes to be inserted into every event payload.", + "type": "integer", + "default": 0 + }, + "final_payload": { + "title": "Final Payload", + "description": "After all the events have been sent we send the optional final payload which can be used to trigger a shutdown of the rulebook, especially when we are using rulebooks to forward messages to other running rulebooks.", + "$ref": "#/$defs/generic_payload" + } + }, + "$defs": { + "generic_payload": { + "type": "object", + "additional_properties": "true" + } + }, + "required": [ + "payload" + ] +} diff --git a/extensions/eda/plugins/event_source/schemas/journald.json b/extensions/eda/plugins/event_source/schemas/journald.json new file mode 100644 index 00000000..ac068a40 --- /dev/null +++ b/extensions/eda/plugins/event_source/schemas/journald.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://redhat.com/ansible_events/sources/journald.json", + "title": "A journald source plugin", + "description": "An ansible-events event source plugin that tails systemd journald logs.", + "type": "object", + "properties": { + "match": { + "description": "Events that matches, see see https://www.freedesktop.org/software/systemd/man/systemd.journal-fields.html ALL matches all events", + "title": "Match", + "type": "string", + "examples": [ + "PRIORITY=6", + "_EXE=/usr/bin/sudo", + "ALL" + ] + } + }, + "required": [ + "match" + ] +} diff --git a/extensions/eda/plugins/event_source/schemas/kafka.json b/extensions/eda/plugins/event_source/schemas/kafka.json new file mode 100644 index 00000000..470d7961 --- /dev/null +++ b/extensions/eda/plugins/event_source/schemas/kafka.json @@ -0,0 +1,127 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://redhat.com/ansible_events/sources/kafka.json", + "title": "Kafka Source Plugin", + "description": "An ansible-rulebook event source plugin for receiving events via a kafka topic.", + "type": "object", + "properties": { + "port": { + "description": "The port where the kafka server is listening", + "type": "integer", + "title": "Port" + }, + "host": { + "description": "The host where the kafka topic is hosted", + "type": "string", + "title": "Host" + }, + "cafile": { + "description": "Certificate authority file path containing certificates used to sign kafka broker certificates", + "type": "string", + "title": "Certificate Authority File", + "default": "" + }, + "certfile": { + "description": "The optional client certificate file path containing the client certificate, as well as CA certificates needed to establish the certificate's authenticity", + "type": "string", + "title": "Certificate File", + "default": "" + }, + "keyfile": { + "description": "The optional client key file path containing the client private key", + "type": "string", + "title": "Key File", + "default": "" + }, + "password": { + "description": "The optional password to be used when loading the certificate chain", + "type": "string", + "title": "Password", + "format": "password" + }, + "check_hostname": { + "description": "Enable SSL hostname verification", + "type": "boolean", + "title": "Check Hostname", + "default": true + }, + "verify_mode": { + "description": "Whether to try to verify other peers' certificates and how to behave if verification fails.", + "enum": [ + "CERT_NONE", + "CERT_OPTIONAL", + "CERT_REQUIRED" + ], + "title": "Verify Mode", + "default": "CERT_REQUIRED", + "type": "string" + }, + "encoding": { + "description": "Message encoding scheme", + "title": "Encoding", + "default": "utf-8", + "type": "string" + }, + "topic": { + "description": "The Kafka topic", + "type": "string", + "title": "Kafka Topic" + }, + "group_id": { + "description": "A Kafka group id", + "type": "string", + "title": "Kafka Group ID" + }, + "offset": { + "description": "Where to start reading messages from", + "type": "string", + "title": "Offset", + "enum": [ + "latest", + "earliest" + ], + "default": "latest" + }, + "security_protocol": { + "description": "Protocol used to communicate with brokers.", + "type": "string", + "enum": [ + "PLAINTEXT", + "SSL", + "SASL_PLAINTEXT", + "SASL_SSL" + ], + "title": "Security Protocol", + "default": "PLAINTEXT" + }, + "sasl_mechanism": { + "description": "Authentication mechanism when security_protocol is configured.", + "type": "string", + "enum": [ + "PLAIN", + "GSSAPI", + "SCRAM-SHA-256", + "SCRAM-SHA-512", + "OAUTHBEARER" + ], + "title": "SASL Mechanism", + "default": "PLAIN" + }, + "sasl_plain_username": { + "title": "SASL Plain Username", + "description": "Username for SASL PLAIN authentication", + "type": "string" + }, + "sasl_plain_password": { + "title": "SASL Plain Password", + "description": "Password for SASL PLAIN authentication", + "type": "string", + "format": "password" + } + }, + "required": [ + "host", + "port", + "topic" + ] +} diff --git a/extensions/eda/plugins/event_source/schemas/pg_listener.json b/extensions/eda/plugins/event_source/schemas/pg_listener.json new file mode 100644 index 00000000..caef410e --- /dev/null +++ b/extensions/eda/plugins/event_source/schemas/pg_listener.json @@ -0,0 +1,26 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://redhat.com/ansible_events/sources/pg_listener.json", + "title": "Postgres Listener Source Plugin", + "description": "An event source plugin for reading events from Postgres Notify/Listen", + "type": "object", + "properties": { + "dsn": { + "description": "The connection string Data Source Name", + "type": "string", + "title": "Data Source Name" + }, + "channels": { + "description": "The channels to listen on", + "title": "Channels", + "type": "array", + "items": { + "type": "string" + } + } + }, + "required": [ + "dsn", + "channels" + ] +} diff --git a/extensions/eda/plugins/event_source/schemas/range.json b/extensions/eda/plugins/event_source/schemas/range.json new file mode 100644 index 00000000..5f70e90d --- /dev/null +++ b/extensions/eda/plugins/event_source/schemas/range.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://redhat.com/ansible_events/sources/range.json", + "title": "Event Source Range Plugin", + "description": "A simple plugin to generate integer values given a limit", + "type": "object", + "properties": { + "limit": { + "description": "The max integer value", + "title": "Limit", + "type": "integer" + }, + "delay": { + "description": "The number of seconds to wait between events", + "title": "Delay", + "type": "integer" + } + }, + "required": [ + "limit" + ] +} diff --git a/extensions/eda/plugins/event_source/schemas/url_check.json b/extensions/eda/plugins/event_source/schemas/url_check.json new file mode 100644 index 00000000..6ea57064 --- /dev/null +++ b/extensions/eda/plugins/event_source/schemas/url_check.json @@ -0,0 +1,32 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://redhat.com/ansible_events/sources/url_check.json", + "title": "URL Checker source plugin", + "description": "An ansible-rulebook event source plugin that polls a set of URLs and sends events with their status.", + "type": "object", + "properties": { + "urls": { + "description": "A list of URL's to poll", + "title": "URLs", + "type": "array", + "items": { + "type": "string" + } + }, + "delay": { + "description": "Number of seconds to wait between polling", + "title": "Delay", + "type": "integer", + "default": 1 + }, + "verify_ssl": { + "description": "Verify SSL Certificate", + "title": "Verify Server Certificate", + "type": "boolean", + "default": true + } + }, + "required": [ + "urls" + ] +} diff --git a/extensions/eda/plugins/event_source/schemas/webhook.json b/extensions/eda/plugins/event_source/schemas/webhook.json new file mode 100644 index 00000000..a34d2a2a --- /dev/null +++ b/extensions/eda/plugins/event_source/schemas/webhook.json @@ -0,0 +1,75 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://redhat.com/ansible_events/sources/webhook.json", + "title": "Webhook Source Plugin", + "description": "Webhook plugins can receive events from external servers", + "type": "object", + "properties": { + "port": { + "description": "The port number to listen for incoming events", + "type": "integer", + "title": "Port" + }, + "host": { + "description": "The host address to listen on, default is 0.0.0.0", + "type": "string", + "title": "Host", + "default": "0.0.0.0" + }, + "token": { + "description": "Authentication token in header", + "type": "string", + "title": "Authentication Token", + "default": "" + }, + "certfile": { + "description": "The certfile to use", + "type": "string", + "title": "Certificate File", + "default": "" + }, + "keyfile": { + "description": "The keyfile to use", + "type": "string", + "title": "Key File", + "default": "" + }, + "password": { + "description": "The password to use", + "type": "string", + "title": "Password", + "default": "" + }, + "hmac_secret": { + "description": "The HMAC Secret to use", + "type": "string", + "title": "HMAC Secret", + "default": "" + }, + "hmac_algo": { + "description": "The HMAC Algorithm to use", + "type": "string", + "title": "HMAC Algorithm", + "default": "sha256" + }, + "hmac_header": { + "description": "The HTTP header which will contain the payload signature", + "type": "string", + "title": "HMAC Header", + "default": "x-hub-signature-256" + }, + "hmac_format": { + "description": "The format of the payload signature, hex or base64", + "type": "string", + "enum": [ + "hex", + "base64" + ], + "title": "HMAC Format", + "default": "hex" + } + }, + "required": [ + "port" + ] +} From 0764d2a8ebc9bab7ef02a08d2a41dc704eca0295 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Fri, 16 Aug 2024 14:30:42 +0200 Subject: [PATCH 3/4] Update README to match the template (#237) * Update README to match the template Signed-off-by: Alina Buzachis Co-authored-by: Sorin Sbarnea --- CONTRIBUTING.md | 29 ++++++++++++- README.md | 107 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 128 insertions(+), 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 00896ec6..c00b2b3f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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 @@ -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//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. @@ -47,7 +72,7 @@ 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: @@ -55,7 +80,7 @@ Sanity and unity tests can easily be run via tox: 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). diff --git a/README.md b/README.md index 4a8a0d5c..62f250f8 100644 --- a/README.md +++ b/README.md @@ -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/). - +[![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. From a772aaddab5a60798db452ddf6666a704a84399d Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Fri, 16 Aug 2024 13:59:12 +0100 Subject: [PATCH 4/4] Temporary disable coverage downgrade step inside check job (#265) --- .github/workflows/tox.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tox.yml b/.github/workflows/tox.yml index a736a8d8..090e7dbc 100644 --- a/.github/workflows/tox.yml +++ b/.github/workflows/tox.yml @@ -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