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:
parent
95e830e5c9
commit
1d62653830
19
.run/Flask wmn.wsgi.run.xml
Normal file
19
.run/Flask wmn.wsgi.run.xml
Normal 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>
|
38
Dockerfile
38
Dockerfile
|
@ -1,26 +1,33 @@
|
|||
FROM docker.io/alpine:latest
|
||||
FROM docker.io/archlinux/archlinux:base
|
||||
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 && \
|
||||
pip install -U pip && \
|
||||
pip install -U setuptools && \
|
||||
pip install -U Flask[async]
|
||||
RUN pacman -Syu --noconfirm python python-pipenv python-setuptools uwsgi uwsgi-plugin-python && \
|
||||
rm -rf /var/cache/pacman && \
|
||||
mkdir /opt/webhook-matrix-notifier
|
||||
|
||||
# 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_GID=1000
|
||||
|
||||
RUN mkdir -p /etc/wmn && \
|
||||
chmod 0700 /etc/wmn && \
|
||||
chown "${WMN_UID}" /etc/wmn && \
|
||||
addgroup -g "${WMN_GID}" wmn && \
|
||||
adduser -s /bin/sh -u "${WMN_UID}" -G wmn -D wmn
|
||||
RUN groupadd -g "${WMN_GID}" wmn && \
|
||||
useradd -u "${WMN_UID}" -g "${WMN_GID}" -m wmn && \
|
||||
mkdir -p /etc/wmn && \
|
||||
chmod 0750 /etc/wmn && \
|
||||
chown "${WMN_UID}:${WMN_GID}" /etc/wmn && \
|
||||
chown -R "${WMN_UID}:${WMN_GID}" /opt/webhook-matrix-notifier
|
||||
|
||||
USER wmn
|
||||
VOLUME /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
|
||||
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
|
||||
CMD [ "uwsgi", "--die-on-term", \
|
||||
"--need-plugin", "python3", \
|
||||
"--module", "wmn.wmn", \
|
||||
"--pythonpath", "/usr/local/lib/wmn", \
|
||||
"--need-plugin", "python", \
|
||||
"--virtualenv", "/opt/webhook-matrix-notifier/.venv", \
|
||||
"--pythonpath", "/opt/webhook-matrix-notifier", \
|
||||
"--module", "wmn.wsgi", \
|
||||
"--master", \
|
||||
"--processes", "1", \
|
||||
"--processes", "2", \
|
||||
"--threads", "2" ]
|
||||
|
|
2
LICENSE
2
LICENSE
|
@ -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
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
|
|
4
Pipfile
4
Pipfile
|
@ -9,7 +9,5 @@ flask = {version = "*", extras = ["async"]}
|
|||
matrix-nio = {version = "*", extras = ["e2e"]}
|
||||
python-dateutil = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[requires]
|
||||
python_version = ">=3.9"
|
||||
python_version = "3.11"
|
||||
|
|
1230
Pipfile.lock
generated
1230
Pipfile.lock
generated
File diff suppressed because it is too large
Load diff
39
README.md
39
README.md
|
@ -1,48 +1,47 @@
|
|||
# Webhook Matrix Notifier
|
||||
|
||||
Takes notifications via webhook, checks a secret and notifies a [Matrix](https://matrix.org) room.
|
||||
Listens to HTTP only. Should be used behind a reverse-proxy with HTTPS.
|
||||
|
||||
This Python project, Webhook Matrix Notifier, is designed to receive data via webhooks, verify a secret,
|
||||
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
|
||||
|
||||
An example configuration is located at `config.yml.example`.
|
||||
By default the file `config.yml` in the current working directory will be used as the configuration.
|
||||
To specify a different configuration file, use the environment variable `WMN_CONFIG_PATH`.
|
||||
An example configuration can be found at `config.yml.example`. By default, the project uses the `config.yml` file
|
||||
in the current working directory for configuration.
|
||||
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"
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
### GitLab
|
||||
|
||||
```
|
||||
```bash
|
||||
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
|
||||
```
|
||||
|
||||
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
|
||||
|
||||
```
|
||||
```bash
|
||||
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"))'`
|
||||
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.
|
||||
|
|
|
@ -1 +1 @@
|
|||
__all__ = ["common", "notify", "wmn"]
|
||||
__all__ = ["common", "notify", "wsgi"]
|
||||
|
|
Loading…
Reference in a new issue