feat(config): update n8n webhook handling (#366)
Some checks failed
Build Docker / Create Docker Image (release) Failing after 4m0s
Release / Tag release (push) Successful in 37s
Release / Create Release (push) Successful in 7s
Release / Publish Docker Images (push) Failing after 2m57s
Snyk / security (push) Successful in 8m22s

Okay, I will explain the code changes presented in the diff.  The primary focus of this pull request appears to be refactoring the N8N webhook URL configuration to use separate URLs for GET and POST requests. Additionally, several files in the `.github` directory have been moved to an `.archive/.github` directory.

**1. Directory Changes:**

*   A number of files related to GitHub configuration (CODEOWNERS, issue templates, dependabot configuration, renovate configuration, and workflow files) have been moved from the `.github` directory to `.archive/.github`. This suggests that these configurations are no longer actively used or are being superseded by other configurations.

**2. Environment Variable Changes (.env.default):**

```diff
--- a/.env.default
+++ b/.env.default
@@ -5,5 +5,6 @@
  APPROVED_DOMAINS="example.com,hello.com"
  APPROVED_ROOMS="abc123,def456"
  APPROVED_USERS="bob@example.com,john@me.com"
  BOT_NAME=""
 -N8N_WEBHOOK_URL=""
 +N8N_GET_WEBHOOK_URL=""
 +N8N_POST_WEBHOOK_URL=""
  WEBEX_API_KEY=""
```

*   The `.env.default` file, which provides default values for environment variables, has been modified.
*   The single `N8N_WEBHOOK_URL` environment variable has been removed.
*   Two new environment variables, `N8N_GET_WEBHOOK_URL` and `N8N_POST_WEBHOOK_URL`, have been added. This indicates the application now requires separate webhook URLs for GET and POST requests to the N8N service.

**3. Configuration Class Changes (app/utils/config.py):**

```diff
--- a/app/utils/config.py
+++ b/app/utils/config.py
@@ -42,9 +42,14 @@ class Config:
          return os.environ["ADMIN_EMAIL"].split(",")

      @property
-    def n8n_webhook_url(self) -> str:
-        """Returns the n8n webhook URL."""
-        return os.environ["N8N_WEBHOOK_URL"]
+    def n8n_get_webhook_url(self) -> str:
+        """Returns the n8n GET webhook URL."""
+        return os.environ["N8N_GET_WEBHOOK_URL"]
+
+    @property
+    def n8n_post_webhook_url(self) -> str:
+        """Returns the n8n POST webhook URL."""
+        return os.environ["N8N_POST_WEBHOOK_URL"]

      @property
      def approved_users(self) -> list:
```

*   The `Config` class in `app/utils/config.py` has been updated to reflect the environment variable changes.
*   The `n8n_webhook_url` property has been removed.
*   Two new properties, `n8n_get_webhook_url` and `n8n_post_webhook_url`, have been added.  These properties retrieve the corresponding environment variables and provide access to the individual webhook URLs.

**4. N8N Utility Changes (app/utils/n8n.py):**

```diff
--- a/app/utils/n8n.py
+++ b/app/utils/n8n.py
@@ -16,7 +16,7 @@ def __n8n_post(data: dict) -> bool:
      """
      headers: dict = {"Content-Type": "application/json"}
      resp: requests.Response = requests.post(
-        url=config.n8n_webhook_url,
+        url=config.n8n_post_webhook_url,
          headers=headers,
          json=data,
          timeout=10,
@@ -58,7 +58,7 @@ def get_tasks(requestor) -> bool:
      """
      headers: dict = {"Content-Type": "application/json"}
      resp: requests.Response = requests.get(
-        url=config.n8n_webhook_url,
+        url=config.n8n_get_webhook_url,
          headers=headers,
          timeout=10,
          verify=True,
```

*   The `app/utils/n8n.py` file has been modified to use the new configuration properties.
*   In the `__n8n_post` function, the `url` parameter in the `requests.post` call now uses `config.n8n_post_webhook_url` instead of the old `config.n8n_webhook_url`.
*   Similarly, in the `get_tasks` function, the `url` parameter in the `requests.get` call now uses `config.n8n_get_webhook_url`.

**5. Test Changes (tests/test\_config\_1.py and tests/test\_config\_2.py):**

```diff
--- a/tests/test_config_1.py
+++ b/tests/test_config_1.py
@@ -16,7 +16,8 @@ def test_config() -> None:
          "WEBEX_API_KEY": "testing",
          "ADMIN_FIRST_NAME": "Test",
          "ADMIN_EMAIL": "test@test.com",
-        "N8N_WEBHOOK_URL": "https://n8n.test.com/webhook/abcdefg",
+        "N8N_GET_WEBHOOK_URL": "https://n8n.test.com/webhook/abc",
+        "N8N_POST_WEBHOOK_URL": "https://n8n.test.com/webhook/def",
          "APPROVED_USERS": "test@test.com",
          "APPROVED_DOMAINS": "test.com",
          "APPROVED_ROOMS": "test",
@@ -34,7 +35,8 @@ def test_config() -> None:
      assert config.approved_rooms == config_vars["APPROVED_ROOMS"].split(",")
      assert config.approved_users == config_vars["APPROVED_USERS"].split(",")
      assert config.bot_name == config_vars["BOT_NAME"]
-    assert config.n8n_webhook_url == config_vars["N8N_WEBHOOK_URL"]
+    assert config.n8n_get_webhook_url == config_vars["N8N_GET_WEBHOOK_URL"]
+    assert config.n8n_post_webhook_url == config_vars["N8N_POST_WEBHOOK_URL"]
      assert config.version == config_vars["APP_VERSION"]
      assert config.webex_token == config_vars["WEBEX_API_KEY"]
```

*   The test files have been updated to use the new environment variables and configuration properties.  The old `N8N_WEBHOOK_URL` is removed and `N8N_GET_WEBHOOK_URL` and `N8N_POST_WEBHOOK_URL` are added and asserted.

**Summary:**

This pull request introduces a separation of N8N webhook URLs for GET and POST requests. This likely allows for more specific control and potentially different workflows depending on the HTTP method used to interact with the N8N service. The `.github` directory changes suggest cleaning up the repository by archiving old or unused configuration files. The tests are updated to align with the new configuration structure.

Co-authored-by: Luke Tainton <ltainton@cisco.com>
Reviewed-on: #366
This commit is contained in:
2025-08-04 09:59:52 +02:00
parent c234cb043d
commit d5a366c4f2
13 changed files with 20 additions and 10 deletions

1
.archive/.github/CODEOWNERS vendored Normal file
View File

@@ -0,0 +1 @@
* @luketainton

View File

@@ -0,0 +1,33 @@
---
name: Bug report
about: Create a report to help improve the bot.
title: 'BUG: '
labels: bug
assignees: luketainton
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Webex Client (please complete the following information):**
- Type: [e.g. Browser, Desktop, Mobile]
- OS: [e.g. iOS, Android, Windows, MacOS]
- Browser: [e.g. Chrome, Safari] (only applicable for browser client)
- Version: [e.g. 22] (only applicable for non-browser clients)
**Additional context**
Add any other context about the problem here.

View File

@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an enhancement for the bot.
title: 'FEATURE: '
labels: enhancement
assignees: luketainton
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

44
.archive/.github/dependabot.yml vendored Normal file
View File

@@ -0,0 +1,44 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
assignees:
- "luketainton"
# reviewers:
# - "luketainton"
commit-message:
prefix: "chore(actions)"
include: "scope"
labels:
- "dependencies"
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "daily"
assignees:
- "luketainton"
# reviewers:
# - "luketainton"
commit-message:
prefix: "chore(docker)"
include: "scope"
labels:
- "dependencies"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "daily"
assignees:
- "luketainton"
# reviewers:
# - "luketainton"
commit-message:
prefix: "chore(pip-prod)"
prefix-development: "chore(pip-dev)"
include: "scope"
labels:
- "dependencies"

47
.archive/.github/renovate.json vendored Normal file
View File

@@ -0,0 +1,47 @@
{
"assignAutomerge": true,
"assigneesFromCodeOwners": true,
"baseBranches": [
"main"
],
"dependencyDashboardAutoclose": true,
"extends": [
"config:base",
":semanticCommits",
":semanticCommitTypeAll(fix)"
],
"labels": [
"dependencies"
],
"packageRules": [
{
"labels": [
"linting"
],
"matchPackagePatterns": [
"black",
"pylint"
]
},
{
"labels": [
"unit-tests"
],
"matchPackagePatterns": [
"coverage",
"pytest"
]
}
],
"platformCommit": true,
"rebaseWhen": "behind-base-branch",
"rollbackPrs": true,
"vulnerabilityAlerts": {
"commitMessagePrefix": "[SECURITY] ",
"enabled": true,
"labels": [
"security"
],
"prCreation": "immediate"
}
}

View File

@@ -0,0 +1,64 @@
name: Build
on:
push:
branches: [main]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
release:
name: Release
runs-on: ubuntu-latest
outputs:
new_tag: ${{ steps.tag_version.outputs.new_tag }}
steps:
- uses: actions/checkout@v4
- name: Bump version and push tag
id: tag_version
uses: mathieudutour/github-tag-action@v6.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: minor
- name: Create a GitHub release
uses: ncipollo/release-action@v1
with:
tag: ${{ steps.tag_version.outputs.new_tag }}
name: ${{ steps.tag_version.outputs.new_tag }}
body: ${{ steps.tag_version.outputs.changelog }}
generateReleaseNotes: true
publish:
name: GitHub Container Registry
runs-on: ubuntu-latest
needs: release
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
- name: Login to GitHub Container Registry
run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ${{ env.REGISTRY }} -u ${{ github.actor }} --password-stdin
- name: Build image for GitHub Package Registry
run: |
docker build . --file Dockerfile \
--build-arg "version=${{ needs.release.outputs.new_tag }}" \
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.release.outputs.new_tag }} \
--tag ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
- name: Push image to GitHub Package Registry
run: |
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ needs.release.outputs.new_tag }}
# deploy:
# name: Update Portainer Deployment
# runs-on: ubuntu-latest
# needs: publish
# steps:
# - uses: fjogeleit/http-request-action@v1
# with:
# url: ${{ secrets.PORTAINER_WEBHOOK_URL }}
# method: POST
# timeout: 60000
# preventFailureOnNoResponse: "true"

20
.archive/.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,20 @@
name: CI
on:
pull_request:
types: [opened, synchronize, reopened]
paths-ignore:
- "README.md"
- "LICENSE.md"
- ".gitignore"
- ".github/CODEOWNERS"
- ".github/renovate.json"
- ".github/dependabot.yml"
jobs:
ci:
uses: luketainton/gha-workflows/.github/workflows/ci-python-poetry-with-docker.yml@main
with:
python-version: 3.13
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

26
.archive/.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,26 @@
name: Release
on:
workflow_dispatch:
schedule:
- cron: "0 9 * * 0"
jobs:
test:
uses: luketainton/gha-workflows/.github/workflows/ci-python-poetry-with-docker.yml@main
with:
python-version: 3.13
secrets:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
create_release:
name: Create Release
uses: luketainton/gha-workflows/.github/workflows/create-release.yml@main
create_docker:
name: Create Docker Image
needs: create_release
if: ${{ needs.create_release.outputs.success == 'true' }}
uses: luketainton/gha-workflows/.github/workflows/build-push-attest-docker.yml@main
with:
release: ${{ needs.create_release.outputs.release_name }}