Skip to content
This repository has been archived by the owner on Nov 8, 2018. It is now read-only.

crossgovernmentservices/csd-notes

Repository files navigation

Civil Service Digital Performance Review Notes App

Build Status

Requirements

  • Python 3
  • Ruby 2.2.0 (for govuk_template)
  • PhantomJS (for UI testing)
  • Dex (see Setting up Dex locally)
  • PostgreSQL 9.4

Quickstart

  1. Clone this repository and cd to the working directory

  2. Install the requirements listed above if you don't have them already

  3. mkvirtualenv --python=/path/to/python3 <appname>

  4. pip install -r requirements.txt

  5. python manage.py install_all_govuk_assets

  6. createdb notes

  7. python manage.py db upgrade

  8. python manage.py runserver

Tests

To run all tests:

python manage.py test

To run only fast unit tests:

python manage.py test spec

To run only smoke tests:

python manage.py test smoke

To run only UI tests:

python manage.py test ui

To generate HTML coverage reports (in the htmlcov directory)

python manage.py test coverage

Deployment

Configuration

The app looks for a SETTINGS environment variable on start up. To retrieve configuration values from AWS DynamoDB using credstash, set the SETTINGS environment variable to AWS. Otherwise, the default configuration is used, which fetches values from the environment.

DEBUG
(default: True) Run the app in debug mode, with exceptions triggering the online debugger
SECRET_KEY
(default: randomly generated) The key used to encypt session cookies and possibly other encrypted data. The default changes on server restart, so sessions will be lost unless a constant value is used
DB_USERNAME
(default: None) The username for the database
DB_PASSWORD
(default: None) The password for the database
DB_HOST
(default: `localhost`) The database hostname
DB_PORT
(default: None) The database port number

Setting up Dex locally

OK, this is a little long-winded:

  1. Find your Google ID number

  2. Browse to Google's OAuth 2 playground

  3. Click on Exchange authorization code for tokens

  4. Paste https://www.googleapis.com/oauth2/v2/userinfo into the Request URI field and Send the request

  5. Make a note of the id field in the JSON data at the bottom of the right hand side of the page

  6. Get a Google client id and client secret

  7. If you do not already have one, create a Google APIs project

  8. Go to Credentials > OAuth consent screen

  9. Add a Product name

  10. Select Create Credentials > OAuth client ID

  11. Select Web application, enter http://127.0.0.1:5556/auth/google/callback into Authorized redirect URIs

  12. Make a note of the Client ID and Client secret values near the top of the page

  13. Click Save

  14. Build Dex

  15. Run sh GOPATH="$(pwd)/go" mkdir -p go/src/github.com/coreos cd go/src/github.com/coreos git clone https://github.com/coreos/dex cd dex

  16. Paste the following into static/fixtures/client.json: json [ { "id": "notes-app", "secret": "c2VjcmV0ZQ==", "redirectURLs": ["http://localhost:5000/callback"] } ]

  17. Paste the following into static/fixtures/emailer.json: json { "type": "fake" }

  18. Paste the following into static/fixtures/users.json, replacing YOUR_ID with your Google ID number as found in step 1, and YOUR_EMAIL and YOUR_NAME with your email address and name, respectively json [ { "id": "YOUR_ID", "email": "YOUR_EMAIL@digital.cabinet-office.gov.uk", "displayName": "YOUR_NAME", "password": "password", "remoteIdentities": [ { "connectorId": "google", "id": "YOUR_ID" } ] } ]

  19. Paste the following into static/fixtures/connectors.json, replacing CLIENT_ID and CLIENT_SECRET with the Client ID and Client secret you obtained in step 2 json [ { "type": "oidc", "id": "google", "issuerURL": "https://accounts.google.com", "clientID": "CLIENT_ID", "clientSecret": "CLIENT_SECRET" } ]

  20. Run bin/dex-worker --no-db --enable-registration

  21. Set up the app as per README instructions, but set the following environment variables before you run it:

    export DEX_APP_CLIENT_ID="notes-app"
    export DEX_APP_CLIENT_SECRET="c2VjcmV0ZQ=="
    export DEX_APP_DISCOVERY_URL="http://127.0.0.1:5556"
    python manage.py runserver
  22. Browse to [http://localhost:5000/notes](notes page)

  23. Be redirected to Dex's login page and click on Log in with Google

  24. (Maybe) be redirected to Google's login page - sign in

  25. Be redirected to the notes app list page, and see your name next to the Sign out link near the top of the page