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.
The url to upload to the datasette instance is /-/webhook-write/
.
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 WEBHOOK_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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18c900d39e212a26db907bcd6fb4ee0ba000665dca87d0686c77921b4b6cfe2c |
|
MD5 | 1a0576697b7b0a31e9786dc71711a4ac |
|
BLAKE2b-256 | 4c2af59d273540827893b4b364dd032384885d1b799fb4f93da90d2b173aa0bf |
Hashes for datasette_webhook_write-0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b30db6e17b34bb9826e2c21c576010774932719462d429fe49738db05d99d61 |
|
MD5 | 0c93cbdcba09f6f80b8777495a9bd78e |
|
BLAKE2b-256 | eb2949da0928e097845b1812979b3c4c708a20544748509a5c301c35517c7638 |