Datasette plugin to write to database via verified webhooks
Project description
datasette-webhook-write
Datasette plugin to write to database via verified webhooks
Installation
Install this plugin in the same environment as Datasette.
$ datasette install datasette-webhook-write
Usage (datasette/receiving side)
This plugin allows writing to a datasette database via hmac-signed http POST calls.
Example for metadata.yml (for usage to receive texts from https://nlg.ax/):
plugins:
datasette-webhook-write:
webhook_secret:
"$env": "WEBHOOK_SECRET"
http_header_name: "x-myax-signature"
database_name: "example"
table_name: "generated_texts"
use_pk:
- "uid"
- "collection_id"
WEBHOOK_SECRET is set as environment variable.
Usage (pushing side)
The json data pushed has to be signed with the WEBHOOK_SECRET and added to the headers of the POST call.
Generate the hmac signature (where document
is the data you want to send, and WEBKOOK_SECRET
is the secret only pushing+receving parties should know):
digest = hmac.new(
key=WEBHOOK_SECRET.encode(),
msg=json.dumps(document).encode(),
digestmod=hashlib.sha1,
)
header = {
"X-SIGNATURE": f"sha1={digest.hexdigest()}",
}
The pushed data is written to the database only when secret+document are generating the same digest.
Development
To set up this plugin locally, first checkout the code. Then create a new virtual environment:
cd datasette-webhook-write
python3 -mvenv venv
source venv/bin/activate
Now install the dependencies and test dependencies:
pip install -e '.[test]'
To run the tests:
pytest
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for datasette-webhook-write-0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43fc7fb2860f70d353950a8c3df76626718ff6aa97d589b847ff415fe1ded5fe |
|
MD5 | 0d18200f621bc58e681bf6be0527e270 |
|
BLAKE2b-256 | 47cf2aaf2bf5750cbf48712d88a2be30a903edff0674d51da6efc07a1f742810 |
Hashes for datasette_webhook_write-0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c64e83ac96a3b21710eb49dd55adac44165fb29f149b9cfb9d5d1b8c493314fa |
|
MD5 | e845e89bc962ab6521aa63716cb5cd6a |
|
BLAKE2b-256 | a109cb4749fdd079bf800a2cff2edb00a72c986ac0b9b34c5ace5967e695a303 |