Skip to content

ONSdigital/ras-secure-message

Repository files navigation

ras-secure-message

The api for the messaging functionality between respondents and the ONS.

Setup

Install Docker

Install postgresql

brew install postgresql

Install pipenv

pip install pipenv

Use pipenv to create a virtualenv and install dependencies

pipenv install

Alternatively you can use make

make build

Set environmental variables. Replace $SOURCE_ROOT with the parent directory of the project.

RAS_SM_PATH=$SOURCE_ROOT/ras-secure-message
LOGGING_LEVEL = DEBUG

Run the application

docker run -d -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgres -d postgres
pipenv run python run.py
 * Running on http://127.0.0.1:5050/
 * Restarting with reloader

or

docker compose up

or (when postgres is set up)

make start

Test the application

Ensure dev dependencies have been installed

make build

Ensure there is a postgres instance running on port 5432

docker run -d -p 5432:5432 --name postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=postgres -d postgres

or you can use the docker-compose.yml file to create postgres

docker compose up

Run the tests with make

make test # Runs linters, behave and unit tests
make lint # Runs linters only

Note: Ensure APP_SETTINGS isn't set in .env as it could cause the tests to fail in a non obvious way.

Run the behave tests with:

pipenv run behave # Runs all of the tests
pipenv run behave tests/behavioural/features/thread_get.feature # Runs individual feature test

Test the response

Now open up a prompt to test out your API using curl

$ curl http://127.0.0.1:5050/health
{"status": "healthy"}

Configuration

Environment variables available for configuration are listed below:

Environment Variable Description Default
LOGGING_LEVEL Log level for the application 'DEBUG'
SECURITY_USER_NAME Username for basic auth N/A
SECURITY_USER_PASSWORD Password for basic auth N/A
JWT_SECRET SECRET used to code JWT N/A
DATABASE_URL Database URI postgresql://postgres:postgres@localhost:5432
NOTIFICATION_TEMPLATE_ID Template id for Gov Notify service N/A
NOTIFY_VIA_GOV_NOTIFY Toggle for using Gov Notify for notifications '1' (enable Gov Notify email notifications)
PARTY_URL URL of the ras-party service N/A
CLIENT_ID ID of the client service in UAA N/A
CLIENT_SECRET Password of the client service in UAA N/A
UAA_URL URL of a UAA instance N/A
USE_UAA Sets whether a client token should be retrieved 1

Database migrations

Although there exists a 'migrations' folder for SQL database migration files, this service does not currently use any database migration tools such as Alembic. As such, the migration files are simply there for record-keeping purposes. Migration scripts will need to be performed manually on the database.