Update to Python 3.11 and Pipfile.lock

Rename wsgi module from wmn
Update Dockerfile to use `pipenv install --deploy`
Clarify README.md
This commit is contained in:
Ben 2024-02-05 17:33:14 +01:00
parent 95e830e5c9
commit 1d62653830
Signed by: ben
GPG key ID: 0F54A7ED232D3319
8 changed files with 653 additions and 681 deletions

View file

@ -0,0 +1,19 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Flask wmn.wsgi" type="Python.FlaskServer">
<option name="application" value="application" />
<module name="webhook-matrix-notifier" />
<option name="target" value="wmn.wsgi" />
<option name="targetType" value="PYTHON" />
<option name="ENV_FILES" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="launchJavascriptDebuger" value="false" />
<method v="2" />
</configuration>
</component>

View file

@ -1,26 +1,33 @@
FROM docker.io/alpine:latest FROM docker.io/archlinux/archlinux:base
MAINTAINER Benedikt Ziemons <ben@rs485.network> MAINTAINER Benedikt Ziemons <ben@rs485.network>
RUN apk add --no-cache uwsgi-python3 python3 py3-yaml py3-pip py3-setuptools py3-matrix-nio py3-dateutil && \ RUN pacman -Syu --noconfirm python python-pipenv python-setuptools uwsgi uwsgi-plugin-python && \
pip install -U pip && \ rm -rf /var/cache/pacman && \
pip install -U setuptools && \ mkdir /opt/webhook-matrix-notifier
pip install -U Flask[async]
# copy required source files # copy required source files
COPY wmn/ /usr/local/lib/wmn/wmn COPY Pipfile Pipfile.lock pyproject.toml LICENSE /opt/webhook-matrix-notifier/
COPY wmn/ /opt/webhook-matrix-notifier/wmn/
ARG WMN_UID=1000 ARG WMN_UID=1000
ARG WMN_GID=1000 ARG WMN_GID=1000
RUN mkdir -p /etc/wmn && \ RUN groupadd -g "${WMN_GID}" wmn && \
chmod 0700 /etc/wmn && \ useradd -u "${WMN_UID}" -g "${WMN_GID}" -m wmn && \
chown "${WMN_UID}" /etc/wmn && \ mkdir -p /etc/wmn && \
addgroup -g "${WMN_GID}" wmn && \ chmod 0750 /etc/wmn && \
adduser -s /bin/sh -u "${WMN_UID}" -G wmn -D wmn chown "${WMN_UID}:${WMN_GID}" /etc/wmn && \
chown -R "${WMN_UID}:${WMN_GID}" /opt/webhook-matrix-notifier
USER wmn USER wmn
VOLUME /etc/wmn/config.yml VOLUME /etc/wmn/config.yml
ENV WMN_CONFIG_PATH=/etc/wmn/config.yml ENV WMN_CONFIG_PATH=/etc/wmn/config.yml
WORKDIR /opt/webhook-matrix-notifier
ENV PIPENV_VENV_IN_PROJECT=1
ARG PIPENV_SITE_PACKAGES=1
RUN pipenv install --deploy
ARG PORT=3031 ARG PORT=3031
EXPOSE $PORT EXPOSE $PORT
@ -28,9 +35,10 @@ ENV UWSGI_SOCKET=:$PORT
# opens a uwsgi socket at the given port, which is to be used by a reverse proxy # opens a uwsgi socket at the given port, which is to be used by a reverse proxy
CMD [ "uwsgi", "--die-on-term", \ CMD [ "uwsgi", "--die-on-term", \
"--need-plugin", "python3", \ "--need-plugin", "python", \
"--module", "wmn.wmn", \ "--virtualenv", "/opt/webhook-matrix-notifier/.venv", \
"--pythonpath", "/usr/local/lib/wmn", \ "--pythonpath", "/opt/webhook-matrix-notifier", \
"--module", "wmn.wsgi", \
"--master", \ "--master", \
"--processes", "1", \ "--processes", "2", \
"--threads", "2" ] "--threads", "2" ]

View file

@ -1,4 +1,4 @@
Copyright 2019-2021 Benedikt Ziemons Copyright 2019-2024 Benedikt Ziemons
Permission is hereby granted, free of charge, to any person obtaining a copy of Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in this software and associated documentation files (the "Software"), to deal in

View file

