Skip to content

Latest commit

 

History

History
172 lines (112 loc) · 3.91 KB

README.md

File metadata and controls

172 lines (112 loc) · 3.91 KB

ATE API

Operational data API for Active Travel England.

CI

Prerequisites

  1. Install Python 3.13
  2. Install Terraform 1.17

Running locally using Compose

To run the server as a container using a database:

  1. Run the services:

    docker compose up
  2. Invoke the server at http://localhost:8000

Running locally using Docker

To run the server as a container:

  1. Build the Docker image:

    docker build -t ate-api .
  2. Run the database image:

    docker run --rm -it -e POSTGRES_USER=ate -e POSTGRES_PASSWORD=password -p 5432:5432 postgres:18
  3. Run the Docker image:

    docker run --rm -it --network=host -e CREATE_DATABASE_SCHEMA=true ate-api
  4. Invoke the server at http://localhost:8000

The server can also be run on a different port by specifying the PORT environment variable:

docker run --rm -it --network=host -e CREATE_DATABASE_SCHEMA=true -e PORT=8001 ate-api

Running locally

  1. Create a virtual environment:

    python3.13 -m venv --prompt . --upgrade-deps .venv
  2. Activate the virtual environment:

    source .venv/bin/activate
  3. Install the dependencies:

    pip install -e .[dev]
  4. Run the database image:

    docker run --rm -it -e POSTGRES_USER=ate -e POSTGRES_PASSWORD=password -p 5432:5432 postgres:18

    Or using Compose:

    docker compose up database
  5. Run the server:

    CREATE_DATABASE_SCHEMA=true make run
  6. Invoke the server at http://localhost:8000

Invoking

To invoke the server running in an environment:

  1. Set the target environment, for example:

    export ENVIRONMENT=dev
  2. Request an access token from the identity provider:

    cd cloud/identity
    terraform workspace select ${ENVIRONMENT}
    ACCESS_TOKEN=$(./request-access-token.sh ${ENVIRONMENT})
  3. Obtain the server details:

    cd cloud/service
    terraform workspace select ${ENVIRONMENT}
    SERVER_URL=$(terraform output -raw url)
  4. Invoke the server with the access token:

    curl -H "Authorization: Bearer ${ACCESS_TOKEN}" ${SERVER_URL}/authorities/GMA

Configuring

The server can be configured with the following environment variables:

Name Value
DATABASE_URL Database URL
CREATE_DATABASE_SCHEMA true to create the database schema
OIDC_SERVER_METADATA_URL Authorisation server configuration endpoint
RESOURCE_SERVER_IDENTIFIER Resource server identifier (this must match the audience claim in the JWT access token)
DOCS_USERNAME HTTP Basic Auth username for documentation (unset to disable)
DOCS_PASSWORD HTTP Basic Auth password for documentation

Environment variables can also be provided in a .env file.

Running formatters and linters

  1. Run the formatters:

    make format
  2. Run the linters:

    make lint

Running tests

Run the tests:

make test

See also

Licence

MIT License