From 3c9e243c1b8e931c6943442ebdd90fd5704d569a Mon Sep 17 00:00:00 2001 From: Francois Blackburn Date: Thu, 16 Jan 2025 07:34:14 -0500 Subject: [PATCH] wazo-auth: add email notification plugin --- website/uc-doc/system/wazo-auth/developer.md | 56 ++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/website/uc-doc/system/wazo-auth/developer.md b/website/uc-doc/system/wazo-auth/developer.md index c3e7a803..1877e83b 100644 --- a/website/uc-doc/system/wazo-auth/developer.md +++ b/website/uc-doc/system/wazo-auth/developer.md @@ -232,3 +232,59 @@ class BarPlugin(object): api.add_resource(BarService, '/users//external/bar', resource_class_args=args) ``` + +### Email Notification + +By default `wazo-auth` implement an email notification plugin to send email through SMTP protocol. +Implementing a new kind of email notification can by done by: + +1. Create a python module implementing the + [email notification interface](https://github.com/wazo-platform/wazo-auth/blob/master/wazo_auth/interfaces.py). +2. Install the python module with an entry point `wazo_auth.email_notification`. +3. Add configuration to use the new `email_notification` plugin. + +#### Example + +```text +setup.py +src/plugin.py +/etc/wazo-auth/conf.d/email_notification.yml +``` + +```python +#!/usr/bin/env python3 +from setuptools import find_packages, setup + +setup( + name='auth_email_notification_proxy', + version='0.1', + packages=find_packages(), + entry_points={ + 'wazo_auth.email_notification': [ + 'proxy = src.plugin:ProxyEmail', + ], + } +) +``` + +```python +import requests + +from wazo_auth.interfaces import BaseEmailNotification + + +class ProxyEmail(BaseEmailNotification): + def __init__(self, config: dict, **kwargs: dict) -> None: + self.proxy_confirmation_url = config['proxy_confirmation_url'] + self.proxy_reset_url = config['proxy_reset_url'] + + def send_confirmation(self, context: dict) -> None: + requests.post(self.proxy_confirmation_url, json=context) + + def send_password_reset(self, context: dict) -> None: + requests.post(self.proxy_reset_url, json=context) +``` + +```yml +email_notification_plugin: proxy +```