Skip to main content

Kinto emailer plugin

Project description

https://github.com/Kinto/kinto-emailer/actions/workflows/tests.yml/badge.svg https://img.shields.io/pypi/v/kinto-emailer.svg

kinto-emailer send emails when some events arise (e.g. new records have been created). It relies on Pyramid Mailer for the sending part.

Install

pip install kinto-emailer

Setup

In the Kinto settings:

kinto.includes = kinto_emailer

mail.default_sender = kinto@restmail.net

# mail.host = localhost
# mail.port = 25
# mail.username = None
# mail.password = None
# mail.tls = False
# mail.queue_path = None

If mail.queue_path is set, the emails are storage in a local Maildir queue.

See more details about Pyramid Mailer configuration.

Validate configuration

The following command will send a dummy email to the specified recipient or will fail if the configuration is not correct:

$ kinto-send-email config/kinto.ini testemailer@restmail.net

Development

Use a fake emailer that write emails files to disk:

mail.debug_mailer = true

How does it work?

Some information — like monitored action or list of recipients — are defined in the collection or the bucket metadata. When an event occurs, the plugin sends emails if one of the expected condition is met.

Usage

The metadata on the collection (or the bucket) must look like this:

{
  "kinto-emailer": {
    "hooks": [{
      "template": "Something happened!",
      "recipients": ['Security reviewers <security-reviews@mozilla.com>']
    }]
  }
}

In the above example, every action on the collection metadata or any record in that collection will trigger an email notification.

The metadata of the collection override the bucket metadata, they are not merged.

Optional:

  • subject (e.g. "An action was performed")

  • sender (e.g. "Kinto team <developers@kinto-storage.org>")

Recipients

The list of recipients can either contain:

  • Email adresses (eg. alice@wonderland.com or "Joe Doe <jon@doe.com>")

  • Group URI (eg. /buckets/staging/groups/reviewers)

With group URIs, the email recipients will be expanded with the group members principals look like email addresses (eg. ldap:peace@world.org).

Selection

It is possible to define several hooks, and filter on some condition. For example:

{
  "kinto-emailer": {
    "hooks": [{
      "resource_name": "record",
      "action": "create",
      "template": "Record created!",
      "recipients": ['Security reviewers <security-reviews@mozilla.com>']
    }, {
      "resource_name": "collection",
      "action": "updated",
      "template": "Collection updated!",
      "recipients": ["Security reviewers <security-reviews@mozilla.com>"]
    }]
  }
}

The possible filters are:

  • resource_name: record or collection (default: all)

  • action: create, update, delete (default: all)

  • collection_id (default: all)

  • record_id (default: all)

  • event: kinto.core.events.AfterResourceChanged (default), or kinto_remote_settings.signer.events.ReviewRequested, kinto_remote_settings.signer.events.ReviewApproved, kinto_remote_settings.signer.events.ReviewRejected

If a filter value starts with the special character ^, then the matching will consider the filter value to be a regular expression.

For example, in order to exclude a specific collection_id, set the filter value to: ^(?!normandy-recipes$).

Template

The template string can have placeholders:

  • bucket_id

  • id: record or collection id

  • user_id

  • resource_name

  • uri

  • action

  • timestamp

  • root_url

  • client_address

  • user_agent

  • settings[name]

For example:

{user_id} has {action}d a {resource_name} in {bucket_id}.

See Kinto core notifications.

Running the tests

To run the unit tests:

$ make tests

Functional Tests

A PostgreSQL database is required.

Install and run PostgreSQL using your system package manager, or using Docker:

$ docker run -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres:15

Create the test database:

$ psql -c "CREATE DATABASE testdb ENCODING 'UTF8' TEMPLATE template0;" -U postgres -h localhost -p 5432

Run a Kinto instance in a separate terminal:

$ make run-kinto

And start the test suite:

$ make functional

Releasing

  1. Create a release on Github on https://github.com/Kinto/kinto-emailer/releases/new

  2. Create a new tag X.Y.Z (This tag will be created from the target when you publish this release.)

  3. Generate release notes

  4. Publish release

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

kinto_emailer-3.0.4.tar.gz (36.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kinto_emailer-3.0.4-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file kinto_emailer-3.0.4.tar.gz.

File metadata

  • Download URL: kinto_emailer-3.0.4.tar.gz
  • Upload date:
  • Size: 36.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for kinto_emailer-3.0.4.tar.gz
Algorithm Hash digest
SHA256 faad1050a7a3370b09ff6faf06239bc267dce7ab259169d64d2eabfbc41854f8
MD5 8a7952c9ff07a56357d613a258643221
BLAKE2b-256 05976b576eceb77aec29c55fe4228d57564125816f8b79f5d8431fe8329bbef9

See more details on using hashes here.

Provenance

The following attestation bundles were made for kinto_emailer-3.0.4.tar.gz:

Publisher: publish.yml on Kinto/kinto-emailer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kinto_emailer-3.0.4-py3-none-any.whl.

File metadata

  • Download URL: kinto_emailer-3.0.4-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for kinto_emailer-3.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 84931ac6ff68cf1be65802297c7b370595765372d1d8aca536caaf7f776a63c9
MD5 53c8967661922155eb30828c572ce298
BLAKE2b-256 9df55a337545175e96e7c57b620c103dca3e8e195559651cc4561e1a295e4a95

See more details on using hashes here.

Provenance

The following attestation bundles were made for kinto_emailer-3.0.4-py3-none-any.whl:

Publisher: publish.yml on Kinto/kinto-emailer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page