This project is build around Notification Type in center.
To register new notification type and to see list of exisitng notification type check in main.go
For each kind of Notification, there is one Notification Type is defined. This section will give details on what are the components of Notification Type which helps to introduce new Notification Type or Enhance existing one.
New Notification Type can be registered as below,
resolvers.Register("analytics.notify.cve", collector.ConfiguredVars(config, collector.NewCVEResolver(authClient, witClient)), nil)
-
First arg, Notification Type name (string), here it is "analytics.notify.cve". You need to come up with unique Notification Type name depending on what kind of New Notificatoin you want to support. Later value of this will be used to get registered Resolver and Validator in NotifyController.Send()
-
Second arg, ReceiverResolver, it is used to find out list of users to which email should be sent when Notificatin arrives for given Notification Type, more on this later.
-
Third arg, ParamValidator, it is used to validate parameter received in Notification payload.
ReceiverResolver is responsible to return list of email to which notification sent for given Notification Type. Resolver will get ID
attribute as input.
The value of ID
attibute should be decided such that the related emails can be fetched.
For ex, to find notification email list for workitem.create
workitem.go type, one would like to get Workitem.ID
for newly created workitem.
You can also decide to set ID
with value of codebase_url
for analytics.notify.cve
cve.go type as with url one can find users who have registred for CVE notification on given Codebase URL.
Resolver will generally get initialized with 'WIT Client' and 'Auth Client' which will be used to query data based on ID
to get notification email list.
This is about email template which include email body, subject, headers etc. All email templates are maintained in template folder. For each Notification Type there is one folder with its name.
Here is sequence diagram of "/api/notify" API. Client will call this API to send Notification Emails.
This project use the dep
dependency management system.
One should have go
(version 1.10 or later), git
and make
installed on the system.
Run make all
to build the whole project. After this one can find executable created at ./bin/fabric8-notification and run the same to run the Notification service locally.
While running locally, you need to set mandrill.apikey
configuration param. This param used in sending notification email. While doing local devl and testing, you can skip send_email part and thus comment in main.go which validate this param.
Run make preview
to run preview/main.go. This will execute all template generation defined in main.go file. This is useful when you want to check the output of your template. The output email will be stored at ./tmp/ folder with file name having Notification Type name as prefix.
Run make test-unit-no-coverage
to run unit tests without coverage.