Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/defra/gwa-notification-receipt

Azure Function app for receiving callbacks from GOV.UK Notify.
https://github.com/defra/gwa-notification-receipt

Last synced: 6 days ago
JSON representation

Azure Function app for receiving callbacks from GOV.UK Notify.

Awesome Lists containing this project

README

        

# GWA Notification Receipt

[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![tested with jest](https://img.shields.io/badge/tested_with-jest-99424f.svg)](https://github.com/facebook/jest)\
[![Build and Deploy Production](https://github.com/DEFRA/gwa-notification-receipt/actions/workflows/build-and-deploy-production.yml/badge.svg)](https://github.com/DEFRA/gwa-notification-receipt/actions/workflows/build-and-deploy-production.yml)
[![Build and Deploy Staging](https://github.com/DEFRA/gwa-notification-receipt/actions/workflows/build-and-deploy-staging.yml/badge.svg)](https://github.com/DEFRA/gwa-notification-receipt/actions/workflows/build-and-deploy-staging.yml)\
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=DEFRA_gwa-notification-receipt&metric=coverage)](https://sonarcloud.io/dashboard?id=DEFRA_gwa-notification-receipt)
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=DEFRA_gwa-notification-receipt&metric=sqale_index)](https://sonarcloud.io/dashboard?id=DEFRA_gwa-notification-receipt)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=DEFRA_gwa-notification-receipt&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=DEFRA_gwa-notification-receipt)\
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=DEFRA_gwa-notification-receipt&metric=security_rating)](https://sonarcloud.io/dashboard?id=DEFRA_gwa-notification-receipt)
[![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=DEFRA_gwa-notification-receipt&metric=vulnerabilities)](https://sonarcloud.io/dashboard?id=DEFRA_gwa-notification-receipt)
[![Known Vulnerabilities](https://snyk.io/test/github/defra/gwa-notification-receipt/badge.svg)](https://snyk.io/test/github/defra/gwa-notification-receipt)

> An [Azure Function app](https://azure.microsoft.com/en-gb/services/functions/)
> for receiving callbacks from
> [GOV.UK Notify](https://www.notifications.service.gov.uk/)

The app exposes an HTTP endpoint where Notify can POST a callback to. The
message is checked for correct authorization, added to a queue for processing
before updating an item in a Cosmos DB container.

## Functions

The app is made up of a number of functions, each function is explained in more
detail in its' own README:

* [ReceiveReceipt](ReceiveReceipt/README.md)
* [ProcessReceipt](ProcessReceipt/README.md)

## Development

The best place to start for an overall view of how JavaScript Functions work in
Azure is the
[Azure Functions JavaScript developer guide](https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-node?tabs=v2).
From there follow the appropriate link to the documentation specific to
your preferred development environment i.e.
[Visual Studio Code](https://docs.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-node)
or
[command line](https://docs.microsoft.com/en-us/azure/azure-functions/create-first-function-cli-node?tabs=azure-cli%2Cbrowser).

The documentation within this repo assumes the `command line` setup has been
completed, specifically for
[Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli).

## Running Locally

To start the function app run `func start` or `npm run start` (which just runs
`func start`).

### Pre-requisites

The app uses Azure Storage queues. When working locally
[Azurite](https://github.com/Azure/Azurite) can be used to emulate storage.
Follow the
[instructions](https://docs.microsoft.com/en-us/azure/storage/common/storage-use-azurite)
for your preferred installation option.

The app uses Cosmos DB. Whilst an emulator can be
[installed locally](https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator?tabs=cli%2Cssl-netstd21)
the effort involved is significant in comparison to using the real thing. On
this basis it is advisable to use a real Cosmos DB instance.

The app uses `local.settings.json` for local development.
[.local.settings.json](.local.settings.json) can be used as the
basis as it contains all required env vars with the exception of secrets which
have been removed. The connection string for Azurite is included.

## Notify Set Up

The app receives message receipts from Notify. Getting set up on Notify is
straight forward, simply follow the
[documentation](https://www.notifications.service.gov.uk/using-notify/get-started).

A callback needs to be set up for the service created in Notify, additional
information in the
[documentation](https://docs.notifications.service.gov.uk/rest-api.html#callbacks).
The callback requires a bearer token be set along with the callback URL.

### Callback URL

In order to test the function it would ideally be deployed so that Notify can
access the URL. There are options available to expose localhost to the internet
such as [ngrok](https://ngrok.com/) and
[localtunnel](https://localtunnel.github.io/www/), however, deploying the
function is simple, more robust and safer.

HTTP Azure Functions can be set to require a
[key for access](https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-http-webhook-trigger?tabs=csharp#authorization-keys).
The callback URL set in Notify needs to include the key for the function.

### Bearer token

Notify requires a bearer token to be set. It is used in the
[Authorization header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization).
The function checks the header is the expected value as set in the env var
`NOTIFY_BEARER_HEADER`. Note that the check is against the full header value,
no manipulation of it takes place for simplicity.

## License

THIS INFORMATION IS LICENSED UNDER THE CONDITIONS OF THE OPEN GOVERNMENT
LICENCE found at:

The following attribution statement MUST be cited in your products and
applications when using this information.

> Contains public sector information licensed under the Open Government license
> v3

### About the license

The Open Government Licence (OGL) was developed by the Controller of Her
Majesty's Stationery Office (HMSO) to enable information providers in the
public sector to license the use and re-use of their information under a common
open licence.

It is designed to encourage use and re-use of information freely and flexibly,
with only a few conditions.