diff --git a/.github/workflows/eda-test-template.yml b/.github/workflows/eda-test-template.yml new file mode 100644 index 0000000..f5ae54f --- /dev/null +++ b/.github/workflows/eda-test-template.yml @@ -0,0 +1,21 @@ +--- +on: [] +name: Linters +jobs: + linters: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install dependencies + run: | + sudo apt-get update -y + sudo apt-get install jq libyaml-dev git build-essential findutils libsystemd-dev -y + sudo python3 -m pip install tox + sudo python3 -m pip install --upgrade --ignore-installed PyYAML + sudo python3 -m pip install --upgrade pip + sudo python3 -m pip install --upgrade virtualenv + sudo python3 -m pip install --upgrade setuptools + - name: Run tox + run: | + tox + diff --git a/extensions/eda/event_source/kentik_webhook.py b/extensions/eda/plugins/event_source/kentik_webhook.py similarity index 90% rename from extensions/eda/event_source/kentik_webhook.py rename to extensions/eda/plugins/event_source/kentik_webhook.py index eab93f7..737fd8c 100644 --- a/extensions/eda/event_source/kentik_webhook.py +++ b/extensions/eda/plugins/event_source/kentik_webhook.py @@ -14,7 +14,6 @@ import asyncio import json import logging -# from collections.abc import Callable from typing import Any from aiohttp import web @@ -35,7 +34,7 @@ def _initialize_logger_config() -> None: # Process incoming webhook alert notifications from Kentik @routes.post("/alert") async def webhook(request: web.Request) -> web.Response: - """Process incoming webhook alert notifications from Kentik + """Process incoming webhook alert notifications from Kentik. Parameters ---------- @@ -57,7 +56,7 @@ async def webhook(request: web.Request) -> web.Response: payload = await request.json() except json.JSONDecodeError as exc: logger.warning( - "Wrong body request: failed to decode JSON payload: %s", exc + "Wrong body request: failed to decode JSON payload: %s", exc, ) raise web.HTTPBadRequest(text="Invalid JSON payload") from None headers = dict(request.headers) @@ -73,7 +72,7 @@ async def webhook(request: web.Request) -> web.Response: # Set app_attr settings in a dictionary def set_app_attr(args: dict[str, Any]) -> dict[str, Any]: - """Set app_attr settings in a dictionary + """Set app_attr settings in a dictionary. Parameters ---------- @@ -86,11 +85,6 @@ def set_app_attr(args: dict[str, Any]) -> dict[str, Any]: Args containing the host and port """ - # Not really used since the values are fed in from the main. - # if "host" not in args: - # host = "0.0.0.0" - # if "port" not in args: - # port = 5000 app_attrs = {} app_attrs["host"] = args.get("host") app_attrs["port"] = args.get("port") @@ -152,7 +146,7 @@ async def put(self: "MockQueue", event: dict) -> None: main( MockQueue(), { - "host": "0.0.0.0", + "host": "127.0.0.1", "port": 5000, }, ), diff --git a/rulebooks/kentik_alert_example_rule.yml b/extensions/eda/rulebooks/kentik_alert_example_rule.yml similarity index 100% rename from rulebooks/kentik_alert_example_rule.yml rename to extensions/eda/rulebooks/kentik_alert_example_rule.yml diff --git a/galaxy.yml b/galaxy.yml index a595265..b2297a5 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,7 +1,7 @@ --- namespace: kentik name: ansible_eda -version: 1.0.0 +version: 1.0.1 readme: README.md authors: - Kentik @@ -31,4 +31,4 @@ issues: https://github.com/kentik/ansible_eda/issues # artifact. A pattern is matched from the relative path of the file or directory of the collection directory. This # uses 'fnmatch' to match the files or directories. Some directories and files like 'galaxy.yml', '*.pyc', '*.retry', # and '.git' are always filtered. Mutually exclusive with 'manifest' -build_ignore: [] +build_ignore: [.github/, tox.ini] diff --git a/kentik-ansible_eda-1.0.0.tar.gz b/kentik-ansible_eda-1.0.1.tar.gz similarity index 54% rename from kentik-ansible_eda-1.0.0.tar.gz rename to kentik-ansible_eda-1.0.1.tar.gz index 51266f8..cd529a4 100644 Binary files a/kentik-ansible_eda-1.0.0.tar.gz and b/kentik-ansible_eda-1.0.1.tar.gz differ diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..b4af282 --- /dev/null +++ b/tox.ini @@ -0,0 +1,27 @@ +[tox] +envlist = ruff, darglint, pylint +skipsdist = true +requires = + ruff + darglint + pylint + +[testenv] +allowlist_externals=* +commands = + {envpython} --version + +[testenv:ruff] +deps = ruff +commands = + bash -c 'ruff check --exclude .tox --select ALL --ignore INP001,FA102,UP001,UP010,I001,FA100,PLR0913,E501 -q extensions/eda/plugins' + +[testenv:darglint] +deps = darglint +commands = + bash -c 'darglint -s numpy -z full extensions/eda/plugins' + +[testenv:pylint] +deps = pylint +commands = + bash -c 'find ./extensions/eda/plugins -name "*.py" -print0 | xargs -0 pylint --output-format=parseable -sn --disable R0801,E0401,C0103,R0913,R0902,R0903'