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
python -m venv venv
source venv/bin/activate
Now install the dependencies and test dependencies:
python -m 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.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 574ef58f1f03f685e6ed638a1214ecbb148f6dbd8865a1b838ccdcac9ec11aac |
|
MD5 | bcafd256308eb523e8499239e6ea8c0e |
|
BLAKE2b-256 | 3cdeea4b22edf1e5cc6ba2b128ba87425fe2883f7f92b42cb220479606041117 |
Hashes for datasette_webhook_write-0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 603b80d5132c48a7eb4e84fd888d1a54bc395282a88d0aa14c020381dae199c3 |
|
MD5 | 80e9d356d05ce1b24d84ea3eb90ec786 |
|
BLAKE2b-256 | f1a6cafad1abb241f57b2f188760a77fc1abba89b90d56a5859882e44ec56d36 |