@ -9,7 +9,5 @@ flask = {version = "*", extras = ["async"]}
matrix-nio = {version = "*", extras = ["e2e"]} matrix-nio = {version = "*", extras = ["e2e"]}
python-dateutil = "*" python-dateutil = "*"
[dev-packages]
[requires] [requires]
python_version = ">=3.9" python_version = "3.11"

1230
Pipfile.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,48 +1,47 @@
# Webhook Matrix Notifier # Webhook Matrix Notifier
Takes notifications via webhook, checks a secret and notifies a [Matrix](https://matrix.org) room. This Python project, Webhook Matrix Notifier, is designed to receive data via webhooks, verify a secret,
Listens to HTTP only. Should be used behind a reverse-proxy with HTTPS. and send notifications to a [Matrix](https://matrix.org) room.
The project provides a wsgi-compatible interface at `wmn.wsgi`, which is suitable for use behind a reverse proxy.
## Configuration ## Configuration
An example configuration is located at `config.yml.example`. An example configuration can be found at `config.yml.example`. By default, the project uses the `config.yml` file
By default the file `config.yml` in the current working directory will be used as the configuration. in the current working directory for configuration.
To specify a different configuration file, use the environment variable `WMN_CONFIG_PATH`. To specify a different configuration file, use the `WMN_CONFIG_PATH` environment variable.
## Running the Command Line Notifier
## Running the command line notifier To notify a room with a simple text/html message,
ensure your credentials are filled out in the configuration file and run:
To notify a room with a simple text message, ensure credentials are filled out in your configuration file and run ```bash
```
python -m wmn.notify -r '!room:matrix.org' "text" "html" python -m wmn.notify -r '!room:matrix.org' "text" "html"
``` ```
Installing the webhook-matrix-notifier will create the shorthand script "matrix-notify" for this. The installation of the package, specified by `pyproject.yaml`
will create a shorthand script called "matrix-notify" for this purpose.
## Testing the Webhook Application Locally
## Testing the webhook application locally 1. Start the local webserver using either `env FLASK_APP=wmn.wsgi flask run` or have your IDE start it for you.
2. Send a POST request using curl.
First, start the webserver locally by `env FLASK_APP=wmn.py flask run` or have your IDE start it for you. \
Then, send a POST request using curl.
### GitLab ### GitLab
``` ```bash
export URLQUOTED_ROOM=`python3 -c 'from urllib.parse import quote_plus; print(quote_plus("#room:matrix.org"))'` export URLQUOTED_ROOM=`python3 -c 'from urllib.parse import quote_plus; print(quote_plus("#room:matrix.org"))'`
curl -i -X POST "http://localhost:5000/matrix?room=${URLQUOTED_ROOM}" -H "X-Gitlab-Event: Push Hook" -H "X-Gitlab-Token: 123" -H "Content-Type: application/json" --data-binary @./testrequest_gitlab.json curl -i -X POST "http://localhost:5000/matrix?room=${URLQUOTED_ROOM}" -H "X-Gitlab-Event: Push Hook" -H "X-Gitlab-Token: 123" -H "Content-Type: application/json" --data-binary @./testrequest_gitlab.json
``` ```
The `X-Gitlab-Token` must correspond to the secret provided in the configuration. Ensure that the `X-Gitlab-Token` corresponds to the secret provided in the configuration.
### Prometheus ### Prometheus
``` ```bash
export URLQUOTED_ROOM=`python3 -c 'from urllib.parse import quote_plus; print(quote_plus("#room:matrix.org"))'` export URLQUOTED_ROOM=`python3 -c 'from urllib.parse import quote_plus; print(quote_plus("#room:matrix.org"))'`
export URLQUOTED_SECRET=`python3 -c 'from urllib.parse import quote_plus; print(quote_plus("123"))'` export URLQUOTED_SECRET=`python3 -c 'from urllib.parse import quote_plus; print(quote_plus("123"))'`
curl -i -X POST "http://localhost:5000/matrix?type=prometheus&secret=${URLQUOTED_SECRET}&room=${URLQUOTED_ROOM}" -H "Content-Type: application/json" --data-binary @./testrequest_prometheus.json curl -i -X POST "http://localhost:5000/matrix?type=prometheus&secret=${URLQUOTED_SECRET}&room=${URLQUOTED_ROOM}" -H "Content-Type: application/json" --data-binary @./testrequest_prometheus.json
``` ```
The secret must be passed as a URI parameter. Ensure that the secret is passed as a URI parameter.

View file

@ -1 +1 @@
__all__ = ["common", "notify", "wmn"] __all__ = ["common", "notify", "wsgi"]