Skip to content

GouvQC/notification-api

 
 

Repository files navigation

Notification

Contains:

  • the public-facing REST API for Notification built on the GOV.UK Notify platform, which teams can integrate with using their clients
  • an internal-only REST API built using Flask to manage services, users, templates, etc (this is what the admin app talks to)
  • asynchronous workers built using Celery to put things on queues and read them off to be processed, sent to providers, updated, etc

Functional constraints

  • We currently do not support sending of letters
  • We currently do not receive a response if text messages were delivered or not

Setting Up

Local installation instruction

On OS X:

  1. Install PyEnv with Homebrew. This will preserve your sanity.

brew install pyenv

  1. Install Python 3.6.9 or whatever is the latest

pyenv install 3.6.9

  1. If you expect no conflicts, set 3.6.9 as you default

pyenv global 3.6.9

  1. Ensure it installed by running

python --version

if it did not, take a look here: pyenv/pyenv#660

  1. Install virtualenv:

pip install virtualenvwrapper

  1. Add the following to your shell rc file. ex: .bashrc or .zshrc
export WORKON_HOME=$HOME/.virtualenvs
export PROJECT_HOME=$HOME/Devel
source  ~/.pyenv/versions/3.6.9/bin/virtualenvwrapper.sh
  1. Restart your terminal and make your virtual environtment:

mkvirtualenv -p ~/.pyenv/versions/3.6.9/bin/python notifications-api

  1. You can now return to your environment any time by entering

workon notifications-api

  1. Install Postgres.app.

  2. Create the database for the application

createdb --user=postgres notification_api

  1. Decrypt our existing set of environment variables

gcloud kms decrypt --project=[PROJECT_NAME] --plaintext-file=.env --ciphertext-file=.env.enc --location=global --keyring=[KEY_RING] --key=[KEY_NAME]

A sane set of defaults exists in .env.example

  1. Install all dependencies

pip3 install -r requirements.txt

  1. Generate the version file ?!?

make generate-version-file

  1. Run all DB migrations

flask db upgrade

  1. Run the service

flask run -p 6011 --host=0.0.0.0

15a. To test

pip3 install -r requirements_for_test.txt

make test

To run the queues

scripts/run_celery.sh
scripts/run_celery_sms.sh
scripts/run_celery_beat.sh

Python version

This codebase is Python 3 only. At the moment we run 3.6.9 in production. You will run into problems if you try to use Python 3.4 or older, or Python 3.7 or newer.

To update application dependencies

requirements.txt file is generated from the requirements-app.txt in order to pin versions of all nested dependencies. If requirements-app.txt has been changed (or we want to update the unpinned nested dependencies) requirements.txt should be regenerated with

make freeze-requirements

requirements.txt should be committed alongside requirements-app.txt changes.

Using Local Jinja for testing template changes

Jinja templates used in this repo: email_template.jinja2

Jinja templates are pulled in from the notification-utils repo. To test jinja changes locally (without needing to update the upstream), follow this procedure:

  1. Create a jinja_templates folder in the project root directory. This folder name is already gitignored and won't be tracked.

  2. Copy the jinja template files from notification-utils into the jinja_templates folder created in step 1

  3. Set a new .ENV variable: USE_LOCAL_JINJA_TEMPLATES=True

  4. Make markup changes, and see them locally!

  5. When finished, copy any changed jinja files back to notification-utils, and push up the PR for your changes in that repo.

  6. Remove USE_LOCAL_JINJA_TEMPLATES=True from your .env file, and delete any jinja in jinja_templates. Deleting the folder and jinja files is not required, but recommended. Make sure you're pulling up-to-date jinja from notification-utils the next time you need to make changes.

Frequent problems

Problem : E999 SyntaxError: invalid syntax when running flake8

Solution : Check that you are in your correct virtualenv, with python 3.5 or 3.6


Problem:

/bin/sh: 1: Syntax error: "(" unexpected
make: *** [Makefile:31: freeze-requirements] Error 2

when running make freeze-requirements

Solution: Change /bin/sh to /bin/bash in the Makefile


Problem: ImportError: failed to find libmagic. Check your installation

Solution:Install libmagic, ex: brew install libmagic


Problem: assert 'test_notification_api' in db.engine.url.database, 'dont run tests against main db

Solution: Do not specify a database in your .env


Problem: Messages are in the queue but not sending

Solution: Check that celery is running.

Politique de sécurité

Document portant sur la prise en charge des mises à jour de sécurité. Voir SECURITY pour plus d'informations.

Releases

No releases published

Packages

No packages published

Languages

  • Python 98.7%
  • HTML 1.1%
  • Other 0.2%